Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > perl and epoll

Reply
Thread Tools

perl and epoll

 
 
sonet
Guest
Posts: n/a
 
      11-03-2006
When i use one program to send data. The speed of upload file is slow.
But when i use two(>=2) programs to testing the transmission speed at
the same time. It is very fast. The transmission speed is almost equal
to (* how many programs is running)

I can not find any solution to slove the problem.I try to modify the the
value of epoll_wait()'s parameter.

my $events_count = epoll_wait( $epoll,15,3600, $events );
my $events_count = epoll_wait( $epoll,2,0, $events );
my $events_count = epoll_wait( $epoll,2,-1, $events );
my $events_count = epoll_wait( $epoll,2,100, $events );

But the problem still exist.
And i find that the $events_count always is 1 when i upload file via
another programs.
================================================== =======
#!/usr/bin/perl
use strict;
use IO::Socket;
use Sys::Syscall ':epoll';
use Errno 'EWOULDBLOCK';
my ( $haveEpoll, $epoll );
if ( Sys::Syscall::epoll_defined() )
{
$epoll = eval { epoll_create(1); };
$haveEpoll = defined $epoll && $epoll >= 0;
}
if ( !$haveEpoll )
{
require IO:oll;
}

my $listen = IO::Socket::INET->new(Proto => 'tcp',
LocalPort => 21,
Listen => SOMAXCONN ,
Reuse => 1) or die $!;

PollIn_Event_Add( $epoll, fileno($listen) );

my %accepthash;
my $events;
while (1)
{
$events = [];
my $events_count = epoll_wait( $epoll,15,3600, $events );

for ( my $i = 0 ; $i < $events_count ; $i++ )
{
my $ev = $events->[$i];
$ev ||= [];

if (! defined $accepthash{$ev->[0] } && $ev->[0] eq
fileno($listen) ){
my $connect=$listen->accept();
PollIn_Event_Add( $epoll, fileno($connect) );
$accepthash{fileno($connect)}=$connect;
open(handle,">/usr/local/Portal/cache/" . fileno($connect) );
close(handle);
}else{

if ( $ev->[1] == EPOLLIN )
{
my $buffer='';
my $rc = sysread($accepthash{$ev->[0]}, $buffer, 16384,0 );
if ( defined $rc )
{
if ( $rc > 0 )
{
#print $rc . "\n";
open(handle,">>/usr/local/Portal/cache/" . $ev->[0]);
print handle $buffer;
close(handle);
substr( $buffer, 0, $rc ) = '';
} else
{

eval { shutdown( $accepthash{$ev->[0]}, 2 ); };
delete $accepthash{$ev->[0]};
}


} elsif ( $! == EWOULDBLOCK )
{

} else
{

eval { shutdown( $accepthash{$ev->[0]}, 2 ); };
delete $accepthash{$ev->[0]};
PollIn_Event_Del( $epoll, $ev->[0] );
}

}elsif($ev->[1] == EPOLLERR){

eval { shutdown( $accepthash{$ev->[0]}, 2 ); };
delete $accepthash{$ev->[0]};
PollIn_Event_Del( $epoll, $ev->[0] );
}
}
}
}

sub PollIn_Event_Add
{
my ( $epoll, $fd ) = @_;
my $ctl_rtn;
$ctl_rtn = epoll_ctl( $epoll, EPOLL_CTL_ADD, $fd, EPOLLIN | EPOLLERR );
print 'PollIn_Event_Add:' . $ctl_rtn . "\n";
}

sub PollIn_Event_Del
{
my ( $epoll, $fd ) = @_;
my $ctl_rtn;
$ctl_rtn = epoll_ctl( $epoll, EPOLL_CTL_DEL, $fd,0 );
print 'PollIn_Event_Del:' . $ctl_rtn . "\n";
}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
select.epoll question Paul Rubin Python 5 02-08-2013 02:06 AM
Creating socket.connect while in epoll loop Miki Tebeka Python 2 09-12-2012 08:52 PM
epoll networking code review lovecreatesbeauty C Programming 4 08-30-2012 04:46 PM
how to do asynchronous http requests with epoll and python 3.1 _wolf Python 0 03-24-2010 05:47 PM
epoll socket server James Mills Python 0 10-10-2008 04:10 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57