Skip to content

Commit

Permalink
Merge branch 'split_files'
Browse files Browse the repository at this point in the history
  • Loading branch information
taiyoh committed Jan 29, 2009
2 parents fa3d682 + 0567768 commit 90fa4a6
Showing 1 changed file with 1 addition and 47 deletions.
48 changes: 1 addition & 47 deletions lib/IO/Lambda/Socket/TCPServer.pm
Expand Up @@ -35,9 +35,8 @@ sub server_start (&) {
}

sub client_accepted (&) {
my $client_input = shift;
my ( $server, $param ) = context;
$param->{ClientInput} = $client_input;
$param->{ClientInput} = shift;
my $accepted = __PACKAGE__.'::Accepted';
$accepted->_make_methods($param);
context $server;
Expand Down Expand Up @@ -66,51 +65,6 @@ sub client_accepted (&) {
}};
}

1;

package IO::Lambda::Socket::TCPServer::Accepted;

sub _make_methods {
my ( $pkg, $param ) = @_;
no strict 'refs';
*{"${pkg}::client_connected"} = $param->{ClientConnected} || sub { };
*{"${pkg}::client_disconnected"} = $param->{ClientDisconnected} || sub { };
*{"${pkg}::client_error"} = $param->{ClientError} || sub { };
*{"${pkg}::client_input"} = $param->{ClientInput};
}

sub new {
my ( $pkg, %param ) = @_;
return bless \%param, $pkg;
}

sub parse {
my ( $self, $buf, $err ) = @_;

$self->{_close} = 0;
if ( $err && $err =~ /^(eof|timeout)$/ ) {
$self->client_disconnected($err, $buf);
$self->close;
}
elsif ($err) {
$self->client_error($err, $buf);
}
else {
$buf =~ s/\r\n//g;
$self->client_input($buf);
$self->{_close} = 0;
}
}

sub close { shift->{_close} = 1; }

sub will_close { shift->{_close} }

sub put {
my ( $self, $buf ) = @_;
syswrite( $self->{_socket}, "$buf\r\n" );
}

1;
__END__
Expand Down

0 comments on commit 90fa4a6

Please sign in to comment.