operation now in process 问题;
来源:互联网 发布:南风知我意gl百度网盘 编辑:程序博客网 时间:2024/05/12 16:34
在非阻塞模式下。连接服务器,有时候会出现服务端提示此错误;
解决办法:
可以把 fcntl(tcpsock,F_SETFL,O_NONBLOCK); 放到connect之后就好了!
个人觉得在connect之前就设nonblock不好。
此问题的官方解释:
man connect:
EINPROGRESS
The socket is non-blocking and the connection cannot be com-
pleted 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() com-
pleted successfully (SO_ERROR is zero) or unsuccessfully
(SO_ERROR is one of the usual error codes listed here, explain-
ing the reason for the failure).
int
connect_nonb(int sockfd, const SA *saptr, socklen_t salen, int nsec)
{
int flags, n, error;
socklen_t len;
fd_set rset, wset;
struct timeval tval;
flags = Fcntl(sockfd, F_GETFL, 0);
Fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
error = 0;
if ( (n = connect(sockfd, saptr, salen)) < 0)
if (errno != EINPROGRESS)
return (-1);
/* Do whatever we want while the connect is taking place. */
if (n == 0)
goto done; /* connect completed immediately */
FD_ZERO(&rset);
FD_SET(sockfd, &rset);
wset = rset;
tval.tv_sec = nsec;
tval.tv_usec = 0;
if ( (n = Select(sockfd + 1, &rset, &wset, NULL,
nsec ? &tval : NULL)) == 0) {
close(sockfd); /* timeout */
errno = ETIMEDOUT;
return (-1);
}
if (FD_ISSET(sockfd, &rset) || FD_ISSET(sockfd, &wset)) {
len = sizeof(error);
if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
return (-1); /* Solaris pending error */
} else
err_quit("select error: sockfd not set");
done:
Fcntl(sockfd, F_SETFL, flags); /* restore file status flags */
if (error) {
close(sockfd); /* just in case */
errno = error;
return (-1);
}
return (0);
}
- operation now in process 问题;
- Laravel migration PHP Storm遇到的问题:failed to open stream: Operation now in progress
- Notes: Process in Operation System and Dead Lock 操作系统中的进程和死锁问题
- 挂载CIFS时出现“Operation now in progress”
- eclipse svn operation in process 无法同步 更新 提交
- LINUX socket 在connect的时候发生 Operation now in progress 错误
- LINUX socket 在connect的时候发生 Operation now in progress 错误
- 关于socket通信中在connect()遇到的Operation now in progress错误
- LINUX socket 在connect的时候发生 Operation now in progress 错误
- LINUX socket 在connect的时候发生 Operation now in progress 错误
- linux下SOCKET在connect时遇到Operation now in progress
- generic operation system : process
- KS GL journal [0807015] cannot do any operation and Fund status is In Process
- In the army now
- In the Army Now
- He had an operation in his knee.but now he is feeling like a million dollar,apparently the pain in his knee is all gone
- luasocket 解决luasocket Operation already in progress 问题
- compare operation in shell
- 如何区分Java中的值传递和引用传递
- linux 中root口令遗失了解决办法
- Ubuntu910虚拟机配置DHCP
- VS文本编辑的正则表达式使用经验
- Flex builder3 装svn插件
- operation now in process 问题;
- ACM常用基础—输入输出
- 一点感想
- 使用MATLAB进行频谱分析
- 课程笔记(3)
- 我是你的守护神
- Windows 2003安全设置大全
- iso中应用外部资源
- 好站