To check for a complete line just use a regex:
if ($buf =~ s/(.*\n)//) {
# line is in $1
my $line = $1;
...process $line here...
}
Note that the s operator conveniently removes the first complete line from $buf as well as returns whether there was a complete line found or not.
btw, have you considered using the Net::IRC module? Have a look at this example: http://jk0.org/projects/perl-irc-bot/
| [reply] [d/l] [select] |
I have considered that but will it work with the GTK2 environment? most of these methods work but the problem is using them with GTK2 when you try to send something to the server. Parse::IRC was a real simple way to do this but I cant get it to work in GTK2 (since it seems that timeouts and IO's never work for me) so I'm going to give Net::IRC a run and see if that works better (though I'm not hopeful).
| [reply] |
I think you should rethink your design a bit, to avoid relying on the IO::Watch to watch the filehandle. You could setup a timer instead to read the filehandle at a fast interval, and check for $die at every timer callback run. Another super simple "hack", would be to have the server send out newlines to every client, like a strobe, every second. Then in your code, when the socket reads just a newline, close up and go to the end of the thread code block.
| [reply] |