Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Problem handling 2 simultaneous socket streams

by BrowserUk (Patriarch)
on Sep 15, 2011 at 14:55 UTC ( [id://926162]=note: print w/replies, xml ) Need Help??


in reply to Problem handling 2 simultaneous socket streams

# NEXT LINE IS BLOCKING --------------------------- if(defined($buf1=<$socket>)) { #put stream2 into buf1

Using buffered IO with non-blocking sockets is a no-no. readline() (<>) won't return until it sees the current delimiter (typically "\n"); if the other end sends data without a delimiter, it will block; if the other end never gets around to sending a delimiter, then it will block forever.

The solution is to use read, sysread or recv, but then you'll need to buffer and track the delimiters yourself, which gets awfully messy.

The whole thing would be far simpler using threads.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2026-02-10 14:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.