libassa  3.5.1
Namespaces | Classes | Typedefs | Enumerations | Functions
ASSA Namespace Reference

Namespaces

 Log
 
 Utils
 

Classes

class  Acceptor
 
class  Address
 
class  AutoPtr
 AutoPtr is based on SGI implementation of a auto_ptr template that makes memory handling a little bit easier. More...
 
class  AutoPtrArray
 AutoPtrArray handles memory management of an array of objects. More...
 
class  AutoPtrArrayRef
 A wrapper class to provide AutoPtr with reference semantics. More...
 
class  AutoPtrRef
 A wrapper class to provide AutoPtr with reference semantics. More...
 
struct  Bfunc
 Bfunc is used by PriorityQueue_impl. More...
 
class  CFUNC_Handler
 CFUNC_Handler class. More...
 
class  CharInBuffer
 CharInBuffer is a bucket for the character-based streams/messages. More...
 
class  ChildStatusHandler
 A helper class of Fork. More...
 
class  CmdLineOpts
 Class CmdLineOpts. More...
 
class  Connector
 Connector is a template class for initialization of communication services. More...
 
class  ConUDPSocket
 
class  Destroyer
 
class  DiagnosticContext
 Class DiagnosticContext tracks who deep a function is in the calling stack. More...
 
class  EventHandler
 EventHandler class. More...
 
class  FdSet
 Class FdSet. More...
 
class  FileLogger
 
class  fnode_t
 forknode_t class. More...
 
class  Fork
 Fork class is a simple wrapper around C library function fork(). More...
 
class  ForkList
 ForkList is a singleton class that keeps a list of all forked children. More...
 
class  GenServer
 
class  IdSet
 
class  INETAddress
 
class  IniFile
 
class  io_ptrs
 io_ptrs structure. More...
 
class  IPv4Socket
 
struct  Less
 Less is borrowed from STL implementation. More...
 
class  Logger
 
class  Logger_Impl
 
class  MaskSet
 
class  MemDump
 
class  Option
 Option class. More...
 
class  PidFileLock
 
class  Pipe
 
class  PriorityQueue
 
class  PriorityQueue_Heap
 
class  PriorityQueue_Impl
 Class PriorityQueue_Impl. More...
 
class  PriorityQueue_STLPQ
 
class  Reactor
 
class  Regexp
 Regexp class. More...
 
class  RemoteLogger
 
class  Repository
 
class  Semaphore
 
class  ServiceHandler
 
class  SigAction
 
class  SIGALRMHandler
 Class SIGALRMHandler handles SIGALRM signal. More...
 
class  SIGCHLDHandler
 Class SIGCHLDHandler handles SIGCHLD signal. More...
 
class  SigHandler
 
class  SigHandlers
 
class  SigHandlersList
 SigHandlersList class. More...
 
class  SIGINTHandler
 SIGINTHandler handles SIGINT signal. More...
 
class  SIGPOLLHandler
 Class SIGPOLLHandler handles SIGPOLL signal. More...
 
class  SigSet
 
class  SIGUSR1Handler
 Class SIGUSR1Handler. More...
 
class  SIGUSR2Handler
 Class SIGUSR2Handler handles SIGUSR2 signal. More...
 
class  Singleton
 
class  Socket
 
class  Socketbuf
 
class  StdOutLogger
 
class  Streambuf
 Streambuf class. More...
 
class  Timer
 
struct  TimerCompare
 TimerCompare class compares two Timers base on their expiration timestamp. More...
 
class  TimerCountdown
 
class  TimerQueue
 
class  TimeVal
 
class  UDPSocket
 
class  UnConUDPSocket
 
class  UNIXAddress
 
class  xdrIOBuffer
 

Typedefs

typedef struct sockaddr SA
 
typedef struct sockaddr_in SA_IN
 
typedef struct sockaddr_un SA_UN
 
typedef unsigned long TimerId
 Timer Id is used in handle_timeout() calls. More...
 
typedef int(EventHandler::* EH_IO_Callback) (int)
 A type for the pointer to I/O-related callback member function of class EventHandler. More...
 

Enumerations

enum  ConnectMode { sync, async }
 
enum  EventType {
  READ_EVENT = 0x01, WRITE_EVENT = 0x02, EXCEPT_EVENT = 0x04, TIMEOUT_EVENT = 0x10,
  SIGNAL_EVENT = 0x20, RWE_EVENTS = 0x07, ALL_EVENTS = 0x37
}
 EventType defines events types that Reactor understands. More...
 
enum  Group {
  TRACE = 0x00000001, APP = 0x00000002, USR1 = 0x00000004, USR2 = 0x00000008,
  USR3 = 0x00000010, ALL_APPS = 0x0000001F, ASSAERR = 0x00000020, PIDFLOCK = 0x00000040,
  CMDLINEOPTS = 0x00000080, SEM = 0x00000100, SIGHAND = 0x00000200, REACT = 0x00000400,
  REACTTRACE = 0x00000800, SOCK = 0x00001000, SOCKTRACE = 0x00002000, XDRBUF = 0x00004000,
  XDRBUFTRACE = 0x00008000, STRMBUF = 0x00010000, STRMBUFTRACE = 0x00020000, FORK = 0x00040000,
  SIGACT = 0x00080000, PIPE = 0x00100000, CHARINBUF = 0x00200000, ADDRESS = 0x00400000,
  INIFILE = 0x00800000, REGEXP = 0x01000000, RES5 = 0x02000000, RES6 = 0x04000000,
  RES7 = 0x08000000, RES8 = 0x10000000, RES9 = 0x20000000, RES10 = 0x40000000,
  ALL_LIB = 0x7FFFFFE0, ALL = 0x7FFFFFFF, NONE = 0x00000000
}
 Bit mask used to mask out log messages. More...
 
enum  marker_t { FUNC_MSG, FUNC_ENTRY, FUNC_EXIT }
 

Functions

Socketoperator>> (Socket &s_, CharInBuffer &b_)
 Regardless of the delimeter size, which can be >1, add the character received to the buffer and compare the end of the buffer with the delimeter. More...
 
bool isReadEvent (EventType e_)
 
bool isWriteEvent (EventType e_)
 
bool isExceptEvent (EventType e_)
 
bool isTimeoutEvent (EventType e_)
 
bool isSignalEvent (EventType e_)
 
bool isRWEEvents (EventType e_)
 
bool isAllEvents (EventType e_)
 
bool is_valid_handler (handler_t socket_)
 Detect socket() error in a portable way. More...
 
void disable_handler (handler_t &socket_)
 Set socket descriptor to invalid value in a portable way. More...
 
int get_errno ()
 Fetch error number in a portable way. More...
 
void set_errno (int new_errno_)
 Set error number in a portable way. More...
 
Socketflush (Socket &os_)
 flush manipulator. More...
 
Socketendl (Socket &os_)
 endl manipulator. More...
 
Socketends (Socket &os_)
 ends manipulator. More...
 
TimeVal operator+ (const TimeVal &lhs_, const TimeVal &rhs_)
 
TimeVal operator- (const TimeVal &lhs_, const TimeVal &rhs_)
 
bool operator> (const TimeVal &lhs_, const TimeVal &rhs_)
 
bool operator!= (const TimeVal &lhs_, const TimeVal &rhs_)
 
bool operator<= (const TimeVal &lhs_, const TimeVal &rhs_)
 
bool operator>= (const TimeVal &lhs_, const TimeVal &rhs_)
 
Socketoperator>> (Socket &s_, xdrIOBuffer &b_)
 

Typedef Documentation

int(EventHandler::* ASSA::EH_IO_Callback)(int)

A type for the pointer to I/O-related callback member function of class EventHandler.

These are:

  • handle_read ()
  • handle_write ()
  • handle_except ()
See also
EventHandler

Definition at line 236 of file EventHandler.h.

typedef struct sockaddr ASSA::SA

Definition at line 33 of file Address.h.

typedef struct sockaddr_in ASSA::SA_IN

Definition at line 34 of file Address.h.

typedef struct sockaddr_un ASSA::SA_UN

Definition at line 44 of file Address.h.

