<< |
Winsock Programmer's FAQ |
>> |
Winsock's Compatibility With BSD Socketsby Warren Young So you say you're a long-time Unix hacker who's new to Windows
programming? And you've heard of this great API called Winsock that's
compatibile with your beloved BSD sockets, but try as you might, you
just can't find the IntroductionIn the beginning, there was chaos. This chaos was in the form of incompatible Windows TCP/IP APIs: a program written for, say, FTP Software's TCP/IP stack wouldn't run on JSB's stack. Then, sometime in 1990, a bunch of people got together and decided to make one nice, big, compatible API called Windows Sockets that would allow a single program to run on any vendor's stack. They decided to base this API on the popular BSD sockets model of network programming, but for various reasons, they didn't include every BSD sockets feature. This article will tell you how to get similar behavior to several BSD features using other Winsock or Win32 facilities. This article is still evolving. Each entry below has two dates after it: an "added" and an optional "modified" date. So, you can periodically come back to this document to see if any new BSD-like behaviors have been uncovered in the Winsock API. Changes to this document will be announced on the main Winsock Programmer's FAQ page, in the What's New section.
The Unix Incidentally, the Winsock method is somewhat more powerful than the
Unix version, because you can pass the duplicated socket to an unrelated
process without any extra steps, whereas a simple
There is partial support for this feature under Winsock, though
the mechanism is dissimilar to the Item Q190351 in the Microsoft Knowledge Base documents a method by which you can redirect a child process's standard handles to a socket. The limitations are that you cannot do this to your own process's handles, you cannot redirect arbitrary handles to a socket (i.e. you can only do it with stdin, stdout and stderr), and not all processes are fully compatible with this API feature. Still, it at least makes an inetd-like program possible under Win32.
Symbolic Error Values (Added 1999.09.25) Most of the error values that EAGAIN (Added 1998.12.24) Many Unix programs, especially those with System V roots, check
for the EAGAIN value in the global readv() and writev() (Added 1998.08.01) BSD sockets' scatter/gather mechanism is very similar to parts of
Winsock 2's overlapped I/O mechanism. Overlapped I/O allows you to pass
several buffers to Equivalence of File and Socket Handles (Added 1998.08.01) Under Winsock 1.1, socket handles are completely distinct from the file handles issued by Win16 and Win32's native I/O facilities. For example, under BSD Unix, you can pass a socket handle to a function that will read from a file. This won't work under Winsock 1.1. Winsock 2, with its close ties to Win32, changes this. Under Winsock
2, a socket handle is now equivalent to a Win32 file handle. So, the
Win32 Winsock's BSD Unix (and other flavors of Unix) provides the
Detecting a Dropped Connection (Added 1999.09.25) Under BSD Unixes, if the remote peer closes its connection and your
program is blocking on Things are different under Winsock. A Cry For UpdatesThis article can always use more work. As it is, it gives a few good
bits of info about BSD-like behavior under Winsock, but there are still
many, many holes left to fill. If you can help me out, please drop me a
line! In particular, the Copyright © 1998-1999 by Warren Young. All rights reserved. |
<< Debugging TCP | WsControl() Revealed >> |
Last modified on 29 April 2000 at 15:52 UTC-7 | Please send corrections to tangent@cyberport.com. |
< Go to the main FAQ page |
|
<<< Go to my Home Page |