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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re: Net::IRC and IO::Socket by btrott
in thread Net::IRC and IO::Socket by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-19 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found