typedef unsigned long ASSA::TimerId

Timer Id is used in handle_timeout() calls.

Definition at line 27 of file EventHandler.h.

Enumeration Type Documentation

Enumerator
sync 

Synchronous connection mode.

async 

Asynchronous connection mode.

Definition at line 43 of file Connector.h.

43  {
44  sync,
45  async
46 };
Asynchronous connection mode.
Definition: Connector.h:45
Synchronous connection mode.
Definition: Connector.h:44

EventType defines events types that Reactor understands.

Enumerator
READ_EVENT 

Notify when there will be at least 1 byte available for reading from IO channel without blocking .

WRITE_EVENT 

Notify when there will be room for at least 1 byte to be written to IO channel without blocking.

EXCEPT_EVENT 

Notify when there is an exception condition detected in TCP layer.

TIMEOUT_EVENT 

Notify about expired timer.

SIGNAL_EVENT 

Notify when UNIX signal is delivered by OS.

RWE_EVENTS 

READ_EVENT | WRITE_EVENT | EXCEPT_EVENT.

ALL_EVENTS 

Mask that includes all events.

Definition at line 34 of file EventHandler.h.

35 {
36  READ_EVENT = 0x01,
39  WRITE_EVENT = 0x02,
42  EXCEPT_EVENT = 0x04,
44  TIMEOUT_EVENT = 0x10,
45  SIGNAL_EVENT = 0x20,
46  RWE_EVENTS = 0x07,
47  ALL_EVENTS = 0x37
48 };
Mask that includes all events.
Definition: EventHandler.h:47
Notify about expired timer.
Definition: EventHandler.h:44
READ_EVENT | WRITE_EVENT | EXCEPT_EVENT.
Definition: EventHandler.h:46
Notify when UNIX signal is delivered by OS.
Definition: EventHandler.h:45
Notify when there will be room for at least 1 byte to be written to IO channel without blocking...
Definition: EventHandler.h:39
Notify when there is an exception condition detected in TCP layer.
Definition: EventHandler.h:42
Notify when there will be at least 1 byte available for reading from IO channel without blocking ...
Definition: EventHandler.h:36

Bit mask used to mask out log messages.

Enumerator
TRACE 

Function call trace.

APP 

Application-level messages.

USR1 

Additional application-level messages.

USR2 

Additional application-level messages.

USR3 

Additional application-level messages.

ALL_APPS 

All application-level messages.

ASSAERR 

ASSA and system errors.

PIDFLOCK 

Class PidFileLock messages.

CMDLINEOPTS 

Class CmdLineOpts messages.

SEM 

Class Semaphore messages.

SIGHAND 

Class SigHandler(s) messages.

REACT 

Class Reactor/PrioriyQueue messages.

REACTTRACE 

Extended Reactor/PrioriyQueue messages.

SOCK 

Class Socket & friends messages.

SOCKTRACE 

Extended Socket & friends messages.

XDRBUF 

Class xdrIOBuffer messages.

XDRBUFTRACE 

Extended xdrIOBuffer messages.

STRMBUF 

Class Streambuf & friends messages.

STRMBUFTRACE 

Extended Streambuf & friends messages.

FORK 

Class Fork messages.

SIGACT 

Class SigACtion messages.

PIPE 

Class Pipe messages.

CHARINBUF 

Class CharInBuffer messages.

ADDRESS 

Class Address & friends messages.

INIFILE 

Class IniFile messages.

REGEXP 

Class RegExp messages.

RES5 

Reserved for future use.

RES6 

Reserved for future use.

RES7 

Reserved for future use.

RES8 

Reserved for future use.

RES9 

Reserved for future use.

RES10 

Reserved for future use.

ALL_LIB 

All library messages.

ALL 

All messages: library + application.

NONE 

Total silence.

Definition at line 25 of file LogMask.h.

