Mark Overmeer > IOMux-0.12 > IOMux::Handler::Write

Download:
IOMux-0.12.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.12   Source  

NAME ^

IOMux::Handler::Write - any mux writer

INHERITANCE ^

 IOMux::Handler::Write
   is a IOMux::Handler

 IOMux::Handler::Write is extended by
   IOMux::Bundle
   IOMux::File::Write
   IOMux::Net::TCP
   IOMux::Pipe::Write

SYNOPSIS ^

  # only use extensions

DESCRIPTION ^

In an event driven program, you must be careful with every Operation System call, because it can block the event mechanism, hence the program as a whole. Often you can be lazy with writes, because its communication buffers are usually working quite asynchronous... but not always. You may skip the callbacks for small writes and prints.

METHODS ^

Constructors

IOMux::Handler::Write->new(OPTIONS)
 -Option    --Defined in     --Default
  fh          IOMux::Handler   <required>
  name        IOMux::Handler   <stringified handle>
  write_size                   4096
fh => FILEHANDLE
name => STRING
write_size => INTEGER
IOMux::Handler::Write->open(MODE, WHAT, OPTIONS) See "Constructors" in IOMux::Handler

Accessors

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

The number of bytes written at each write.

User interface

Connection

$obj->close([CALLBACK]) See "Connection" in IOMux::Handler
$obj->timeout([TIMEOUT]) See "Connection" in IOMux::Handler

Writing

$obj->print(STRING|SCALAR|LIST|ARRAY)

Send one or more lines to the output. The data is packed into a single string first. The ARRAY (of strings) and SCALAR (ref string) choices are available for efficiency.

example:

  $conn->print($some_text);
  $conn->print(\$some_text);

  my $fh = $conn->fh;
  print $fh "%s%d%X", $foo, $bar, $baz;
$obj->printf(FORMAT, PARAMS)

example:

    $conn->printf("%s%d%X", $foo, $bar, $baz);

    my $fh = $conn->fh;
    $fh->printf("%s%d%X", $foo, $bar, $baz);
$obj->say(STRING|SCALAR|LIST|ARRAY)

Like print() but adding a newline at the end.

$obj->write(SCALAR, [MORE])

Send the content of the string, passed as reference in SCALAR. You probably want to use print() or printf(). You may provide a code reference to produce MORE info when the output buffer get empty.

Multiplexer

Connection

$obj->mux_init(MUX, [HANDLER]) See "Connection" in IOMux::Handler
$obj->mux_remove See "Connection" in IOMux::Handler
$obj->mux_timeout See "Connection" in IOMux::Handler

Reading

$obj->mux_except_flagged(FILENO) See "Reading" in IOMux::Handler
$obj->mux_read_flagged(FILENO) See "Reading" in IOMux::Handler

Writing

$obj->mux_outbuffer_empty

Called after all pending output has been written to the file descriptor. You may use this callback to produce more data to be written.

When this method is not overruled, the multiplexer will stop listening to the write flag until an explicit write() gets executed.

example:

  package My::Service;
  use base 'IOMux::Net::TCP';

  sub mux_outbuffer_empty()
  {   my $self = shift;
      if(my $data = $self->produce_more_data)
      {   $self->write(\$data);
      }
      else
      {   $self->SUPER::mux_outbuffer_empty;
      }
  }
$obj->mux_output_waiting

Returns true is there is output queued.

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

Service

Helpers

$obj->extractSocket(HASH)
IOMux::Handler::Write->extractSocket(HASH) See "Helpers" in IOMux::Handler
$obj->fdset(STATE, READ, WRITE, ERROR) 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: