Lev Walkin wrote:
> Hi there,
>
> The sources (io.c) has the following function:
>
> ===
>
> int st_connect(st_netfd_t *fd, struct sockaddr *addr, int addrlen,
> st_utime_t timeout)
> {
> int n, err = 0;
>
> while (connect(fd->osfd, addr, addrlen) < 0) {
> if (errno != EINTR) {
> if (errno != EINPROGRESS && (errno != EADDRINUSE || err == 0))
> return -1;
> /* Wait until the socket becomes writable */
> if (st_netfd_poll(fd, POLLOUT, timeout) < 0)
> return -1;
> /* Try to find out whether the connection setup succeeded or failed */
> n = sizeof(int);
> if (getsockopt(fd->osfd, SOL_SOCKET, SO_ERROR, (char *)&err,
> (socklen_t *)&n) < 0)
> return -1;
> if (err) {
> errno = err;
> return -1;
> }
> break;
> }
> err = 1;
> }
>
> return 0;
> }
>
> ===
>
> Can anybody explain the hidden meaning of
>
> err = 1
>
> string?
>
Some platforms (e.g., IRIX 6.2, fixed in 6.5) have "peculiar"
implementation of connect(2). On those platforms if connect(2) is
interrupted (errno == EINTR) after socket was bound by the kernel,
the second connect(2) attempt will fail with errno == EADDRINUSE.
The code above ignores EADDRINUSE iff connect(2) was previously
interrupted (the err flag was set).
--Gene
|