25  {
26  TRACE = 0x00000001,
27  APP = 0x00000002,
28  USR1 = 0x00000004,
29  USR2 = 0x00000008,
30  USR3 = 0x00000010,
31  /*-----------------------------------------------------------------------*/
32  ALL_APPS = 0x0000001F,
33  /*-----------------------------------------------------------------------*/
34  ASSAERR = 0x00000020,
35  PIDFLOCK = 0x00000040,
36  CMDLINEOPTS = 0x00000080,
37  SEM = 0x00000100,
38  SIGHAND = 0x00000200,
39  REACT = 0x00000400,
40  REACTTRACE = 0x00000800,
41  SOCK = 0x00001000,
42  SOCKTRACE = 0x00002000,
43  XDRBUF = 0x00004000,
44  XDRBUFTRACE = 0x00008000,
45  STRMBUF = 0x00010000,
46  STRMBUFTRACE = 0x00020000,
47  FORK = 0x00040000,
48  SIGACT = 0x00080000,
49  PIPE = 0x00100000,
50  CHARINBUF = 0x00200000,
51  ADDRESS = 0x00400000,
52  INIFILE = 0x00800000,
53  REGEXP = 0x01000000,
54  RES5 = 0x02000000,
55  RES6 = 0x04000000,
56  RES7 = 0x08000000,
57  RES8 = 0x10000000,
58  RES9 = 0x20000000,
59  RES10 = 0x40000000,
60  /*-----------------------------------------------------------------------*/
61  ALL_LIB = 0x7FFFFFE0,
62  ALL = 0x7FFFFFFF,
63  NONE = 0x00000000
64 };
Class CmdLineOpts messages.
Definition: LogMask.h:36
Class IniFile messages.
Definition: LogMask.h:52
ASSA and system errors.
Definition: LogMask.h:34
Reserved for future use.
Definition: LogMask.h:55
All messages: library + application.
Definition: LogMask.h:62
Reserved for future use.
Definition: LogMask.h:58
Additional application-level messages.
Definition: LogMask.h:29
Class Fork messages.
Definition: LogMask.h:47
Reserved for future use.
Definition: LogMask.h:54
Class Pipe messages.
Definition: LogMask.h:49
Additional application-level messages.
Definition: LogMask.h:30
Reserved for future use.
Definition: LogMask.h:59
Application-level messages.
Definition: LogMask.h:27
Function call trace.
Definition: LogMask.h:26
Additional application-level messages.
Definition: LogMask.h:28
Class RegExp messages.
Definition: LogMask.h:53
Class PidFileLock messages.
Definition: LogMask.h:35
Reserved for future use.
Definition: LogMask.h:56
Extended Reactor/PrioriyQueue messages.
Definition: LogMask.h:40
All library messages.
Definition: LogMask.h:61
Class Reactor/PrioriyQueue messages.
Definition: LogMask.h:39
All application-level messages.
Definition: LogMask.h:32
Class Semaphore messages.
Definition: LogMask.h:37
Class Streambuf & friends messages.
Definition: LogMask.h:45
Extended Streambuf & friends messages.
Definition: LogMask.h:46
Total silence.
Definition: LogMask.h:63
Extended xdrIOBuffer messages.
Definition: LogMask.h:44
Class SigHandler(s) messages.
Definition: LogMask.h:38
Class Address & friends messages.
Definition: LogMask.h:51
Class CharInBuffer messages.
Definition: LogMask.h:50
Class Socket & friends messages.
Definition: LogMask.h:41
Class SigACtion messages.
Definition: LogMask.h:48
Reserved for future use.
Definition: LogMask.h:57
Class xdrIOBuffer messages.
Definition: LogMask.h:43
Extended Socket & friends messages.
Definition: LogMask.h:42
Enumerator
FUNC_MSG 
FUNC_ENTRY 
FUNC_EXIT 

Definition at line 67 of file LogMask.h.

67  {
68  FUNC_MSG,
69  FUNC_ENTRY,
70  FUNC_EXIT
71 };

Function Documentation

void ASSA::disable_handler ( handler_t socket_)
inline

Set socket descriptor to invalid value in a portable way.

socket_ is set to the value out of valid range.

Definition at line 108 of file Logger_Impl.h.

References BAD_HANDLER.

Referenced by ASSA::IPv4Socket::accept(), ASSA::Socket::close_handler(), and ASSA::IPv4Socket::open().

109  {
110  socket_ = BAD_HANDLER;
111  }
#define BAD_HANDLER
Sort out WIN32/mingw oddities.
Definition: Logger_Impl.h:81
Socket& ASSA::endl ( Socket os_)
inline

endl manipulator.

If you want to insert a newline character ('
') to terminate a text line, you should favor the manipulator endl. This manipulator inserts a newline character and also flushes the stream buffer.

Author
Vladislav Grinchenko

Definition at line 602 of file Socket.h.

References ASSA::Socket::flush(), and ASSA::Socket::write().

Referenced by ASSA::GenServer::display_help(), ASSA::FileLogger::dump(), ASSA::FileLogger::handle_rollover(), ASSA::GenServer::init(), and ASSA::Logger::log_open().

603 {
604  char c = '\n';
605  os_.write (&c, 1);
606  os_.flush ();
607  return (os_);
608 }
Socket& ASSA::ends ( Socket os_)
inline

ends manipulator.

You can insert a null character (without flushing the output stream) with the manipulator ends. A common use for a Socket object is to mediate output to a stream buffer that constructs an in-memory character sequence. Such a sequence wants a terminating null character. The manipulator ends provides highly visible evidence that the null character is indeed being supplied.

Author
Vladislav Grinchenko

Definition at line 622 of file Socket.h.

References ASSA::Socket::write().

Referenced by ASSA::Option::dump(), ASSA::Semaphore::dump(), ASSA::FdSet::dump_c_str(), ASSA::Socket::dumpState(), ASSA::GenServer::get_version(), ASSA::GenServer::handle_signal(), ASSA::Reactor::registerIOHandler(), and ASSA::PidFileLock::write_pid().

623 {
624  char c = '\0';
625  os_.write (&c, 1);
626  return (os_);
627 }
Socket& ASSA::flush ( Socket os_)
inline
int ASSA::get_errno ( )
inline

Fetch error number in a portable way.

Definition at line 115 of file Logger_Impl.h.

Referenced by ASSA::IPv4Socket::connect(), ASSA::Connector< SERVICE_HANDLER, PEER_CONNECTOR >::connect(), ASSA::Connector< SERVICE_HANDLER, PEER_CONNECTOR >::handle_write(), ASSA::IPv4Socket::read(), ASSA::Socketbuf::sys_read(), and ASSA::Socketbuf::underflow().

116  {
117  int myerrno;
118 #if defined (WIN32)
119  myerrno = WSAGetLastError ();
120 #else
121  myerrno = errno;
122 #endif
123  return myerrno;
124  }
bool ASSA::is_valid_handler ( handler_t  socket_)
inline

Detect socket() error in a portable way.

Returns
true if socket is in valid range; false otherwise.

Definition at line 100 of file Logger_Impl.h.

References BAD_HANDLER.

Referenced by ASSA::IPv4Socket::accept(), ASSA::Socket::clear(), ASSA::IPv4Socket::clone(), ASSA::IPv4Socket::close(), ASSA::IPv4Socket::connect(), ASSA::IPv4Socket::open(), ASSA::IPv4Socket::read(), ASSA::Reactor::removeIOHandler(), and ASSA::IPv4Socket::write().

101  {
102  return (socket_ != BAD_HANDLER);
103  }
#define BAD_HANDLER
Sort out WIN32/mingw oddities.
Definition: Logger_Impl.h:81
bool ASSA::isAllEvents ( EventType  e_)
inline

Definition at line 87 of file EventHandler.h.

References isExceptEvent(), isReadEvent(), isSignalEvent(), isTimeoutEvent(), and isWriteEvent().

88 {
89  return isReadEvent (e_) && isWriteEvent (e_) && isExceptEvent (e_) &&
90  isSignalEvent (e_) && isTimeoutEvent (e_) ;
91 }
bool isSignalEvent(EventType e_)
Definition: EventHandler.h:75
bool isExceptEvent(EventType e_)
Definition: EventHandler.h:63
bool isTimeoutEvent(EventType e_)
Definition: EventHandler.h:69
bool isWriteEvent(EventType e_)
Definition: EventHandler.h:57
bool isReadEvent(EventType e_)
Definition: EventHandler.h:51
bool ASSA::isExceptEvent ( EventType  e_)
inline

Definition at line 63 of file EventHandler.h.

References EXCEPT_EVENT.

Referenced by isAllEvents(), isRWEEvents(), ASSA::Reactor::registerIOHandler(), and ASSA::Reactor::removeHandler().

64 {
65  return (e_ & EXCEPT_EVENT) == EXCEPT_EVENT;
66 }
Notify when there is an exception condition detected in TCP layer.
Definition: EventHandler.h:42
bool ASSA::isReadEvent ( EventType  e_)
inline

Definition at line 51 of file EventHandler.h.

References READ_EVENT.

Referenced by isAllEvents(), isRWEEvents(), ASSA::Reactor::registerIOHandler(), and ASSA::Reactor::removeHandler().

52 {
53  return (e_ & READ_EVENT) == READ_EVENT;
54 }
Notify when there will be at least 1 byte available for reading from IO channel without blocking ...
Definition: EventHandler.h:36
bool ASSA::isRWEEvents ( EventType  e_)
inline

Definition at line 81 of file EventHandler.h.

References isExceptEvent(), isReadEvent(), and isWriteEvent().

82 {
83  return isReadEvent (e_) && isWriteEvent (e_) && isExceptEvent (e_);
84 }
bool isExceptEvent(EventType e_)
Definition: EventHandler.h:63
bool isWriteEvent(EventType e_)
Definition: EventHandler.h:57
bool isReadEvent(EventType e_)
Definition: EventHandler.h:51
bool ASSA::isSignalEvent ( EventType  e_)
inline

Definition at line 75 of file EventHandler.h.

References SIGNAL_EVENT.

Referenced by isAllEvents(), and ASSA::Reactor::registerIOHandler().

76 {
77  return (e_ & SIGNAL_EVENT) == SIGNAL_EVENT;
78 }
Notify when UNIX signal is delivered by OS.
Definition: EventHandler.h:45
bool ASSA::isTimeoutEvent ( EventType  e_)
inline

Definition at line 69 of file EventHandler.h.

References TIMEOUT_EVENT.

Referenced by isAllEvents(), ASSA::Reactor::registerIOHandler(), and ASSA::Reactor::removeHandler().

70 {
71  return (e_ & TIMEOUT_EVENT) == TIMEOUT_EVENT;
72 }
Notify about expired timer.
Definition: EventHandler.h:44
bool ASSA::isWriteEvent ( EventType  e_)
inline

Definition at line 57 of file EventHandler.h.

References WRITE_EVENT.

Referenced by isAllEvents(), isRWEEvents(), ASSA::Reactor::registerIOHandler(), and ASSA::Reactor::removeHandler().

58 {
59  return (e_ & WRITE_EVENT) == WRITE_EVENT;
60 }
Notify when there will be room for at least 1 byte to be written to IO channel without blocking...
Definition: EventHandler.h:39
bool ASSA::operator!= ( const TimeVal lhs_,
const TimeVal rhs_ 
)
inline

Definition at line 312 of file TimeVal.h.

313 {
314  return !( lhs_ == rhs_ );
315 }
TimeVal ASSA::operator+ ( const TimeVal lhs_,
const TimeVal rhs_ 
)
inline

Definition at line 273 of file TimeVal.h.

References ASSA::TimeVal::normalize().

274 {
275  TimeVal temp(lhs_);
276  temp += rhs_;
277  temp.normalize ();
278  return temp;
279 }
TimeVal ASSA::operator- ( const TimeVal lhs_,
const TimeVal rhs_ 
)
inline

Definition at line 282 of file TimeVal.h.

References ASSA::TimeVal::normalize().

283 {
284  TimeVal temp(lhs_);
285  temp -= rhs_;
286  temp.normalize ();
287  return temp;
288 }
bool ASSA::operator<= ( const TimeVal lhs_,
const TimeVal rhs_ 
)
inline

Definition at line 318 of file TimeVal.h.

319 {
320  return !(rhs_ < lhs_);
321 }
bool ASSA::operator> ( const TimeVal lhs_,
const TimeVal rhs_ 
)
inline

Definition at line 306 of file TimeVal.h.

307 {
308  return rhs_ < lhs_;
309 }
bool ASSA::operator>= ( const TimeVal lhs_,
const TimeVal rhs_ 
)
inline

Definition at line 324 of file TimeVal.h.

325 {
326  return !(lhs_ < rhs_);
327 }
Socket& ASSA::operator>> ( Socket s_,
xdrIOBuffer b_ 
)

Definition at line 25 of file xdrIOBuffer.cpp.

References ASSAERR, DL, ASSA::xdrIOBuffer::dump(), EL, ASSA::xdrIOBuffer::error, ASSA::xdrIOBuffer::get_state(), ASSA::Socket::getBytesAvail(), ASSA::xdrIOBuffer::m_buf, ASSA::xdrIOBuffer::m_ptr, ASSA::xdrIOBuffer::m_state, ASSA::xdrIOBuffer::m_sz, ASSA::Socket::read(), ASSA::xdrIOBuffer::size(), trace_with_mask, ASSA::xdrIOBuffer::waiting, XDRBUFTRACE, and ASSA::xdrIOBuffer::xmitted.

26 {
27  trace_with_mask("Socket >> xdrIOBuffer", XDRBUFTRACE);
28 
29  DL((XDRBUFTRACE,"Buffer Initially:\n"));
30  b_.dump ();
31 
32  if (b_.m_state != xdrIOBuffer::waiting) {
33  EL((ASSAERR,"Wrong state: %s\n", b_.get_state ().c_str ()));
34  return s_;
35  }
36  int expected = b_.m_sz - b_.size ();
37 
38  DL((XDRBUFTRACE,"Bytes expected: %d\n",expected));
39  DL((XDRBUFTRACE,"Bytes in Socket buffer(s): %d\n", s_.getBytesAvail ()));
40  int ret;
41 
42  if ((ret = s_.read (b_.m_ptr, expected)) <= 0)
43  {
44 #if defined(WIN32)
45  if (WSAGetLastError () != WSAEWOULDBLOCK) {
46  WSASetLastError (0);
47  EL((ASSAERR,"Socket::read() error!\n"));
48  b_.m_state = xdrIOBuffer::error;
49  }
50 #else
51  if (errno != EWOULDBLOCK) {
52  EL((ASSAERR,"Socket::read() error!\n"));
53  b_.m_state = xdrIOBuffer::error;
54  }
55 #endif
56  else {
57  EL((ASSAERR,"Socket::read() error! \n"));
58  }
59  return s_;
60  }
61  b_.m_ptr += ret;
62 
63  DL((XDRBUFTRACE,"Received %d bytes\n", ret));
64  b_.dump ();
65 
66  if (b_.m_sz == b_.size ()) { // at the end
67  DL((XDRBUFTRACE,"Complete message is in the buffer!\n"));
68  b_.m_state = xdrIOBuffer::xmitted;
69  b_.m_ptr = b_.m_buf; // rewind m_ptr for parsing stage
70  b_.dump ();
71  }
72  return s_;
73 }
ASSA and system errors.
Definition: LogMask.h:34
int size() const
Return number of bytes in xdrIOBuffer.
Definition: xdrIOBuffer.h:171
state_t m_state
Object state.
Definition: xdrIOBuffer.h:146
char * m_ptr
Pointer for next I/O operation into the buffer.
Definition: xdrIOBuffer.h:143
int m_sz
Buffer size and maximum expected size.
Definition: xdrIOBuffer.h:140
int getBytesAvail(void) const
Return number of bytes available in socket receive buffer.
Definition: Socket.cpp:48
#define DL(X)
A macro for writing debug message to the Logger.
Definition: Logger.h:273
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition: Logger.h:437
virtual int read(char *buf_, const u_int size_)
Read expected number of bytes from the socket.
Definition: Socket.h:551
#define EL(X)
A macro for writing error message to the Logger.
Definition: Logger.h:285
void dump() const
Dump object's internal state to the log file.
Extended xdrIOBuffer messages.
Definition: LogMask.h:44
char * m_buf
Buffer.
Definition: xdrIOBuffer.h:137
string get_state() const
Give verbal interpretation of object's state.
Socket& ASSA::operator>> ( ASSA::Socket s_,
ASSA::CharInBuffer b_ 
)

Regardless of the delimeter size, which can be >1, add the character received to the buffer and compare the end of the buffer with the delimeter.

Read bytes from Socket stream until either record delimiter is detected, or EOF occured, or Socket stream is exhausted.

If match, bite off delimiter and set the state to complete. If not, continue reading till either there is no more characters to read, or Socket error (Fail or EOF), or buffer overflow. If overflow occurs, set the state to 'error' and terminate.

Definition at line 80 of file CharInBuffer.cpp.

References CHARINBUF, ASSA::CharInBuffer::chop(), ASSA::CharInBuffer::complete, DL, ASSA::CharInBuffer::error, ASSA::CharInBuffer::m_buffer, ASSA::CharInBuffer::m_delimiter, ASSA::CharInBuffer::m_max_size, ASSA::CharInBuffer::m_state, ASSA::Socket::read(), ASSA::CharInBuffer::state(), ASSA::CharInBuffer::state_name(), trace_with_mask, and ASSA::CharInBuffer::waiting.

81 {
82  trace_with_mask ("Socket >> CharInBuffer", CHARINBUF);
83  register char c;
84 
85  if (b_.state () != CharInBuffer::waiting) {
86  DL((CHARINBUF,"Wrong state %s\n", b_.state_name (b_.state ())));
87  return s_;
88  }
89 
90  while (s_.read (&c, 1) == 1)
91  {
92  b_.m_buffer += c;
93 
94  if (b_.m_buffer.size() < b_.m_delimiter.size()) { // Bug # 1252926
95  continue;
96  }
97 
98  if (b_.m_buffer.substr (
99  b_.m_buffer.size ()-b_.m_delimiter.size ()) == b_.m_delimiter)
100  {
101  b_.chop ();
102  b_.m_state = CharInBuffer::complete;
103  return s_;
104  }
105 
106  if (b_.m_buffer.length () >= b_.m_max_size) {
107  b_.m_state = CharInBuffer::error;
108  break;
109  }
110  }
111 
112  if (!s_) { // EOF or error
113  b_.state (CharInBuffer::error);
114  }
115 
116  return s_;
117 }
size_t m_max_size
Maximum allowable size (delimiter included) before overflow occurs.
Definition: CharInBuffer.h:113
void chop()
Remove the delimiter from the end of the buffer.
Definition: CharInBuffer.h:145
#define DL(X)
A macro for writing debug message to the Logger.
Definition: Logger.h:273
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition: Logger.h:437
std::string m_delimiter
Delimiter. Multibyte delimiter is allowed.
Definition: CharInBuffer.h:116
virtual int read(char *buf_, const u_int size_)
Read expected number of bytes from the socket.
Definition: Socket.h:551
static const char * state_name(state_t state_)
Report the state name.
std::string m_buffer
Buffer to store the bytes received.
Definition: CharInBuffer.h:110
Class CharInBuffer messages.
Definition: LogMask.h:50
state_t state() const
Report the current state of the object.
Definition: CharInBuffer.h:93
state_t m_state
Internal state of an object.
Definition: CharInBuffer.h:107
void ASSA::set_errno ( int  new_errno_)
inline

Set error number in a portable way.

Definition at line 128 of file Logger_Impl.h.

Referenced by ASSA::Connector< SERVICE_HANDLER, PEER_CONNECTOR >::connect(), ASSA::Connector< SERVICE_HANDLER, PEER_CONNECTOR >::doSync(), ASSA::Connector< SERVICE_HANDLER, PEER_CONNECTOR >::handle_timeout(), and ASSA::Connector< SERVICE_HANDLER, PEER_CONNECTOR >::handle_write().

129  {
130 #if defined (WIN32)
131  WSASetLastError (new_errno_);
132 #else
133  errno = new_errno_;
134 #endif
135  }