在建TCP连接错误115操作的原因是什么? [英] TCP Connect error 115 Operation in Progress What is the Cause?

查看:10488
本文介绍了在建TCP连接错误115操作的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序及牡丹TCP连接,这是工作normaly。
但是,在一个网络服务器有很多IP说


  • 174.X.X.X

  • 54.x.x.x
    像这样

当调用TCP连接(非60秒超时阻塞)
以IP 174.X.X.X 总是成功。
但是,TCP连接到同一台服务器和IP 54.x.x.x 失败(大部分时间),并将errno 115
正在进行measn操作。

能否请您解释我什么是错误号115的可能原因

操作系统:Linux

我的TCP conenct code是如下

  tcp_connect(......)
{  INT iValOpt = 0;
  INT iLength = 0;  FCNT((INT)(长)SockID,F_SETFL_O_NONBLOCK);  RET =连接(sockID,(结构sockaddr *)pstSockAdr,uiSockLen);  如果(RET℃下)
  {        如果(错误== EINPROGRESS)
        {
                stTv.tv_sec = 60;
                stTv.tv_usec = 0;
                FD_ZERO(安培; write_fd);
                FD_SET(sockID,&安培; write_fd);                iLength = sizeof的(INT);                如果(0℃;选择(sockID + 1),NULL,&放大器; write_fd,NULL,&放大器; STTV);                {
                        如果(0>的getsockopt(sockID,SOL_SOCKET,SO_ERROR,(无效*)(安培; iValOpt),放大器; iLength))
                        {
                                返回-1
                        }                        如果(0!= iValOpt)
                        {
                                返回-1;
                        }
                        返回成功;
                }                其他
                {
                        返回-1;
                }        }
        其他
        {
                返回-1;
        }
    }   返回成功;}


解决方案

根据您的信息:


  • 您正在尝试做一个连接() 54.x.x.x

  • 套接字非阻塞

  • 连接超时是 60秒

首先,如果你看着你的 /usr/include/asm-generic/errno.h 你会看到以下内容:

 的#define EINPROGRESS 115 / *正在进行操作* /

这意味着在插座上的现有操作正在进行。因为,你说你在做一个连接()通话,让做的 人连接


  

EINPROGRESS


  
  

套接字是非阻塞,连接无法完成
  立即。这是可能的选择(2)或poll(2)通过完成
  选择用于写入的插座。后选择(2)表示
  可写性,使用setsockopt(2)阅读水平SO_ERROR选项
  SOL_SOCKET以确定是否连接()成功完成
  (SO_ERROR是零)或失败(SO_ERROR是通常的一个
  错误codeS列在这里,解释失败的原因)。


所以,最好的猜测是握手TCP 3路(你的连接()来电 54.xxx IP地址)花费的时间比预期完成。因为连接()操作已经在进行中,插座上的任何后续操作产生到 EINPROGRESS 错误code。正如在手册页的建议,尝试使用选择()调查()来检查,如果您的插座已准备就绪使用(执行阅读()的write()电话)。

您可以针点是什么preventing您的TCP握手通过捕捉和流量从自己的计算机分析来/和 54.x.x.x 来完成。帮你这个最好的工具被称为 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() to 54.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