<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=big5">
<META content="MSHTML 6.00.2800.1561" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2>
<DIV><FONT size=2>Sorry my english is very poor. Our mother language is
chinese.</FONT></DIV>
<DIV><FONT
size=2>===============================================================</FONT></DIV>
<DIV><FONT size=2>I have some problem about epoll. The </FONT><FONT
size=3>Danga::Socket use epoll ,too. Is it have the</FONT></DIV>
<DIV>same problem?</DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV>When i use one program to send data. The speed of upload file is
slow.<BR>But when i use two(>=2) programs to testing the transmission speed
at<BR>the same time. It is very fast. The transmission speed is almost
equal<BR>to (* how many programs is running)<BR><BR>I can not find any solution
to slove the problem.I try to modify the the<BR>value of epoll_wait()'s
parameter.<BR><BR>my $events_count = epoll_wait( $epoll,15,3600, $events
);<BR>my $events_count = epoll_wait( $epoll,2,0, $events );<BR>my $events_count
= epoll_wait( $epoll,2,-1, $events );<BR>my $events_count = epoll_wait(
$epoll,2,100, $events );<BR><BR>But the problem still exist.<BR>And i find that
the $events_count always is 1 when i upload file via<BR>another
programs.<BR>=========================================================<BR>#!/usr/bin/perl<BR>use
strict;<BR>use IO::Socket;<BR>use Sys::Syscall ':epoll';<BR>use Errno
'EWOULDBLOCK';<BR>my ( $haveEpoll, $epoll );<BR>if (
Sys::Syscall::epoll_defined() )<BR>{<BR> $epoll = eval { epoll_create(1);
};<BR> $haveEpoll = defined $epoll && $epoll >= 0;<BR>}<BR>if (
!$haveEpoll )<BR>{<BR> require IO::Poll;<BR>}<BR><BR>my $listen =
IO::Socket::INET->new(Proto =>
'tcp',<BR> LocalPort =>
21,<BR> Listen => SOMAXCONN
,<BR> Reuse => 1) or die
$!;<BR><BR>PollIn_Event_Add( $epoll, fileno($listen) );<BR><BR>my
%accepthash;<BR>my $events;<BR>while (1)<BR>{<BR> $events = [];<BR> my
$events_count = epoll_wait( $epoll,15,3600, $events );<BR><BR> for ( my $i
= 0 ; $i < $events_count ; $i++ )<BR> {<BR> my $ev =
$events->[$i];<BR> $ev ||=
[];<BR><BR> if (! defined
$accepthash{$ev->[0] } && $ev->[0] eq<BR>fileno($listen)
){<BR> my
$connect=$listen->accept();<BR>
PollIn_Event_Add( $epoll, fileno($connect)
);<BR>
$accepthash{fileno($connect)}=$connect;<BR>
open(handle,">/usr/local/Portal/cache/" . fileno($connect) );<BR>
close(handle);<BR>
}else{<BR><BR> if ( $ev->[1] == EPOLLIN )<BR> {<BR>
my $buffer='';<BR> my $rc = sysread($accepthash{$ev->[0]},
$buffer, 16384,0 );<BR> if ( defined $rc )<BR>
{<BR> if ( $rc > 0 )<BR>
{<BR> #print $rc . "\n";<BR>
open(handle,">>/usr/local/Portal/cache/" .
$ev->[0]);<BR> print handle
$buffer;<BR> close(handle);<BR>
substr( $buffer, 0, $rc ) = '';<BR> }
else<BR>
{<BR><BR>
eval { shutdown( $accepthash{$ev->[0]}, 2 );
};<BR>
delete $accepthash{$ev->[0]};<BR> }<BR><BR><BR>
} elsif ( $! == EWOULDBLOCK )<BR> {<BR><BR> }
else<BR>
{<BR><BR>
eval { shutdown( $accepthash{$ev->[0]}, 2 );
};<BR>
delete $accepthash{$ev->[0]};<BR> PollIn_Event_Del( $epoll,
$ev->[0] );<BR> }<BR><BR> }elsif($ev->[1] ==
EPOLLERR){<BR><BR>
eval { shutdown( $accepthash{$ev->[0]}, 2 );
};<BR>
delete $accepthash{$ev->[0]};<BR> PollIn_Event_Del( $epoll,
$ev->[0] );<BR> }<BR>
}<BR> }<BR>}<BR><BR>sub PollIn_Event_Add<BR>{<BR> my ( $epoll, $fd ) =
@_;<BR> my $ctl_rtn;<BR> $ctl_rtn = epoll_ctl( $epoll, EPOLL_CTL_ADD,
$fd, EPOLLIN | EPOLLERR );<BR> print 'PollIn_Event_Add:' . $ctl_rtn .
"\n";<BR>}<BR><BR>sub PollIn_Event_Del<BR>{<BR> my ( $epoll, $fd ) =
@_;<BR> my $ctl_rtn;<BR> $ctl_rtn = epoll_ctl( $epoll, EPOLL_CTL_DEL,
$fd,0 );<BR> print 'PollIn_Event_Del:' . $ctl_rtn .
"\n";<BR>}<BR></DIV></FONT></DIV></BODY></HTML>