otijim has asked for the wisdom of the Perl Monks concerning the following question:

I am using some code in the Network Programming with Perl book, but I'm coding in Win32 (Win2k) with ActiveState Perl.

I'm using the IO::Getline (pg 368) example, trying to get some NON-Blocking IO for sockets.
It calls for a line:
use Errno 'EWOULDBLOCK';

Perl complains that there is no EWOULDBLOCK. I suppose this is because Win32 doesn't support. Is there a Win32 Equivalant(sp?).

I searched all over, I found a module called Win32::WinError but I didn't see anything that looked like it correlated.

Thanks
  • Comment on Win32 equivalant to Errno 'EWOULDBLOCK'

Replies are listed 'Best First'.
(tye)Re: Win32 equivalant to Errno 'EWOULDBLOCK'
by tye (Sage) on Jul 20, 2001 at 00:02 UTC

    Networking sockets are second-class objects under Win32 (they aren't integrated into the C RTL's I/O subsystem nor into the operating system). So the error codes are only found in WinSock.h and don't get put into the C RTL's errno and they are called things like "WSAEWOULDBLOCK".

    Perl does copy them into $! but that isn't very handy because a bug in Perl causes:     print $!=10035 to print simply "Unknown error". It should at least report "Unknown error (10035)"! I actually started work on a patch for this that would also allow me to write a module that, when used, would cause it to print "WinSock operation would block" (for example). I ran into some snags (like "use Errno" using %! in a strange way so that I couldn't use it and so had to come up with some global varable name) and never finished the patch so it looks like even the "Unknown error (10035)" part of the patch got dropped. ):

    But this is all relatively unimportant compared to the fact that you'll have quite a bit of trouble getting sockets to be non-blocking under Win32. I've seen a couple of proposals for rather ugly hacks that have been reported to work (I just tried to find them but it will take me some more time in Super Search to come up with them) as well as some ideas on patching Perl to make the standard SOCK->blocking(0) work.

    So we should probably patch the Errno.pm-generating code to pull in the non-overlapping WSAE* codes for compatability...

    I'm sorry that this isn't my first priority right now so that some of these good patch ideas aren't likely to get implemented by me soon. But if anyone feels qualified do some patching work, I'd be happy to offer guidance. /:

            - tye (but my friends call me "Tye")
      It seems from Microsoft's documents, the easiest way to get the error code is to use win32::GetLastError().

        Oh, that isn't the problem at all. You can already get the error code via 0+$! (and probably via 0+$^E). But you can't get a description for the error; not with the standard method used for $! [C's strerror()] nor with the standard method used for $^E/GetLastError() [Win32::FormatMessage()] nor with any subroutine that I've found. They don't even have error descriptions in the comments in WinSock.h.

        So my plan was to write error descriptions and put them into a module and patch Perl such that $! would know where to find these descriptioins when its regular method failed. And that looks easier to you than using $! or $^E? Getting the error code isn't the hard part.

                - tye (but my friends call me "Tye")
Re: Win32 equivalant to Errno 'EWOULDBLOCK'
by MeowChow (Vicar) on Jul 19, 2001 at 23:44 UTC