Reputation: 91885
If I set up a socket for non-blocking operation, as follows:
int fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP);
int rc = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
...is connect
guaranteed to fail with EINPROGRESS
, or do I need to handle the case where it succeeds immediately?
Upvotes: 0
Views: 320
Reputation: 136425
Not necessarily. Connecting to 127.0.0.1
may connect or fail immediately.
Upvotes: 3
Reputation: 310980
You need to handle the case where it succeeds immediately. That's why it returns 0 or -1. The documentation doesn't make any exception about that for non-blocking mode.
Upvotes: 2