LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Types | Public Member Functions | Public Attributes
LogCabin::Event::File Class Reference

A File is called by the Event::Loop when a file becomes readable or writable. More...

#include <File.h>

Inheritance diagram for LogCabin::Event::File:
LogCabin::Event::Signal LogCabin::Event::Timer LogCabin::RPC::anonymous_namespace{ClientSession.cc}::FileNotifier LogCabin::RPC::MessageSocket::ReceiveSocket LogCabin::RPC::MessageSocket::SendSocket LogCabin::RPC::OpaqueServer::BoundListener LogCabin::Server::Globals::ExitHandler LogCabin::Server::Globals::LogRotateHandler LogCabin::Server::ServerStats::SignalHandler LogCabin::Event::Loop::NullTimer LogCabin::RPC::anonymous_namespace{ClientSession.cc}::TimerNotifier LogCabin::RPC::ClientSession::Timer

List of all members.

Classes

class  Monitor
 Registers a File handler to be monitored by the Event::Loop. More...

Public Types

enum  Ownership {
  CLOSE_ON_DESTROY,
  CALLER_CLOSES_FD
}
 Specifies who is in charge of closing the file descriptor. More...

Public Member Functions

 File (int fd, Ownership ownership=CLOSE_ON_DESTROY)
 Construct a file event handler.
virtual ~File ()
 Destructor.
virtual void handleFileEvent (uint32_t events)=0
 This method is overridden by a subclass and invoked when a file event occurs.
 File (const File &)
Fileoperator= (const File &)

Public Attributes

const int fd
 The file descriptor to monitor.
const Ownership ownership
 See Ownership.

Detailed Description

A File is called by the Event::Loop when a file becomes readable or writable.

The client should inherit from this and implement the handleFileEvent() method for when the file becomes readable or writable.

File objects can be created from any thread, but they will always fire on the thread running the Event::Loop.

Definition at line 36 of file File.h.


Member Enumeration Documentation

Specifies who is in charge of closing the file descriptor.

Enumerator:
CLOSE_ON_DESTROY 

The File destructor will close() fd.

CALLER_CLOSES_FD 

The caller will be in charge of closing fd.

The File destructor will not close() fd.

Definition at line 129 of file File.h.


Constructor & Destructor Documentation

LogCabin::Event::File::File ( int  fd,
Ownership  ownership = CLOSE_ON_DESTROY 
) [explicit]

Construct a file event handler.

After this is constructed, you'll want to create an Event::File::Monitor for it.

Parameters:
fdA file descriptor of a valid open file to monitor. Unless release() is called first, this File object will close the file descriptor when it is destroyed.
ownershipSpecifies who is in charge of closing fd. Default: this class will close fd in the destructor.

Definition at line 86 of file File.cc.

Destructor.

Closes the file descriptor if ownership is set to CLOSE_ON_DESTROY.

Definition at line 92 of file File.cc.


Member Function Documentation

virtual void LogCabin::Event::File::handleFileEvent ( uint32_t  events) [pure virtual]

This method is overridden by a subclass and invoked when a file event occurs.

This method will be invoked by the main event loop on whatever thread is running the Event::Loop.

If the event still exists when this method returns (e.g., the file is readable but the method did not read the data), then the method will be invoked again (unless flags such as EPOLLONESHOT or EPOLLET are used).

Parameters:
eventsIndicates whether the file is readable or writable or both (OR'ed combination of EPOLL_EVENTS values).

Implemented in LogCabin::RPC::OpaqueServer::BoundListener, LogCabin::RPC::MessageSocket::ReceiveSocket, LogCabin::RPC::MessageSocket::SendSocket, LogCabin::Event::Signal, LogCabin::Event::Timer, and LogCabin::RPC::anonymous_namespace{ClientSession.cc}::FileNotifier.

File& LogCabin::Event::File::operator= ( const File )

Member Data Documentation

The file descriptor to monitor.

Definition at line 178 of file File.h.

See Ownership.

Definition at line 183 of file File.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines