Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Non-blocking socket read on Windows

by salva (Canon)
on Feb 13, 2006 at 14:41 UTC ( [id://529837]=note: print w/replies, xml ) Need Help??


in reply to Non-blocking socket read on Windows

On Windows, you can use this ioctl call to make the socket non blocking:
ioctl($socket, 0x8004667e, $nonblocking);

update: $nonblocking = 1 => makes the socket non blocking, $nonblocking = 0 => makes the socket blocking.

Replies are listed 'Best First'.
Re^2: Non-blocking socket read on Windows
by spurperl (Priest) on Feb 13, 2006 at 17:53 UTC
    This solution works admirably !

    After setting the ioctl() command you're suggesting on my socket, I'm reading from it using sysread(), which behaves in a non-blocking way, returning the amount of bytes it has actually read. This overall works much faster than my looping approach, especially for longer messages.

    Although this is probably off-topic, it's curious how the "magic value" of 0x8004667E is created. The "macro" for non-blocking IO in ioctl() is FIONBIO, and its calculation is done thus:

    IOC_IN = 0x80000000h; FIONBIO = IOC_IN + 4 * 65536 + ORD ('f') * 256 + 126;
    I wonder what is the rationale behind this ? Can someone explain how these things work ? Is it portable to just plunge the magic value in my code ?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-24 08:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found