U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ MT-multithreading and servers » Lost socket error (and how to get it)
Re: Lost socket error (and how to get it) [message #40202 is a reply to message #40198] Tue, 02 July 2013 20:46 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14291
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
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Need a working simple example of using sockets with GUI in U++
Next Topic: Communicate two PCs using http
Goto Forum:
  


Current Time: Mon Jul 27 03:44:30 GMT+2 2026

Total time taken to generate the page: 0.00934 seconds