Re: MemPool.c's

From: Guido Serassio <serassio@dont-contact.us>
Date: Tue, 16 Apr 2002 22:30:43 +0200

Hi Henrik,

Il 22.04 16/04/2002 Henrik Nordstrom ha scritto:
>Guido Serassio wrote:
>
> > Sorry, but I just removed this from the nt source code ....
>
>Just curious, but how do you now deal with the difference in file and socket
>filedescriptors, and their possible numeric overlap?
>
>(too lazy to dig into the nt branch to find out..)

The difference between Files ant Sockets it's present only at the MSVCRT
level. For NT all are simply handles to something.
So, using _get_osfhandle(), _open_osfhandle() and _free_osfhnd() MSVCRT
functions that works on real OS handles remapped on MSVCRT FD will make the
magic:

#define socket(f,t,p) \
         (INVALID_SOCKET == ((SOCKET)ws32_result = socket(f,t,p)) ? \
         ((WSAEMFILE == (errno = WSAGetLastError()) ? errno = EMFILE : -1),
-1) : \
         (SOCKET)_open_osfhandle(ws32_result,0))

#define closesocket(s) \
         { \
         (SOCKET_ERROR == closesocket(_get_osfhandle(s)) ? \
         (errno = WSAGetLastError()), -1 : 0); \
         _free_osfhnd(s); \
         _osfile(s) = 0; \
         }

#define select(n,r,w,e,t) \
         (SOCKET_ERROR == (ws32_result = select(n,r,w,e,t)) ? \
         (errno = WSAGetLastError()), -1 : ws32_result)

And so on.
In this manner Unix Socket code compiles unchanged at 99% and the major
problem that socket handle ordinal returned from socket() are not reused
and always grows without sequentiality is resolved.

The only limit is that FD count limit is hard coded to 2048.

For this work, we must thanks Andrey Shorin.

Regards

Guido

>Regards
>Henrik

-
=======================================================
Serassio Guido
Via Albenga, 11/4 10134 - Torino - ITALY
E-mail: guido.serassio@serassio.it
WWW: http://www.serassio.it
Received on Tue Apr 16 2002 - 14:31:17 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:15:11 MST