The return value of a EthernetClient.connect()

The official documentation says that the method the EthernetClient.connect() returns an int (1,-1,-2,-3,-4). But in the source code EthernetClient.cpp we can see:

int EthernetClient::connect(IPAddress ip, uint16_t port) {
  if (_sock != MAX_SOCK_NUM)
    return 0;

  for (int i = 0; i < MAX_SOCK_NUM; i++) {
    uint8_t s = W5100.readSnSR(i);
    if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT || s == SnSR::CLOSE_WAIT) {
      _sock = i;
      break;
    }
  }

  if (_sock == MAX_SOCK_NUM)
    return 0;

  _srcport++;
  if (_srcport == 0) _srcport = 1024;
  socket(_sock, SnMR::TCP, _srcport, 0);

  if (!::connect(_sock, rawIPAddress(ip), port)) {
    _sock = MAX_SOCK_NUM;
    return 0;
  }

  while (status() != SnSR::ESTABLISHED) {
    delay(1);
    if (status() == SnSR::CLOSED) {
      _sock = MAX_SOCK_NUM;
      return 0;
    }
  }

  return 1;
}

Hence, this function can return only 0 or 1. Am I wrong or not?

I translated it to Russian language in this way.

Those return codes are for the dns server response on the second overload of connect().

int EthernetClient::connect(const char* host, uint16_t port) {
  // Look up the host first
  int ret = 0;
  DNSClient dns;
  IPAddress remote_addr;

  dns.begin(Ethernet.dnsServerIP());
  ret = dns.getHostByName(host, remote_addr);
  if (ret == 1) {
    return connect(remote_addr, port);
  } else {
    return ret;
  }
}

Not there? Update your IDE.

This function eventually calls a function, which I mentioned above:
return connect(remote_addr, port);
Accordingly for versions client.connect(URL, port) - returns int(1,0,-1,-2,-3,-4), and for version client.connect(ip, port) - returns int (0,1)

malok:
This function eventually calls a function, which I mentioned above:
return connect(remote_addr, port);
Accordingly for versions client.connect(URL, port) - returns int(1,0,-1,-2,-3,-4), and for version client.connect(ip, port) - returns int (0,1)

Correct. The function you mentioned is only called if the dns succeeds in the client.connect(URL, port) version.