Mark Overmeer > IOMux > IOMux::Net::TCP

Download:
IOMux-0.12.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.12   Source  

NAME ^

IOMux::Net::TCP - handle a TCP connection

INHERITANCE ^

 IOMux::Net::TCP
   is a IOMux::Handler::Read
   is a IOMux::Handler

 IOMux::Net::TCP
   is a IOMux::Handler::Write
   is a IOMux::Handler

 IOMux::Net::TCP is extended by
   IOMux::HTTP

DESCRIPTION ^

Handle a service or locally initiated TCP connection.

METHODS ^

Constructors

IOMux::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          IOMux::Handler   <required>
  name        IOMux::Handler   'tcp $host:$port'
  read_size   IOMux::Handler::Read  32768
  socket                       <required>
  write_size  IOMux::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 = IOMux::Net::TCP->new
    ( socket   => $socket
    );
  $mux->add($client);

  # short form
  my $client = IOMux::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
    );
IOMux::Net::TCP->open(MODE, WHAT, OPTIONS) See "Constructors" in IOMux::Handler
IOMux::Net::TCP->open(MODE, WHAT, OPTIONS) See "Constructors" in IOMux::Handler

Accessors

$obj->fh See "Accessors" in IOMux::Handler
$obj->fh See "Accessors" in IOMux::Handler
$obj->fileno See "Accessors" in IOMux::Handler
$obj->fileno See "Accessors" in IOMux::Handler
$obj->mux See "Accessors" in IOMux::Handler
$obj->mux See "Accessors" in IOMux::Handler
$obj->name See "Accessors" in IOMux::Handler
$obj->name See "Accessors" in IOMux::Handler
$obj->readSize([INTEGER]) See "Accessors" in IOMux::Handler::Read
$obj->socket
$obj->usesSSL See "Accessors" in IOMux::Handler
$obj->usesSSL See "Accessors" in IOMux::Handler
$obj->writeSize([INTEGER]) See "Accessors" in IOMux::Handler::Write

User interface

Connection

$obj->close([CALLBACK]) See "Connection" in IOMux::Handler
$obj->close([CALLBACK]) See "Connection" in IOMux::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 IOMux::Handler
$obj->timeout([TIMEOUT]) See "Connection" in IOMux::Handler

Reading

$obj->readline(CALLBACK) See "Reading" in IOMux::Handler::Read
$obj->slurp(CALLBACK) See "Reading" in IOMux::Handler::Read

Writing

$obj->print(STRING|SCALAR|LIST|ARRAY) See "Writing" in IOMux::Handler::Write
$obj->printf(FORMAT, PARAMS) See "Writing" in IOMux::Handler::Write
$obj->say(STRING|SCALAR|LIST|ARRAY) See "Writing" in IOMux::Handler::Write
$obj->write(SCALAR, [MORE]) See "Writing" in IOMux::Handler::Write

Multiplexer

Connection

$obj->mux_init(MUX, [HANDLER]) See "Connection" in IOMux::Handler
$obj->mux_init(MUX, [HANDLER]) See "Connection" in IOMux::Handler
$obj->mux_remove See "Connection" in IOMux::Handler
$obj->mux_remove See "Connection" in IOMux::Handler
$obj->mux_timeout See "Connection" in IOMux::Handler
$obj->mux_timeout See "Connection" in IOMux::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 IOMux::Handler
$obj->mux_except_flagged(FILENO) See "Reading" in IOMux::Handler
$obj->mux_input(BUFFER) See "Reading" in IOMux::Handler::Read
$obj->mux_read_flagged(FILENO) See "Reading" in IOMux::Handler
$obj->mux_read_flagged(FILENO) See "Reading" in IOMux::Handler

Writing

$obj->mux_outbuffer_empty See "Writing" in IOMux::Handler::Write
$obj->mux_output_waiting See "Writing" in IOMux::Handler::Write
$obj->mux_write_flagged(FILENO) See "Writing" in IOMux::Handler
$obj->mux_write_flagged(FILENO) See "Writing" in IOMux::Handler

Service

Helpers

$obj->extractSocket(HASH)
IOMux::Net::TCP->extractSocket(HASH) See "Helpers" in IOMux::Handler
$obj->extractSocket(HASH)
IOMux::Net::TCP->extractSocket(HASH) See "Helpers" in IOMux::Handler
$obj->fdset(STATE, READ, WRITE, ERROR) See "Helpers" in IOMux::Handler
$obj->fdset(STATE, READ, WRITE, ERROR) See "Helpers" in IOMux::Handler
$obj->show See "Helpers" in IOMux::Handler
$obj->show See "Helpers" in IOMux::Handler

SEE ALSO ^

This module is part of IOMux distribution version 0.12, built on January 27, 2011. Website: http://perl.overmeer.net/ All modules in this suite: "Any::Daemon", "IOMux", and "IOMux::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

syntax highlighting: