]> git.pond.sub.org Git - empserver/commit
Revamp server's Windows POSIX compatibility code
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 13 Apr 2009 13:35:40 +0000 (15:35 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 30 Nov 2009 18:45:04 +0000 (19:45 +0100)
commit1c08ccf25bf9c02eebb30680a47e6dd7a2c6f143
tree97eeaef5ed21720f3b0f496c6ba6f174116f2c7f
parent798af5b45bfce190221fabe9c464e3253f6a575b
Revamp server's Windows POSIX compatibility code

Unlike POSIX sockets, Windows sockets are not file descriptors, but
"OS handles", with a completely separate set of functions.

However, Windows can create a file descriptor for a socket, and return
a file descriptor's underlying handle.  Use that instead of wrapping
our own file descriptors around Windows file descriptors and sockets.

Remove the wrapping machinery: MAX_FDS, enum fdmap_io_type, struct
fdmap, fdmap[], nfd, get_fd(), free_fd(), set_fd(), lookup_handle(),
lookup_fd().

Rewrite SOCKET_FUNCTION(), posix_accept(), posix_socket(),
posix_close(), ftruncate(), posix_open(), posix_read(), posix_write(),
fcntl().

Remove FILE_FUNCTION(), posix_fstat(), posix_lseek(),
SHARED_FUNCTION(), and fileno(), because the system's functions now
work fine.

posix_fsync() is used only #ifdef _WIN32, remove it, and call
_commit() directly.

The old code stuffed WSA error codes into errno, which doesn't work.
Use new w32_set_winsock_errno() to retrieve, convert & stuff into
errno.  Adapt inet_ntop() to set the WSA error code instead of errno,
so it can use w32_set_winsock_errno().

Move EWOULDBLOCK from sys/socket.h to w32misc.h, and drop unused
ENOTSOCK, EAFNOSUPPORT.

Use SOCKET rather than int in Windows-specific code.
src/lib/commands/powe.c
src/lib/empthread/ntthread.c
src/lib/w32/posixio.c
src/lib/w32/sys/socket.h
src/lib/w32/unistd.h
src/lib/w32/w32misc.h