#758 EWOULBLOCK not set in RxSock on 3.2.0

v4.1
closed
5
2012-08-14
2009-07-14
regli
No

ooRexx 3.2.0
Windows 7 RC (7100)
Contact me at regli .. at .. yahoo.com

Trying to implement non blocking I/O I encountered that EWOULBLOCK is not set by SockAccept when in non blocking mode.

The following code should allow easy validation of the claim as there is no client and accept would block unless set to non-blocking.:

/ main program /
serverPort = 3700

If RxFuncQuery('SockDropFuncs') then do
rc = RxFuncAdd("SockLoadFuncs","rxsock","SockLoadFuncs")
rc = SockLoadFuncs()
end

/ setup TCP socket /
s = SockSocket('AF_INET','SOCK_STREAM','0')
if (s < 0) then do
say processName 'SockSocket error: 'errno' !' h_errno
endcode = 8
exit endcode
end

/ We want to reuse the same socket. This will prevent a socket in use msg.

/
rc = SockSetSockOpt(s, "SOL_SOCKET", "SO_REUSEADDR", "1");
if (rc < 0) then do
say processName 'SockSetSocketOpt error: 'errno' !' h_errno
endcode = 8
exit endcode
end

server.!family = 'AF_INET'
server.!port = serverPort
server.!addr = 'INADDR_ANY' / receive on all IP addresses /

/ Bind Socket to Port /
rc = SockBind(s,'server.!')
if (rc < 0) then do
say processName 'SockBind error: 'errno' !' h_errno
endcode = 8
exit endcode
end

/ create a connection queue for x clients /
rc = SockListen(s, 20)
if (rc < 0) then do
say processName 'SockListen error: 'errno' !' h_errno
endcode = 8
exit endcode
end

/ uncomment to set to blocking
rc = SockIoctl(s,"FIONBIO", "0");

/
/ set connect socket to non-blocking /
rc = SockIoctl(s,"FIONBIO", "1");
if rc < 0 then do
say processName 'SockIoctl error: 'errno' !' h_errno
endcode = 8
exit endcode
end

cs = SockAccept(s, "client!")
if cs < 0 then do
/ should check for EWOULDBLOCK but ooRexx 3.2+ doesn't seem to return it /
say processName 'SockAccept error: 'errno' !' h_errno
end

rc = SockShutDown(s,2)
call SysSleep(1.0)
rc = SockClose(s)

exit 0 / leave program /

Discussion

  • Mark Miesfeld

    Mark Miesfeld - 2010-08-15

    Hi,

    Sorry it has taken so long to give you a repsonse to this. We don't have the resources to always respond promptly to bugs.

    This seems to be a Windows problem rather than a bug in ooRexx. Your example program works fine on Ubuntu and Fedora Core 13 EWOULDBLOCK is set as expected.

    However, on Windows, Windows simply does not set the error code. ooRexx is merely reporting the status set by Windows, which is 0. WSAGetLastError(), which is what should be used on Windows, reports 0.

    I put in a debugging statement right after the accept() call in the underlying C++ implementation:

    Windows accept() ret=-1 INVALID_SOCKET=-1 errno=0 WSAGetLastError()=0

    Running your program on Windows:

    C:\work.ooRexx\ewouldblock>testEWOULBLOCK.rex
    Windows accept() ret=-1 INVALID_SOCKET=-1 errno=0 WSAGetLastError()=0
    PROCESSNAME SockAccept error: 0 ! 1541
    SockSock_Errno: 0

    C:\work.ooRexx\ewouldblock>

     
  • Mark Miesfeld

    Mark Miesfeld - 2010-08-16

    Committed revision 6112.

    This is fixed in trunk and you will see the fix in the next release of ooRexx.

    This was our bug. If the address arg to SockAccept() is used, we fill in the stem with the returned address after the underlying accept() is invoked, then we set errno and h_errno. On Windows only, one of the functions used to fill in the stem sets errno back to 0.

    In your example program, if you change this line:

    cs = SockAccept(s, "client!")

    to

    cs = SockAccept(s)

    you will see errno set to EWOULDBLOCK as you expect.

     
  • Mark Miesfeld

    Mark Miesfeld - 2010-09-09

    Committed revision 6161.

    4.1.0 merge

     
  • Mark Miesfeld

    Mark Miesfeld - 2010-12-05

    The fix for this item was in the 4.1.0 release.

     


Anonymous

Cancel  Add attachments





Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks