
use strict;
use warnings;
use IO::Socket::INET;

Xchat::register( "Xchat::hook_fd test", "1.0000_01",
                 "Script for testing Xchat::hook_fd" );

my $sock = IO::Socket::INET->new( LocalAddr => "127.0.0.1",
				  LocalPort => 4242,
				  Proto => "udp",
				  ReuseAddr => 1,
				  Blocking => 0,
				  Timeout => 0,
				) or warn "Error creating socket: $@";
if( $sock ) {
	Xchat::print( ["Hooking fd, ", $sock->fileno] );
	Xchat::hook_fd( $sock,
		sub {
#			Xchat::print "Got data";
			my ($socket, $flags) = @_;
			my $bytes = sysread $socket, my $info, 1024;
			Xchat::set_context(Xchat::find_context);
#			Xchat::print "socket => $socket";
#			Xchat::print "flags => $flags";
#			Xchat::print "bytes => $bytes";
#			Xchat::print $info;
			Xchat::command( $info );
		}
	);
}
