http://qs321.pair.com?node_id=89927


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.