Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Win32 Nonblocking Sockets

by jy38 (Initiate)
on Apr 20, 2001 at 22:05 UTC ( [id://74258]=perlquestion: print w/replies, xml ) Need Help??

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

I want to do some simple networking stuff on a win32 box and want to use nonblocking sockets. However whenever I try to use FCNTL it doesn't work namely since I'm on a win32 box.
So how do I get a recv call to be nonblocking? --John

Replies are listed 'Best First'.
Re: Win32 Nonblocking Sockets
by twerq (Deacon) on Apr 20, 2001 at 22:13 UTC
    I could be way off, and have never developed in Perl for Windows, but if you want to try setting your open socket to non-blocking, you can try

    $sock->blocking(0);

    . . . hopefully this is has been written to work properly on the windows platform.

    --twerq

      That calls IO::Handle::blocking whose code (found under ext/IO/IO.xs of the Perl source code distribution) boils down to this:

      static int io_blocking(InputStream f, int block) { int RETVAL; if(!f) { errno = EBADF; return -1; } #if defined(HAS_FCNTL) /* ... */ #else return -1; #endif }
      and HAS_FCNTL isn't defined under Win32 so it just always return -1 under Win32.

      I should try to patch that. ):

      Anyway, it isn't much help right now.

              - tye (but my friends call me "Tye")
        Windows does have fcntl but doesn't include O_NONBLOCK (according to mingw's headers). However I have coded non blocking sockets in a cross platform program. I used ioctl like this
        int on = 1; int error = IOCTL(server_socket, FIONBIO, &on); if (error < 0) die("Couldn't set non-blocking");
        Note that IOCTL == ioctl under unix and == ioctlsocket under windows.

        I don't know whether this is useful directly from perl under windows or not but it could certainly go in the xs module.

        Non blocking sockets are OK under windows, but it is practically impossible to make anything else non blocking - you have to get into overlapped IO etc shudder!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://74258]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-03-28 22:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found