【发布时间】:2017-08-24 09:03:18
【问题描述】:
我阅读了以下示例代码,我想知道是否有人能说出 connect() 在哪些平台上可能会因 EINPROGRESS 或 EALREADY 以外的其他原因而失败。
失败是指执行示例中的else 分支以执行。源代码中的评论建议使用 FreeBSD。有没有其他系统?我无法让它在 Linux 上失败。
if (connect(hostp->sockets[i],
(struct sockaddr *)res->ai_addr,
res->ai_addrlen) == -1) {
/* This is what we expect. */
if (errno == EINPROGRESS) {
printf(" connect EINPROGRESS OK "
"(expected)\n");
FD_SET(hostp->sockets[i], &wrfds);
} else {
/*
* This may happen right here, on
* localhost for example (immediate
* connection refused).
* I can see that happen on FreeBSD
* but not on Solaris, for example.
*/
printf(" connect: %s\n",
strerror(errno));
++n;
}
[...]
【问题讨论】:
标签: sockets unix posix portability errno