TCP 连接错误 115 操作正在进行中 原因是什么? [英] TCP Connect error 115 Operation in Progress What is the Cause?
问题描述
我的应用程序创建了一个 TCP 连接,这工作正常.但是在一个网络服务器有很多IP说
- 174.X.X.X
- 54.x.x.x像这样
调用 TCP 连接时(非阻塞,超时 60 秒)到 IP 174.X.X.X
总是成功的.但是 TCP 使用 ip 54.x.x.x
连接到同一服务器失败(大多数情况下),错误号为 115测量操作正在进行中.
你能解释一下 errno 115 的可能原因是什么
操作系统:Linux
我的TCP连接代码如下
tcp_connect(......){int iValOpt = 0;int iLength = 0;fcnt((int)(long)SockID,F_SETFL_O_NONBLOCK);ret = 连接 (sockID,(struct sockaddr*)pstSockAdr,uiSockLen);如果 (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)){返回-1}如果 (0 != iValOpt){返回-1;}返回成功;}别的{返回-1;}}别的{返回-1;}}返回成功;}
根据您的信息:
- 您正在尝试对
54.x.x.x
执行 - 套接字是
非阻塞
- 连接超时为
60 秒
connect()
首先,如果您查看您的 /usr/include/asm-generic/errno.h
,您将看到以下内容:
#define EINPROGRESS 115/* 操作正在进行中 */
这意味着对套接字的现有操作正在进行中.因为,你说你正在做一个 connect()
调用,让我们做一个 man connect
:
因此,最好的猜测是 TCP 3 次握手(您对 54.xxx
IP 地址的 connect()
调用)花费的时间比预期的要长完全的.由于 connect()
操作已经在进行中,因此对套接字的任何后续操作都会导致 EINPROGRESS
错误代码.按照手册页中的建议,尝试使用 select()
或 poll()
来检查您的套接字是否已准备好使用(执行 read()
或 write()
调用).
您可以通过捕获和分析进出您自己的机器和 54.x.x.x
的流量来确定阻止 TCP 握手完成的原因.帮助您解决此问题的最佳工具称为 WireShark.祝你好运.
My application creats a TCP connection, This is working normaly. But in one network server has many IP say
- 174.X.X.X
- 54.x.x.x like this
When calling TCP connect (Non blocking with timeout of 60 seconds)
to IP 174.X.X.X
is always success .
But TCP connect to same server with ip 54.x.x.x
is failing (most of the times) with errno 115
measn operation in progress.
Can you please explain me what are the possible reason for errno 115
OS : Linux
My TCP conenct code is as 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;
}
Based on your information:
- You are trying to do a
connect()
to54.x.x.x
- The socket is
non-blocking
- Connection timeout is
60 sec
First, if you look into your /usr/include/asm-generic/errno.h
you'll see the following:
#define EINPROGRESS 115 /* Operation now in progress */
It means an existing operation on the socket is in progress. Since, you said you are doing a connect()
call, lets do a 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, the best guess would be that the TCP 3-way handshake (your connect()
call to 54.x.x.x
IP address) is taking longer than expected to complete. Since the connect()
operation is already in progress, any subsequent operation on the socket is resulting into EINPROGRESS
error code. As suggested in the man page, try to use select()
or poll()
to check if your socket is ready to use (to perform read()
or write()
calls).
You can pin-point what is preventing your TCP handshake to complete by capturing and analyzing the traffic to/from your own machine and 54.x.x.x
. The best tool to help you with this is called WireShark. Good luck.
这篇关于TCP 连接错误 115 操作正在进行中 原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!