[M3devel] the lingering socket linger question, non-blocking Win32 sockets?

Jay K jay.krell at cornell.edu
Mon Apr 19 05:27:01 CEST 2010


shorter story:

  - Does anyone have significant socket-using Modula-3 code to test? That is used on Posix and Win32?

  - Given the extremely high similarly between the Windows and Posix (BSD) socket interfaces, I strongly suggest we unify the implementations, including removing some of the historical differences. I also strongly suspect the Posix implementation is the "better" one, that has recieved more thought and testing. The Win32 variants of the Modula-3 libraries often seem..suspicious.

Like they were a very initial version but never really recieved the attention needed.

 

 

longer story:

 

So..I've asked a few times, why this seemingly opposite code:

 

 

C:\dev2\cm3.2\m3-libs\libm3\src\os\POSIX\SocketPosix.m3(453):    linger := struct_linger{1, 1};
C:\dev2\cm3.2\m3-libs\libm3\src\os\WIN32\SocketWin32.m3(401):    linger := struct_linger{0, 0};



I have a *little* more information.

 

 

 Windows documentation warns about using linger{1} on non-blocking sockets.

 The default {0} seems to be what you'd want. Seems like the setsockopt isn't needed.

 SocketPosix.m3 sets sockets to be non-blocking.

    I associate "non blocking" with "prone to be slow or hang-until-timeout in real world, want to avoid that".

 Older SocketWin32.m3 seems to have in mind non-blocking:

Searching for 'WSAEWOULDBLOCK'...
C:\dev2\cm3.2\m3-libs\libm3\src\os\WIN32\SocketWin32.m3.sav(137):        | WinSock.WSAEWOULDBLOCK =>
C:\dev2\cm3.2\m3-libs\libm3\src\os\WIN32\SocketWin32.m3.sav(189):        | WinSock.WSAEWOULDBLOCK =>
C:\dev2\cm3.2\m3-libs\libm3\src\os\WIN32\SocketWin32.m3.sav(241):        | WinSock.WSAEWOULDBLOCK =>
C:\dev2\cm3.2\m3-libs\libm3\src\os\WIN32\SocketWin32.m3.sav(274):        | WinSock.WSAEWOULDBLOCK =>
C:\dev2\cm3.2\m3-libs\libm3\src\os\WIN32\SocketWin32.m3.sav(315):          | WinSock.WSAEWOULDBLOCK =>
C:\dev2\cm3.2\m3-libs\libm3\src\os\WIN32\SocketWin32.m3.sav(356):          | WinSock.WSAEWOULDBLOCK =>


 

  current SocketWin32.m3 does *not* set the sockets to non-blocking.

 

 

And there seems to be patterns to account for that -- checking BytesAvailable at the start of operations like Read and ReceiveFrom, where the Posix version does not. The Posix version using select/poll where the Win32 version does not (though the win32 ".sav" files does).

 

 

SocketWin32.m3.sav:

    IF WinSock.ioctlsocket (sock, WinSock.FIONBIO, ADR(one)) = SockErr THEN


 

 

Using select/poll in Posix is slightly complicated by user threads.

  The complexity is under the covers in the thread implementation.

Win32 doesn't have that problem.

 

 

 - Jay

 
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100419/85914135/attachment-0001.html>


More information about the M3devel mailing list