我正在使用带有TCP服务器的select.我想将STDIN添加到选择文件句柄集.
#!/usr/bin/perl use IO::Select; use IO::Socket::INET; my $sock = IO::Socket::INET->new(LocalPort => $serv_listen_port,Proto => 'tcp',List en=> 1); my $s = IO::Select->new(); $s->add(\*STDIN); #want to be responsive to user input (allow me to type commands for example) $s->add($sock); @readytoread=$s->can_read(1); #timeout = 1sec foreach $readable (@readytoread) { if ($readable==$sock) { #This was a listen request,I accept and add new client here } if ($readable == STDIN){ #what to do on this line? #This is user typing input into server on terminal } }
在这里的代码中需要第4行到最后一行的帮助.
解决方法
$readable->fileno == fileno STDIN
或者,如果您对此感到满意,则fileno STDIN为零,您可以直接检查.