|
|
Home » U++ Library support » U++ MT-multithreading and servers » Lost socket error (and how to get it)
Lost socket error (and how to get it) [message #40198] |
Tue, 02 July 2013 10:47 |
|
koldo
Messages: 3372 Registered: August 2008
|
Senior Veteran |
|
|
Hello all
When calling TcpSocket::Connect() the error code is lost. Take a look to actual function and comments:
bool TcpSocket::RawConnect(addrinfo *arp)
{
if(!arp) {
SetSockError("connect", -1, "not found");
return false;
}
for(int pass = 0; pass < 2; pass++) {
addrinfo *rp = arp;
while(rp) {
if(rp->ai_family == AF_INET == !pass && // Try to connect IPv4 in the first pass
Open(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) {
if(connect(socket, rp->ai_addr, (int)rp->ai_addrlen) == 0 ||
GetErrorCode() == SOCKERR(EINPROGRESS) || GetErrorCode() == SOCKERR(EWOULDBLOCK)
) {
mode = CONNECT;
return true;
}
Close(); // Error is cleaned
}
rp = rp->ai_next;
}
}
SetSockError("connect", -1, "failed"); // Here is not reported
return false;
}
A possible solution to get the error could be:
- int errorCode
- errorCode = GetErrorCode() just before Close()
- Including TcpSocketErrorDesc(errorCode) in SetSockError();
Best regards
Iñaki
|
|
|
|
Re: Lost socket error (and how to get it) [message #40202 is a reply to message #40198] |
Tue, 02 July 2013 20:46 |
|
mirek
Messages: 13984 Registered: November 2005
|
Ultimate Member |
|
|
koldo wrote on Tue, 02 July 2013 04:47 | Hello all
When calling TcpSocket::Connect() the error code is lost. Take a look to actual function and comments:
bool TcpSocket::RawConnect(addrinfo *arp)
{
if(!arp) {
SetSockError("connect", -1, "not found");
return false;
}
for(int pass = 0; pass < 2; pass++) {
addrinfo *rp = arp;
while(rp) {
if(rp->ai_family == AF_INET == !pass && // Try to connect IPv4 in the first pass
Open(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) {
if(connect(socket, rp->ai_addr, (int)rp->ai_addrlen) == 0 ||
GetErrorCode() == SOCKERR(EINPROGRESS) || GetErrorCode() == SOCKERR(EWOULDBLOCK)
) {
mode = CONNECT;
return true;
}
Close(); // Error is cleaned
}
rp = rp->ai_next;
}
}
SetSockError("connect", -1, "failed"); // Here is not reported
return false;
}
A possible solution to get the error could be:
- int errorCode
- errorCode = GetErrorCode() just before Close()
- Including TcpSocketErrorDesc(errorCode) in SetSockError();
|
I am not so sure about this: note that it is doing two passes, tries to connect ipv4 first, then ipv6. Which error is relevant?
Mirek
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Wed Jun 05 07:01:23 CEST 2024
Total time taken to generate the page: 0.01477 seconds
|
|
|