- documented check (non-blocking open finished)
This commit is contained in:
23
network.c
23
network.c
@ -321,7 +321,7 @@ CreateSocketAdress(
|
|||||||
}
|
}
|
||||||
oldopts = fcntl(self->sockid, F_GETFL, 0);
|
oldopts = fcntl(self->sockid, F_GETFL, 0);
|
||||||
if (! (oldopts | O_NONBLOCK)) {
|
if (! (oldopts | O_NONBLOCK)) {
|
||||||
/* assume success when in blocking bmode */
|
/* assume success when in blocking mode */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
FD_ZERO(&wmask);
|
FD_ZERO(&wmask);
|
||||||
@ -331,17 +331,22 @@ CreateSocketAdress(
|
|||||||
iret = select(self->sockid+1, &rmask, &wmask, NULL, &tmo);
|
iret = select(self->sockid+1, &rmask, &wmask, NULL, &tmo);
|
||||||
if (iret == 0) return 0; /* in progress */
|
if (iret == 0) return 0; /* in progress */
|
||||||
if (iret > 0) {
|
if (iret > 0) {
|
||||||
if (FD_ISSET(self->sockid, &wmask)) {
|
/* the connection has either succeded or failed
|
||||||
if (FD_ISSET(self->sockid, &rmask)) {
|
- the write flag indicates success
|
||||||
iret = recv(self->sockid, NULL, 0, 0);
|
- the read flag indicates, if there is already data pending
|
||||||
|
the read flag should not appear without the write flag
|
||||||
|
*/
|
||||||
|
if (FD_ISSET(self->sockid, &wmask)) { /* should always be true */
|
||||||
|
if (FD_ISSET(self->sockid, &rmask)) { /* there may already be data for read */
|
||||||
|
iret = recv(self->sockid, NULL, 0, 0); /* zero length, check only return value */
|
||||||
if (iret >= 0) {
|
if (iret >= 0) {
|
||||||
iret = 1;
|
iret = 1; /* success */
|
||||||
}
|
} /* else failure */
|
||||||
} else {
|
} else {
|
||||||
iret = send(self->sockid, NULL, 0, 0);
|
iret = send(self->sockid, NULL, 0, 0); /* zero length, check only return value */
|
||||||
if (iret >= 0) {
|
if (iret >= 0) {
|
||||||
iret = 1;
|
iret = 1; /* success */
|
||||||
}
|
} /* else failure */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user