我无障碍地连接到TCP套接字。
printf("%m")
打印出Operation now in progress
,但errno
设置为0
。在打印之前,我也保存了errno
的值,以确保printf
不会摆弄它。很奇怪-printf
应该输出Success
。我的意思是,显然,问题是当我访问errno
时得到0
。如果重要的话,我正在相当老的内核(2.6左右)上使用uclibc。我vsprintf
访问errno
与我访问*__errno_location()
的方式之间并没有什么区别。
或者,如何判断我的套接字是否与connect
发生实际问题,或者它是否仍在连接?
示例:
int sock = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP);
/* create sockaddr struct (remote)... */
int fd = connect(sock, (const struct sockaddr*)&remote, sizeof(remote));
printf("%d, %d\n", fd, errno);
printf("%m");
输出:
-1, 0
Operation now in progress
我希望得到以下输出:
-1, 115
Operation now in progress
因为115是EINPROGRESS