# Passenger::EventedServer Class Reference

A base class for writing single-threaded, evented servers that use non-blocking I/O. More...

`#include <EventedServer.h>`

Inheritance diagram for Passenger::EventedServer:
[legend]

List of all members.

## Protected Member Functions
virtual void | onClientDisconnected (EventedClient *client)
| Called when a client has been disconnected.

## Detailed Description

A base class for writing single-threaded, evented servers that use non-blocking I/O.

It uses libev for its event loop. EventedServer handles much of the situps regarding client connection management and output buffering and tries to make it easy to implement a zero-copy architecture.

## Basic usage

Derived classes can override the onClientReadable() method, which is called every time a specific client becomes readable. It is passed a Client object which contains information about the client, such as its file descriptor. One can use the read() system call in that method to receive data from the client. Please note that client file descriptors are always set to non-blocking mode so you need to handle this gracefully.

EventedServer provides the write() method for sending data to the client. This method will attempt to send the data to the client immediately; if it fails with EAGAIN then EventedServer will take care of scheduling the send at a later time when the client is ready again to receive data.

To disconnect the client, call disconnect(). The connection might not be actually closed until all pending outgoing data have been sent out, but all the gory details is taken care of for you.

## Keeping per-client information

If you need to keep per-client information then you can override the createClient() method and make it return an object that's a subclass of EventedServer::Client. This object is passed to onClientReadable(), so in there you can just cast the client object to your subclass.

## Client object life times

All client objects are destroyed along with the EventedServer. Disconnecting a client also causes it to be destroyed after the current event handler has run or a short period of time after that.

## Member Function Documentation

virtual void Passenger::EventedServer::onClientDisconnected | ( | EventedClient * | client | ) | `[inline, protected, virtual]`

Called when a client has been disconnected.

This may either be triggered immediately by disconnect() or triggered after pending data has been sent out. This means that if you call disconnect() from onClientReadable() you need take care of the possibility that control returns to onClientReadable() after this method is done.

Please note that when EventedServer is being destroyed, onClientDisconnected() is *not* triggered.

The documentation for this class was generated from the following file:

- EventedServer.h