Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Net::IRC and IO::Socket

by btrott (Parson)
on Jun 20, 2001 at 10:03 UTC ( [id://89927]=note: print w/replies, xml ) Need Help??


in reply to Net::IRC and IO::Socket

Two "monopolistic" processes can share, and that sharing is done through the use of select; select is used to wait on a set of sockets, and to pass control back to you when at least one of those handles is "ready". However "ready" is defined: for example, you may be waiting for the socket to be have data that can be read from it; or you could be waiting for the socket to be ready for writing, etc.

In this case, it's slightly tricky, because you want to intermix a socket "contained" by Net::IRC and one that you're using in your own application. After a look at the Net::IRC docs, it looks like you might be able to use the 'addfh' method to add your UDP socket handle to the list of handles in the select loop that is entered when you call the 'start' method.

When you use 'addfh', it looks like you give Net::IRC a filehandle, a callback function to call when the handle is "ready", and a flag saying what kind of handle this is (reading/writing/error).

So, in other words, you might do something like this (note: untested)--

$irc->addfh($socket, \&has_data, "r"); $irc->start; sub has_data { my $socket = shift; $socket->recv(my $data, 1024); ## Now trigger some Net::IRC event based on $data }
Note that you may need to investigate the exact args that get passed to your callback function; I'm not sure if the filehandle is the only thing passed. Note also that you'll need to get the Net::IRC object somehow, I believe, in order to send an event based on $data; one way to do this would be to create the callback function as a closure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-24 01:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found