"Gisle Vanem" <[EMAIL PROTECTED]> writes:

>> #ifndef ENOTCONN
>> # define ENOTCONN X_ENOTCONN
>> #endif
>
> Except you cannot make Winsock return X_ENOTCONN.

But we don't really care because we're in control of what gets stores
into errno after Winsock calls.  So instead of:

  errno = WSAGetLastError ();

windows_select and friends can go ahead and say:

  errno = winsock_error_to_errno (WSAGetLastError ());

winsock_error_to_errno and esaily convert Winsock errors to errno
errors expected by the rest of Wget, adding support for the missing
ones such as ENOTCONN.

> It returns WSAENOTCONN (def'ed to ENOTCONN in mswindows.h).

If we do this, we should probably remove those defines.  They would no
longer be needed.

>> const char *
>> windows_strerror (int err)
>> {
>>   /* Leave the standard ones to strerror. */
>>   if (err < X_ERRBASE)
>>     return strerror (err);
>> 
>>   /* Handle the unsupported ones manually. */
>>   switch (err)
>>     {
>>       case X_ENOTCONN:
>>         return "Connection refused";
>
> Which AFAICS is the pretty much the same as in my patch.

One difference is that your patch requires the use of special
GET_ERRNO and SET_ERRNO codes that I'm trying to avoid.  Another is
that windows_strerror calls real strerror for everything except for
the few error codes which really are unavailable under Windows, such
as ENOTCONN.  This should (I think) remove the need for the large
switch you have in get_winsock_error.

> Another thing is that Wget could mask errnos for Unix too. In
> connect.c:
>
>  ...
>    {
>      CLOSE (sock);
>      sock = -1;
>      goto out;
>    }
>
> out:
> ...
>  else
>    {
>      save_errno = errno;
>      if (!silent)
>        logprintf (LOG_VERBOSE, "failed: %s.\n", strerror (errno));
>      errno = save_errno;
>    }
>
> The close() could possibly set errno too, but we want the errno 
> from bind() or connect() don't we?

For close() to set errno, it would have to fail, and that should not
be possible in normal operation.  (Unlike fclose, close cannot write
data, it should just tell kernel to get rid of the descriptor.)  If
close really fails, then something is seriously wrong and we care
about the errno from close at least as much as we care about errno
from connect or bind.  In practice it probably doesn't make sense to
care about close setting errno.

Reply via email to