Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To understand this, you have to realize that Winsock was created in the early 1990s, back when the Windows 3.x dinosaur roamed the earth.</p> <p>The Windows Sockets ("Winsock") API mirrors most of the BSD sockets API: where both provide a given function, both do the same thing. So, <code>socket()</code> is the same call under both APIs. There are minor differences in places, but nothing bigger than the differences in network programming for other systems based on BSD sockets, such as Linux and OS X.</p> <p>In addition to implementing that common base API, the Winsock API also provides many extensions to BSD sockets. Many have names similar to the original functions, but with a <code>WSA</code> prefix and camel-case for everything else. These are purely extended versions of the original functions, not replacements for them. You pick which one to use depending on whether you need the extended functionality and whether your program has to be portable to systems that provide only the BSD sockets API. For instance, <code>WSASocket()</code> takes the same parameters as <code>socket()</code> plus three additional ones which have to do with other Winsock extensions. If you do not need the extensions, there is no real penalty to calling <code>socket()</code> instead, and you get a portability benefit besides.</p> <p>In addition to these simple extensions, there are Winsock extensions that have no direct BSD equivalent, such as <code>WSAAsyncSelect()</code>. These generally have to do with differences in the way Windows programs are written, as compared to programs for Unixy systems. In this particular case, <code>WSAAsyncSelect()</code> exists to make it easier to write single-threaded GUI programs that use sockets without network I/O blocking the GUI or <em>vice versa</em>. This is useful today, but absolutely critical to Winsock's success back in the Windows 3.1 days, which didn't have threads or other useful multiprocessing and IPC mechanisms.</p> <p>That leaves only a few oddballs like <code>closesocket()</code> and <code>ioctlsocket()</code>.</p> <p><code>closesocket()</code> is the same as <a href="http://linux.die.net/man/2/close" rel="noreferrer"><code>close(2)</code></a> under POSIX/Unix, except that it only takes sockets, not file handles. That's part of the reason for the name change, but the real reasons come from that early-1990s history issue I brought up above. In those days, some Windows compilers &mdash; there were <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Zortech" rel="noreferrer">more</a> <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Watcom_C/C%2B%2B_compiler" rel="noreferrer">available</a> <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Borland_C%2B%2B" rel="noreferrer">then</a> than today &mdash; included POSIX API equivalents to ease porting code from other platforms to Windows. Such features were very limited, and didn't include sockets support, but nevertheless, the <code>close()</code> function name was considered "taken" on Windows at that time. It isn't true any more, but Winsock is a product of its history and can't be changed now.</p> <p>The story for <code>ioctlsocket()</code> vs. <code>ioctl()</code> is similar. One big difference is that <code>ioctlsocket()</code> is greatly limited on Windows as compared to what <code>ioctl()</code> can do on a Unix system. It exists only to provide Windows with a few network-related facilities that the original Winsock creators thought useful in the BSD sockets API. Over the years, much of what you can do with sockets and <code>ioctl()</code> on Unixy systems but not with <code>ioctlsocket()</code> has been added to Windows through other APIs, just one of which is <code>WSAIoctl()</code>.</p> <p>I've written an article on "<a href="http://tangentsoft.net/wskfaq/articles/history.html" rel="noreferrer">The History of Winsock</a>" for the <a href="http://tangentsoft.net/wskfaq/" rel="noreferrer">Winsock Programmer's FAQ</a> (which I maintain) that goes into more detail on all this. Another relevant article is "<a href="http://tangentsoft.net/wskfaq/articles/bsd-compatibility.html" rel="noreferrer">BSD Sockets Compatibility</a>."</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload