@@ -3,14 +3,18 @@ package Sys::Syscall; use strict; use POSIX qw(ENOSYS SEEK_CUR); +use Config; require Exporter; use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS $VERSION); $VERSION = "0.25"; @ISA = qw(Exporter); -@EXPORT_OK = qw(sendfile epoll_ctl epoll_create epoll_wait EPOLLIN EPOLLOUT EPOLLERR EPOLLHUP EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD); -%EXPORT_TAGS = (epoll => [qw(epoll_ctl epoll_create epoll_wait EPOLLIN EPOLLOUT EPOLLERR EPOLLHUP +@EXPORT_OK = qw(sendfile epoll_ctl epoll_create epoll_wait + EPOLLIN EPOLLOUT EPOLLERR EPOLLHUP EPOLLRDBAND + EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD); +%EXPORT_TAGS = (epoll => [qw(epoll_ctl epoll_create epoll_wait + EPOLLIN EPOLLOUT EPOLLERR EPOLLHUP EPOLLRDBAND EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD)], sendfile => [qw(sendfile)], ); @@ -19,6 +23,7 @@ use constant EPOLLIN => 1; use constant EPOLLOUT => 4; use constant EPOLLERR => 8; use constant EPOLLHUP => 16; +use constant EPOLLRDBAND => 128; use constant EPOLL_CTL_ADD => 1; use constant EPOLL_CTL_DEL => 2; use constant EPOLL_CTL_MOD => 3; @@ -53,6 +58,12 @@ if ($^O eq "linux") { # boundaries. my $u64_mod_8 = 0; + # if we're running on an x86_64 kernel, but a 32-bit process, + # we need to use the i386 syscall numbers. + if ($machine eq "x86_64" && $Config{ptrsize} == 4) { + $machine = "i386"; + } + if ($machine =~ m/^i[3456]86$/) { $SYS_epoll_create = 254; $SYS_epoll_ctl = 255; @@ -222,7 +233,7 @@ sub epoll_wait_mod4 { $epoll_wait_events = "\0" x 12 x $epoll_wait_size; } my $ct = syscall($SYS_epoll_wait, $_[0]+0, $epoll_wait_events, $_[1]+0, $_[2]+0); - for ($_ = 0; $_ < $ct; $_++) { + for (0..$ct-1) { @{$_[3]->[$_]}[1,0] = unpack("LL", substr($epoll_wait_events, 12*$_, 8)); } return $ct; @@ -235,7 +246,7 @@ sub epoll_wait_mod8 { $epoll_wait_events = "\0" x 16 x $epoll_wait_size; } my $ct = syscall($SYS_epoll_wait, $_[0]+0, $epoll_wait_events, $_[1]+0, $_[2]+0); - for ($_ = 0; $_ < $ct; $_++) { + for (0..$ct-1) { # 16 byte epoll_event structs, with format: # 4 byte mask [idx 1] # 4 byte padding (we put it into idx 2, useless)