[MLton] bug in MLton and bug in basis
Wesley W. Terpstra
wesley@terpstra.ca
Thu, 18 Aug 2005 16:57:50 +0200
On Aug 18, 2005, at 4:51 PM, Florian Weimer wrote:
> Solaris returns the error code in errno, not in the passed integer, so
> you need something like this:
>
> int
> half_duplex_handler::get_error()
> {
> int error = 0;
> socklen_t len = sizeof(error);
>
> errno = 0;
> if (getsockopt(fd(), SOL_SOCKET, SO_ERROR, &error, &len) >= 0) {
> // Non-Solaris case: error is overwritten with the error code,
> // Nothing to do.
> } else {
> // Solaris case: errno has the error code.
> error = errno;
> }
>
> return error;
> }
Are you sure that's still the case?
I'm looking at io.c from libst which says:
int st_connect(_st_netfd_t *fd, const struct sockaddr *addr, int
addrlen,
st_utime_t timeout)
{
int n, err = 0;
while (connect(fd->osfd, addr, addrlen) < 0) {
if (errno != EINTR) {
/*
* On some platforms, if connect() is interrupted (errno ==
EINTR)
* after the kernel binds the socket, a subsequent connect()
* attempt will fail with errno == EADDRINUSE. Ignore EADDRINUSE
* iff connect() was previously interrupted. See Rich Stevens'
* "UNIX Network Programming," Vol. 1, 2nd edition, p. 413
* ("Interrupted connect").
*/
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;
}
This library is very well ported, including to Solaris...