| IO-Mux documentation | view source | Contained in the IO-Mux distribution. |
IO::Mux::Net::TCP - handle a TCP connection
IO::Mux::Net::TCP is a IO::Mux::Handler::Read is a IO::Mux::Handler IO::Mux::Net::TCP is a IO::Mux::Handler::Write is a IO::Mux::Handler IO::Mux::Net::TCP is extended by IO::Mux::HTTP
Handle a service or locally initiated TCP connection.
Build a connection as client or server. You may either pass an prepared
socket object or parameters to initiate one. All OPTIONS which start
with capitals are passed to the socket creation. See extractSocket()
for those additional OPTIONS.
-Option --Defined in --Default fh IO::Mux::Handler <required> name IO::Mux::Handler 'tcp $host:$port' read_size IO::Mux::Handler::Read 32768 socket <required> write_size IO::Mux::Handler::Write 4096
Provide a socket, either as object or the parameters to instantiate it.
example:
# long form, most flexible
my $socket = IO::Socket::INET->new
( PeerAddr => 'www.example.com:80'
, Reuse => 1
);
my $client = IO::Mux::Net::TCP->new
( socket => $socket
);
$mux->add($client);
# short form
my $client = IO::Mux::Net::TCP->new
( PeerAddr => 'www.example.com:80'
, Reuse => 1
);
$mux->add($client);
# even shorter
my $client = $mux->open('tcp'
, PeerAddr => 'www.example.com:80'
, Reuse => 1
);
Shut down a socket for reading or writing or both. See the shutdown
Perl documentation for further details.
If the shutdown is for reading (0 or 2), it happens immediately. However, shutdowns for writing (1 or 2) are delayed until any pending output has been successfully written to the socket.
example:
$conn->shutdown(1);
For sockets, this does not nessecarily mean that the descriptor has been closed, as the other end of a socket could have used shutdown() to close just half of the socket, leaving us free to write data back down the still open half.
example:
In this example, we send a final reply to the other end of the socket, and then shut it down for writing. Since it is also shut down for reading (implicly by the EOF condition), it will be closed once the output has been sent, after which the mux_close callback will be called.
sub mux_eof
{ my ($self, $ref_input) = @_;
print $fh "Well, goodbye then!\n";
$self->shutdown(1);
}
This module is part of IO-Mux distribution version 0.11, built on January 26, 2011. Website: http://perl.overmeer.net/ All modules in this suite: Any::Daemon, IO::Mux, and IO::Mux::HTTP.
Please post questions or ideas to perl@overmeer.net
Copyrights 2011 by Mark Overmeer. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html
| IO-Mux documentation | view source | Contained in the IO-Mux distribution. |