[MLton] bug in MLton and bug in basis
Wesley W. Terpstra
wesley@terpstra.ca
Thu, 18 Aug 2005 16:46:03 +0200
On Aug 18, 2005, at 3:49 PM, Florian Weimer wrote:
> * Wesley W. Terpstra:
>> Next, whoever wrote the standard clearly did not understand what
>> Ctl.getERROR should do. It should return an OS.SysErr option, not
>> a bool! That system call tells you WHAT the last error was, not if
>> there
>> was an error on the last operation (which you can infer if the last
>> error had a value of 0).
>
> Is this some ML-specific feature? Usually, successful calls do not
> set the errno variable.
Maybe you misunderstood me..?
int status, n;
n = sizeof(status);
getsockopt(socket, SOL_SOCKET, SO_ERROR, (char*)&status,
(socklen_t*)&n);
The result stored in 'status' is the value of 'errno' after the last
call
on the provided socket. For example, if you just saw a socket become
writeable (after non-blocking connect), then 'status' will contain what
'errno' would have been if you had run a blocking connect.
The methods in Socket.Ctl.get* return the value of the pointed to
parameter (in this case 'status'), not the return code of getsockopt
itself.
If getsockopt fails, then errno as set by getsockopt forms the
OS.SysErr.
Compare with, for example, Ctl.getREUSEADDR which returns the
status of the re-use address flag, not the return code of getsockopt.
The problem is that the author of the standard thought that the
value stored in 'status' after a SO_ERROR was a bool.
That's wrong; it's an errno value.
>> The most common use of this system call is to determine the return
>> code from a previous non-blocking connect.
>
> You need some hackery to get this right because Solaris behaves
> differently from most systems. IIRC, Stevens provides a portable (in
> the practical sense) snippet of code in UNIX Network Programming.
I believe you are mistaken; I just checked the state-threads.sf.net
library which definitely runs on Solaris. They use SO_ERROR too.