Connect nonblocking socket in win32 #100

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
4 participants
@don-pit

don-pit commented Mar 3, 2013

Last part of pull request #94 (prolonged connection phase on nonblocking socket).

Connect nonblocking socket in win32
If socket is nonblocking and connection cannot be completed immediately,
connect() sets last error to WSAEWOULDBLOCK (as stated in MSDN).
@lpc921

This comment has been minimized.

Show comment
Hide comment
@lpc921

lpc921 Jul 8, 2013

Works for me on VS2008 and MinGW. Thanks.

lpc921 commented Jul 8, 2013

Works for me on VS2008 and MinGW. Thanks.

@morgoth6

This comment has been minimized.

Show comment
Hide comment
@morgoth6

morgoth6 Jul 13, 2013

There seems to be a problem with this patch as it fails for me when attempt to connect() to modbus client on Win32 (both VS2008 and MinGW)

According to MSDN (http://msdn.microsoft.com/en-us/library/windows/desktop/ms737625%28v=vs.85%29.aspx) the connect() returns WSAEWOULDBLOCK in case on non blocking socket connection in progress:

"With a nonblocking socket, the connection attempt cannot be completed immediately. In this case, connect will return SOCKET_ERROR, and WSAGetLastError will return WSAEWOULDBLOCK."

Changing the if() in _connect() from:

if (rc == -1 && WSAGetLastError() == WSAEINPROGRESS) {

to

if (rc == -1 && WSAGetLastError() == WSAEWOULDBLOCK) {

Seems to fix the connection problems for me. But to be honest it would be good to think for a real solution for this errno mess in "One-True-Correct-And-Right-In-All-Places" system (read Windows) My current project assumes both Linux and Windows portability and it would be nice to have both.

There seems to be a problem with this patch as it fails for me when attempt to connect() to modbus client on Win32 (both VS2008 and MinGW)

According to MSDN (http://msdn.microsoft.com/en-us/library/windows/desktop/ms737625%28v=vs.85%29.aspx) the connect() returns WSAEWOULDBLOCK in case on non blocking socket connection in progress:

"With a nonblocking socket, the connection attempt cannot be completed immediately. In this case, connect will return SOCKET_ERROR, and WSAGetLastError will return WSAEWOULDBLOCK."

Changing the if() in _connect() from:

if (rc == -1 && WSAGetLastError() == WSAEINPROGRESS) {

to

if (rc == -1 && WSAGetLastError() == WSAEWOULDBLOCK) {

Seems to fix the connection problems for me. But to be honest it would be good to think for a real solution for this errno mess in "One-True-Correct-And-Right-In-All-Places" system (read Windows) My current project assumes both Linux and Windows portability and it would be nice to have both.

#ifdef OS_WIN32
- if (rc == -1 && WSAGetLastError() == WSAEINPROGRESS) {

This comment has been minimized.

This comment has been minimized.

@don-pit

don-pit Jul 16, 2013

Sorry, I miss the point. The check against WSAEWOULDBLOCK is introduced within this diff hunk.

@don-pit

don-pit Jul 16, 2013

Sorry, I miss the point. The check against WSAEWOULDBLOCK is introduced within this diff hunk.

@stephane

This comment has been minimized.

Show comment
Hide comment
@stephane

stephane Jan 28, 2014

Owner

Thank you @don-pit for your patch.

Owner

stephane commented Jan 28, 2014

Thank you @don-pit for your patch.

@stephane stephane closed this in 706fa6b Jan 28, 2014

mk8 added a commit to mk8/libmodbus that referenced this pull request Jan 29, 2014

Fix TCP IPv4 modbus_connect() on win32 (closes #100 and #165)
Thank you Petr Gladkiy and MarjanTomas.
Sorry for the delay...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment