1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
// $Id: Protocol_Handler.cpp 91813 2010-09-17 07:52:52Z johnnyw $
#ifndef JAWS_BUILD_DLL
#define JAWS_BUILD_DLL
#endif
#include "jaws3/Protocol_Handler.h"
#include "jaws3/Concurrency.h"
JAWS_Protocol_State::~JAWS_Protocol_State (void)
{
}
JAWS_Protocol_Handler::JAWS_Protocol_Handler ( JAWS_Protocol_State *state
, void *data
)
: state_ (state)
, data_ (data)
, mb_ (& this->db_)
{
this->db_.base ((char *) this, 0 /* an infinite queue */);
}
JAWS_Protocol_Handler::~JAWS_Protocol_Handler (void)
{
this->mb_.replace_data_block (0);
}
int
JAWS_Protocol_Handler::service (void)
{
if (this->state_ == 0)
return -1;
return this->state_->service (this, this->data_);
}
void
JAWS_Protocol_Handler::event_complete ( const JAWS_Event_Result &result
, void *act
)
{
// This call is done in the context of the dispatching
// thread (e.g., by the Reactor thread, or by one of the
// threads in the Proactor, or by the invoker of the IO
// if the IO is synchronous).
this->state_ = this->state_->transition (result, this->data_, act);
// At this point, we need to cue this Handler back into
// the concurrency mechanism. This probably means the
// Message Queue of some Concurrency Task.
JAWS_Concurrency::instance ()->putq (this);
// Doing it this way is less efficient than calling into
// the service() method of the next state directly from
// here, but it gains the flexibility of a more modular
// concurrency mechanism.
}
|