NAME
IO::Mux::Net::TCP - handle a TCP connection
INHERITANCE
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
DESCRIPTION
Handle a service or locally initiated TCP connection.
METHODS
Constructors
- IO::Mux::Net::TCP->new(OPTIONS)
-
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
- fh => FILEHANDLE
- name => STRING
- read_size => INTEGER
- socket => IO::Socket::INET
-
Provide a socket, either as object or the parameters to instantiate it.
- write_size => INTEGER
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 );
- IO::Mux::Net::TCP->open(MODE, WHAT, OPTIONS) See "Constructors" in IO::Mux::Handler
- IO::Mux::Net::TCP->open(MODE, WHAT, OPTIONS) See "Constructors" in IO::Mux::Handler
Accessors
- $obj->fh See "Accessors" in IO::Mux::Handler
- $obj->fh See "Accessors" in IO::Mux::Handler
- $obj->fileno See "Accessors" in IO::Mux::Handler
- $obj->fileno See "Accessors" in IO::Mux::Handler
- $obj->mux See "Accessors" in IO::Mux::Handler
- $obj->mux See "Accessors" in IO::Mux::Handler
- $obj->name See "Accessors" in IO::Mux::Handler
- $obj->name See "Accessors" in IO::Mux::Handler
- $obj->readSize([INTEGER]) See "Accessors" in IO::Mux::Handler::Read
- $obj->socket
- $obj->usesSSL See "Accessors" in IO::Mux::Handler
- $obj->usesSSL See "Accessors" in IO::Mux::Handler
- $obj->writeSize([INTEGER]) See "Accessors" in IO::Mux::Handler::Write
User interface
Connection
- $obj->close([CALLBACK]) See "Connection" in IO::Mux::Handler
- $obj->close([CALLBACK]) See "Connection" in IO::Mux::Handler
- $obj->shutdown((0|1|2))
-
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);
- $obj->timeout([TIMEOUT]) See "Connection" in IO::Mux::Handler
- $obj->timeout([TIMEOUT]) See "Connection" in IO::Mux::Handler
Reading
- $obj->readline(CALLBACK) See "Reading" in IO::Mux::Handler::Read
- $obj->slurp(CALLBACK) See "Reading" in IO::Mux::Handler::Read
Writing
- $obj->print(STRING|SCALAR|LIST|ARRAY) See "Writing" in IO::Mux::Handler::Write
- $obj->printf(FORMAT, PARAMS) See "Writing" in IO::Mux::Handler::Write
- $obj->say(STRING|SCALAR|LIST|ARRAY) See "Writing" in IO::Mux::Handler::Write
- $obj->write(SCALAR, [MORE]) See "Writing" in IO::Mux::Handler::Write
Multiplexer
Connection
- $obj->mux_init(MUX, [HANDLER]) See "Connection" in IO::Mux::Handler
- $obj->mux_init(MUX, [HANDLER]) See "Connection" in IO::Mux::Handler
- $obj->mux_remove See "Connection" in IO::Mux::Handler
- $obj->mux_remove See "Connection" in IO::Mux::Handler
- $obj->mux_timeout See "Connection" in IO::Mux::Handler
- $obj->mux_timeout See "Connection" in IO::Mux::Handler
Reading
- $obj->mux_eof
-
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); }
- $obj->mux_except_flagged(FILENO) See "Reading" in IO::Mux::Handler
- $obj->mux_except_flagged(FILENO) See "Reading" in IO::Mux::Handler
- $obj->mux_input(BUFFER) See "Reading" in IO::Mux::Handler::Read
- $obj->mux_read_flagged(FILENO) See "Reading" in IO::Mux::Handler
- $obj->mux_read_flagged(FILENO) See "Reading" in IO::Mux::Handler
Writing
- $obj->mux_outbuffer_empty See "Writing" in IO::Mux::Handler::Write
- $obj->mux_output_waiting See "Writing" in IO::Mux::Handler::Write
- $obj->mux_write_flagged(FILENO) See "Writing" in IO::Mux::Handler
- $obj->mux_write_flagged(FILENO) See "Writing" in IO::Mux::Handler
Service
Helpers
- $obj->extractSocket(HASH)
- IO::Mux::Net::TCP->extractSocket(HASH) See "Helpers" in IO::Mux::Handler
- $obj->extractSocket(HASH)
- IO::Mux::Net::TCP->extractSocket(HASH) See "Helpers" in IO::Mux::Handler
- $obj->fdset(STATE, READ, WRITE, ERROR) See "Helpers" in IO::Mux::Handler
- $obj->fdset(STATE, READ, WRITE, ERROR) See "Helpers" in IO::Mux::Handler
- $obj->show See "Helpers" in IO::Mux::Handler
- $obj->show See "Helpers" in IO::Mux::Handler
SEE ALSO
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
LICENSE
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