Skip Menu |
 

Subject: Windows socket(...) returns SOCKET, not file handle
sendto_kdc.c start_connection(...) calls socket(...).

The returned SOCKET is treated as a file handle.

On Windows, the SOCKET is greater than FD_SETSIZE, so close is called.
The SOCKET is also greater than the number of file handles, so close
asserts.
Date: Fri, 21 Mar 2008 15:39:42 -0600
From: Jeffrey Altman <jaltman@mit.edu>
To: rt@krbdev.mit.edu
Subject: Re: [krbdev.mit.edu #5925] Windows socket(...) returns SOCKET, not file handle
RT-Send-Cc:
Kevin Koch via RT wrote:
Show quoted text
> sendto_kdc.c start_connection(...) calls socket(...).
>
> The returned SOCKET is treated as a file handle.
>
> On Windows, the SOCKET is greater than FD_SETSIZE, so close is called.
> The SOCKET is also greater than the number of file handles, so close
> asserts.

(1) close() is a C Runtime Library function that only works on C RTL
file descriptors. closesocket() must be used for SOCKET returned by
socket().

(2) FD_SETSIZE in winsock has no relation to the value of SOCKET
handles. FD_SETSIZE is the number of sockets that can be stored in an
fd_set. It is not a maximum bound on the value of the handle.

Arrays of FD_SETSIZE are not safe to use on Windows. Alternative data
structures must be designed that will work on all platforms including
UNIX/Linux systems whose "ulimit -n" values are raised above FD_SETSIZE.
Date: Fri, 21 Mar 2008 17:06:36 -0500
From: Nicolas Williams <Nicolas.Williams@sun.com>
To: rt@krbdev.mit.edu
Subject: Re: [krbdev.mit.edu #5925] Windows socket(...) returns SOCKET, not file handle
RT-Send-Cc:
Download (untitled) / with headers
text/plain 1.4KiB
On Fri, Mar 21, 2008 at 05:37:13PM -0400, Jeffrey Altman via RT wrote:
Show quoted text
> Kevin Koch via RT wrote:
> > sendto_kdc.c start_connection(...) calls socket(...).
> >
> > The returned SOCKET is treated as a file handle.
> >
> > On Windows, the SOCKET is greater than FD_SETSIZE, so close is called.
> > The SOCKET is also greater than the number of file handles, so close
> > asserts.
>
> (1) close() is a C Runtime Library function that only works on C RTL
> file descriptors. closesocket() must be used for SOCKET returned by
> socket().
>
> (2) FD_SETSIZE in winsock has no relation to the value of SOCKET
> handles. FD_SETSIZE is the number of sockets that can be stored in an
> fd_set. It is not a maximum bound on the value of the handle.
>
> Arrays of FD_SETSIZE are not safe to use on Windows. Alternative data
> structures must be designed that will work on all platforms including
> UNIX/Linux systems whose "ulimit -n" values are raised above FD_SETSIZE.

Agreed.

You might want to consider using libevent, which has support for "Linux,
*BSD, Mac OS X, Solaris and Windows" and which is distributed with a
3-clause BSD license (but without the advertising clause).

This should result in more portable code and should allow you to let
someone else worry about the low-level details of I/O polling and async
I/O on each OS. With any luck you might even be able to reduce the
amount of source code related to I/O polling and async I/O in MIT krb5
significantly.

Nico
--
Date: Fri, 21 Mar 2008 17:23:49 -0600
From: Jeffrey Altman <jaltman@mit.edu>
To: rt@krbdev.mit.edu
Subject: Re: [krbdev.mit.edu #5925] Windows socket(...) returns SOCKET, not file handle
RT-Send-Cc:
Download (untitled) / with headers
text/plain 1.1KiB
Nicolas Williams via RT wrote:

Show quoted text
> You might want to consider using libevent, which has support for "Linux,
> *BSD, Mac OS X, Solaris and Windows" and which is distributed with a
> 3-clause BSD license (but without the advertising clause).

It has a documentation requirement for the party that distributes
the libevent library or binaries that include the library. For KFW, I
believe the copyright and inclusion of libevent will have to be
documented. The license can be found at:

http://www.monkey.org/~provos/libevent/LICENSE

Show quoted text
> This should result in more portable code and should allow you to let
> someone else worry about the low-level details of I/O polling and async
> I/O on each OS. With any luck you might even be able to reduce the
> amount of source code related to I/O polling and async I/O in MIT krb5
> significantly.

Looking over the examples this looks like a very easy fix to the I/O
issues related to the use of UNIX fds larger than FD_SETSIZE. Using
libevent would be a definite win.

However, in locations where the socket fd is being used as an index
into an array of objects switching from select() to libevent will
not be the solution.

Jeffrey Altman
From: raeburn@mit.edu
Subject: SVN Commit

Don't do FD_SETSIZE check on Windows.
Also, for form's sake, use closesocket instead of close inside the check.

Kevin or Jeff, could you please verify that the code works again?
Commit By: raeburn



Revision: 20479
Changed Files:
U trunk/src/lib/krb5/os/sendto_kdc.c
[raeburn - Thu Jun 26 20:32:05 2008]:

Show quoted text
>
> Don't do FD_SETSIZE check on Windows.
> Also, for form's sake, use closesocket instead of close inside the check.
>
> Kevin or Jeff, could you please verify that the code works again?
> Commit By: raeburn
>
>
>
> Revision: 20479
> Changed Files:
> U trunk/src/lib/krb5/os/sendto_kdc.c

This is correct.

This fix is not required on the 1.6 branch so I am resolving the ticket.
From: Ken Raeburn <raeburn@MIT.EDU>
To: rt-comment@krbdev.mit.edu
Subject: Re: [krbdev.mit.edu #5925] Windows socket(...) returns SOCKET, not file handle
Date: Mon, 21 Jul 2008 14:29:38 -0400
RT-Send-Cc:
Okay. Thanks for checking.

Ken