EV::Buffer(3)

NAME
HTTP::Server::EV::Buffer - Non-blocking output buffer.

GLOBAL PARAMETERS
$HTTP::Server::EV::Buffer::autoflush = 1024*10; # Default buffered data size in bytes when buffer starts waiting socket to be writable to send data. Setting 0 disables buffering, data will be sent as soon as socket becomes writable.

METHODS

  new({ fh => $sock_handle , flush => autoflush_threshold(optional), onerror => sub { onerror(disconect) optional callback} });
Creates new HTTP::Server::EV::Buffer object.

  $buffer->print(@args)
Prints data to buffer.

  $buffer->flush( $flush_threshold(optional) )
Sends all buffered data to socket and sets new flush threshold if $flush_threshold defined;

  $buffer->flush_wait( sub{} )
->flush only starts sending data in async background mode. ->flush_wait starts flushing and calls callback when all data is sent. If callback isn't specified it will try use Coro to block current thread (threading in PortListener must be enabled). If threading disabled and no callback specified it works as ->flush

  $buffer->{onerror} = sub {} or $buffer->onerror(sub {})
Set onerror callback, which called when client disconeted before cerver closed connection.

  $buffer->give_up_handle
Use when you need do some bi-directional communication through client socket(for ex. websocket server or make CONNECT proxy). Returns filehandle opened for RW and now buffer won't do anything with handle - $buffer will be set to undef; Call ->flush_wait before calling ->give_up_handle if you have data in buffer, otherwise it will be lost

  $buffer->{error_w}->start
Call this after ->new if you use H:S:E:Buffer without HTTP::Server::EV and need onerror callback. It's called automatically after receiving GET or POST request, for other methods you must start watcher manually after reading all data from handle.