scclib
Stable Cloud Computing C++ Library
Public Types | Public Member Functions | List of all members
scc::util::Event Class Reference

Signaling kernel event counter. More...

#include <event.h>

Public Types

enum  EventFlag { nonblocking = 1 , semaphore = 2 }
 Event flags. More...
 

Public Member Functions

 Event (int=0)
 Construct an event. More...
 
 Event (const Event &)=delete
 No copy.
 
void operator= (const Event &)=delete
 No copy.
 
 Event (Event &&other)
 Move constructor.
 
const Eventoperator= (Event &&other)
 Move assignment.
 
 operator int () const
 Cast object to int.
 
int fd () const
 Return file descriptor. More...
 
void reset (int=-1)
 Reset the event. More...
 
uint64_t read ()
 Read from (decrement) the event counter. More...
 
void write (uint64_t)
 Write to (increment) the event counter. More...
 

Detailed Description

Signaling kernel event counter.

Writes increment the event counter.

Sempahore mode means reads will decrement the counter by 1. Otherwise, reads reset the counter to 0.

Non-blocking mode means the event can throw an exception (EAGAIN) if called when not signalled. The event should probably be polled in this case. See: Kernel file descriptor event notification poller

Examples
examples/net/netmain.cc, net/unittest/inet.cc, net/unittest/inet_stream.cc, net/unittest/unix.cc, util/unittest/event.cc, and util/unittest/poller.cc.

Definition at line 78 of file event.h.

Member Enumeration Documentation

◆ EventFlag

Event flags.

Enumerator
nonblocking 

Non-blocking mode. If an event is read while unsignalled, throws and exception.

semaphore 

Semaphore mode. Event reads decrement the counter by 1. Otherwise, reads set the counter to 0.

Definition at line 86 of file event.h.

Constructor & Destructor Documentation

◆ Event()

Event::Event ( int  flags = 0)

Construct an event.

Parameters
flagsEvent flags, see: EventFlag

Definition at line 45 of file event.cc.

Member Function Documentation

◆ fd()

int scc::util::Event::fd ( ) const
inline

Return file descriptor.

-1 for invalid object.

Definition at line 122 of file event.h.

◆ read()

uint64_t Event::read ( )

Read from (decrement) the event counter.

For blocking event, blocks until counter becomes signalled (non-zero). For a non-blocking event, throws an exception if the counter is not signalled.

For a semaphore, returns 1 and decrements counter by 1. Otherwise, returns the counter value and sets counter to 0.

Examples
net/unittest/inet.cc.

Definition at line 82 of file event.cc.

◆ reset()

void Event::reset ( int  flags = -1)

Reset the event.

Reset the event to unsignalled state (counter 0).

Parameters
flagsif >= 0, override the event flags, otherwise, reset to original flags. See: EventFlag
Examples
net/unittest/inet.cc.

Definition at line 63 of file event.cc.

◆ write()

void Event::write ( uint64_t  v)

Write to (increment) the event counter.

Parameters
vIncrements the event counter by the value.
Examples
net/unittest/inet.cc.

Definition at line 94 of file event.cc.


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