Skip to content
Browse files

use sysread, syswrite instead of PerlIO

  • Loading branch information...
1 parent 8b0249e commit b126090790b1243dffc9af4514f1274f69bc2e4f @hirose31 hirose31 committed Sep 25, 2009
Showing with 9 additions and 3 deletions.
  1. +9 −3 echo-epoll.pl
View
12 echo-epoll.pl
@@ -4,6 +4,7 @@
use IO::Socket::INET;
use IO::Epoll;
use Fcntl;
+use POSIX qw(:errno_h);
my $concurrent = 10; # max event
my $port = 9010;
@@ -49,11 +50,16 @@
} else {
### >client: $ev->[0], $$
open my $sock, "+<&=".$ev->[0] or die "fdopen: $!";
- my $line = <$sock>;
- if ($line) {
- print $sock $line;
+ my $buf = "";
+ my $r = sysread $sock, $buf, 24;
+ #warn "[$r] <$buf> $ev->[0]\n";
+ if ($r) {
+ syswrite $sock, $buf, $r;
} else {
### no data: $ev->[0], $$
+ if (!defined $r && ($! == EINTR || $! == EAGAIN)) {
+ next;
+ }
epoll_ctl($epfd, EPOLL_CTL_DEL, $ev->[0], 0) >= 0
|| die "epoll_ctl: $!\n";
$Sock_Holder[$ev->[0]] = undef;

0 comments on commit b126090

Please sign in to comment.
Something went wrong with that request. Please try again.