[poe-commits] poe/POE/Component/Server TCP.pm,1.22,1.23
Brought to you by:
rcaputo
From: <rc...@us...> - 2002-07-29 22:34:46
|
Update of /cvsroot/poe/poe/POE/Component/Server In directory usw-pr-cvs1:/tmp/cvs-serv25792/POE/Component/Server Modified Files: TCP.pm Log Message: James March noted that Client::TCP and Server::TCP don't mention how to send a response on their connected sockets. While omitting such an important fact from the docs is a great way to make people read them carefully, it's better to include the information. Index: TCP.pm =================================================================== RCS file: /cvsroot/poe/poe/POE/Component/Server/TCP.pm,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** TCP.pm 18 Jun 2002 22:18:37 -0000 1.22 --- TCP.pm 29 Jul 2002 22:34:44 -0000 1.23 *************** *** 116,195 **** # Revise the acceptor callback so it spawns a session. ! $accept_callback = sub { ! my ($socket, $remote_addr, $remote_port) = @_[ARG0, ARG1, ARG2]; ! POE::Session->create ! ( inline_states => ! { _start => sub { ! my ( $kernel, $session, $heap ) = @_[KERNEL, SESSION, HEAP]; ! $heap->{shutdown} = 0; ! $heap->{remote_ip} = inet_ntoa($remote_addr); ! $heap->{remote_port} = $remote_port; ! $heap->{client} = POE::Wheel::ReadWrite->new ! ( Handle => $socket, ! Driver => POE::Driver::SysRW->new( BlockSize => 4096 ), ! Filter => $client_filter->new(@client_filter_args), ! InputEvent => 'tcp_server_got_input', ! ErrorEvent => 'tcp_server_got_error', ! FlushedEvent => 'tcp_server_got_flush', ! ); ! $client_connected->(@_); ! }, ! # To quiet ASSERT_STATES. ! _child => sub { }, ! _signal => sub { 0 }, ! tcp_server_got_input => sub { ! my $heap = $_[HEAP]; ! return if $heap->{shutdown}; ! $client_input->(@_); ! }, ! tcp_server_got_error => sub { ! my ($heap, $operation, $errnum) = @_[HEAP, ARG0, ARG1]; ! $heap->{shutdown} = 1; ! # Read error 0 is disconnect. ! if ($operation eq 'read' and $errnum == 0) { ! $client_disconnected->(@_); ! } ! else { ! $client_error->(@_); ! } ! delete $heap->{client}; ! }, ! tcp_server_got_flush => sub { ! my $heap = $_[HEAP]; ! $client_flushed->(@_); ! delete $heap->{client} if $heap->{shutdown}; ! }, ! shutdown => sub { ! my $heap = $_[HEAP]; ! $heap->{shutdown} = 1; ! if (defined $heap->{client}) { ! delete $heap->{client} ! unless $heap->{client}->get_driver_out_octets(); ! } ! }, ! _stop => $client_disconnected, ! tcp_server_got_flushed => sub { ! my ($kernel, $heap) = @_[KERNEL, HEAP]; ! delete $heap->{client} if $heap->{shutdown}; ! }, ! # User supplied states. ! %$inline_states ! }, ! # More user supplied states. ! package_states => $package_states, ! object_states => $object_states, ! ); ! }; }; --- 116,197 ---- # Revise the acceptor callback so it spawns a session. ! unless (defined $accept_callback) { ! $accept_callback = sub { ! my ($socket, $remote_addr, $remote_port) = @_[ARG0, ARG1, ARG2]; ! POE::Session->create ! ( inline_states => ! { _start => sub { ! my ( $kernel, $session, $heap ) = @_[KERNEL, SESSION, HEAP]; ! $heap->{shutdown} = 0; ! $heap->{remote_ip} = inet_ntoa($remote_addr); ! $heap->{remote_port} = $remote_port; ! $heap->{client} = POE::Wheel::ReadWrite->new ! ( Handle => $socket, ! Driver => POE::Driver::SysRW->new(BlockSize => 4096), ! Filter => $client_filter->new(@client_filter_args), ! InputEvent => 'tcp_server_got_input', ! ErrorEvent => 'tcp_server_got_error', ! FlushedEvent => 'tcp_server_got_flush', ! ); ! $client_connected->(@_); ! }, ! # To quiet ASSERT_STATES. ! _child => sub { }, ! _signal => sub { 0 }, ! tcp_server_got_input => sub { ! my $heap = $_[HEAP]; ! return if $heap->{shutdown}; ! $client_input->(@_); ! }, ! tcp_server_got_error => sub { ! my ($heap, $operation, $errnum) = @_[HEAP, ARG0, ARG1]; ! $heap->{shutdown} = 1; ! # Read error 0 is disconnect. ! if ($operation eq 'read' and $errnum == 0) { ! $client_disconnected->(@_); ! } ! else { ! $client_error->(@_); ! } ! delete $heap->{client}; ! }, ! tcp_server_got_flush => sub { ! my $heap = $_[HEAP]; ! $client_flushed->(@_); ! delete $heap->{client} if $heap->{shutdown}; ! }, ! shutdown => sub { ! my $heap = $_[HEAP]; ! $heap->{shutdown} = 1; ! if (defined $heap->{client}) { ! delete $heap->{client} ! unless $heap->{client}->get_driver_out_octets(); ! } ! }, ! _stop => $client_disconnected, ! tcp_server_got_flushed => sub { ! my ($kernel, $heap) = @_[KERNEL, HEAP]; ! delete $heap->{client} if $heap->{shutdown}; ! }, ! # User supplied states. ! %$inline_states ! }, ! # More user supplied states. ! package_states => $package_states, ! object_states => $object_states, ! ); ! }; ! } }; *************** *** 352,355 **** --- 354,361 ---- $kernel->post( server => "shutdown" ) # stop listening for connections + # Responding to a client. + + $heap->{client}->put(@things_to_send); + =head1 DESCRIPTION *************** *** 376,381 **** Acceptor => \&accept_handler ! Acceptor and ClientInput are mutually exclusive. Enabling one ! prohibits the other. =item Address --- 382,387 ---- Acceptor => \&accept_handler ! Acceptor lets programmers rewrite the guts of Server::TCP entirely. ! It disables the code that provides the /Client.*/ callbacks. =item Address *************** *** 441,445 **** ClientInput is a coderef that will be called to handle client input. ! The callback receives its parameters directyl from ReadWrite's InputEvent. ARG0 is the input record, and ARG1 is the wheel's unique ID. --- 447,451 ---- ClientInput is a coderef that will be called to handle client input. ! The callback receives its parameters directly from ReadWrite's InputEvent. ARG0 is the input record, and ARG1 is the wheel's unique ID. |