views:

406

answers:

4

Is there any benefit on Windows to use the WSA winsock functions compared to the BSD-style ones?

+2  A: 

Only if you plan to deploy to a legacy platform like Windows 95 or there is something in the winsock API that you absolutely cannot live without and you don't want to roll yourself (<-- doubtful tho).

Jason Coco
+2  A: 

The most significant difference is the availability of Asynchronous Event style APIs in Winsock.

With Berkeley sockets, each time you read or write your application will "block" until the network is ready, which could make your application unresponsive (unless the network I/O is handled in a different thread).

With an async interface, you can arrange for a callback function to be called as part of the normal windows message loop each time data is received or when the transmit buffer is empty.

Alnitak
On Linux, BSD sockets allow non-blocking reads, or you can use select() to see if there is any data available. I'd assume the same is on windows, but it may be that feature is missing in the BSD socket API.
davr
A: 

With respect to Alnitak's answer, I agree - I'd just add that you need not use a message loop to use asynch operations on sockets. Using I/O completion ports is a very scalable way to build a high-performance networked application.

+1  A: 

If you design around the BSD paradigm, your code can work on other platforms with less porting work. If you assume that your network library will support asynchronous I/O (as Alnitak mentions), you're going to have to do a lot more work if that gets pulled out from under you.

Of course, if you're sure you'll never leave the warm bosom of Microsoft, feel free to go to town.

Coderer