TCP Connect Error 115 Work in progress What is the cause?

My application creates a TCP connection, it works fine. But on one network server a lot of IPs say

  • 174.XXX
  • 54.xxx like this

When you call a TCP connection (without blocking with a timeout of 60 seconds) to IP 174.XXX always a success. But a TCP connection to the same server with ip 54.xxx fails (in most cases) with the errno 115 measurement operation being performed.

Could you explain to me what is the possible reason for errno 115

OS: Linux

TCP code code below

 tcp_connect(......) { int iValOpt = 0; int iLength= 0; fcnt((int)(long)SockID,F_SETFL_O_NONBLOCK); ret = connect (sockID,(struct sockaddr*)pstSockAdr,uiSockLen); if (ret < 0) { if (errno == EINPROGRESS) { stTv.tv_sec = 60; stTv.tv_usec = 0; FD_ZERO(&write_fd); FD_SET(sockID,&write_fd); iLength = sizeof(int); if (0 < select (sockID+1) , NULL,&write_fd,NULL,&stTv); { if(0 > getsockopt(sockID,SOL_SOCKET,SO_ERROR,(void*)(&iValOpt),&iLength)) { return -1 } if (0 != iValOpt) { return -1; } return success; } else { return -1; } } else { return -1; } } return success; } 
+9
c networking network-programming tcp errno
source share
2 answers

Based on your information:

  • You are trying to do connect() to 54.xxx
  • non-blocking socket
  • Connection timeout 60 sec

Firstly, if you look at /usr/include/asm-generic/errno.h , you will see the following:

 #define EINPROGRESS 115 /* Operation now in progress */ 

This means that an existing operation is being performed on the socket. Since you said you were using the connect() call, enable man connect :

 EINPROGRESS

 The socket is nonblocking and the connection cannot be completed 
 immediately.  It is possible to select (2) or poll (2) for completion by
 selecting the socket for writing.  After select (2) indicates
 writability, use getsockopt (2) to read the SO_ERROR option at level
 SOL_SOCKET to determine whether connect () completed successfully
 (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual
 error codes listed here, explaining the reason for the failure).

So, it’s best to assume that the TCP three-way handshake (your connect() call to 54.xxx IP address) takes longer than expected. Since the connect() operation is already in EINPROGRESS , any subsequent operation in the juice results in an EINPROGRESS code EINPROGRESS . As suggested on the man page, try using select() or poll() to check if your socket is ready (to make read() or write() calls).

You can specify what prevents your handshake from ending TCP by capturing and analyzing traffic to / from your own machine and 54.xxx . The best tool to help you with this is called WireShark . Good luck.

TCP 3 way handshake

+16
source share

It looks like the behavior of connect () :

If the connection cannot be established immediately, and O_NONBLOCK for the file descriptor for the socket, connect () does not work and set errno to [EINPROGRESS], but the connection request will not be interrupted and the connection is established asynchronously. Subsequent calls to connect () for the same socket before the connection is established, should fail and set errno to [EALREADY].

+4
source share

All Articles