Defines the interface for a service that exchanges data with its connected peer and supports buffering. More...
#include <Svc_Handler.h>


Public Member Functions | |
| ACE_Buffered_Svc_Handler (ACE_Thread_Manager *thr_mgr=0, ACE_Message_Queue< ACE_SYNCH_USE > *mq=0, ACE_Reactor *reactor=ACE_Reactor::instance(), size_t max_buffer_size=0, ACE_Time_Value *relative_timeout=0) | |
| virtual | ~ACE_Buffered_Svc_Handler (void) |
| Destructor, which calls <flush>. | |
| virtual int | put (ACE_Message_Block *message_block, ACE_Time_Value *timeout=0) |
| virtual int | flush (void) |
| virtual int | handle_timeout (const ACE_Time_Value &time, const void *) |
| void | dump (void) const |
| Dump the state of an object. | |
Protected Member Functions | |
| virtual int | flush_i (void) |
Protected Attributes | |
| size_t | maximum_buffer_size_ |
| size_t | current_buffer_size_ |
| Current size in bytes of the <Message_Queue> contents. | |
| ACE_Time_Value | next_timeout_ |
| Timeout value used to control when the buffer is flushed. | |
| ACE_Time_Value | interval_ |
| Interval of the timeout. | |
| ACE_Time_Value * | timeoutp_ |
| Timeout pointer. | |
Defines the interface for a service that exchanges data with its connected peer and supports buffering.
The buffering feature makes it possible to queue up ACE_Message_Blocks in an ACE_Message_Queue until (1) the queue is "full" or (2) a period of time elapses, at which point the queue is "flushed" via <sendv_n> to the peer.
Definition at line 266 of file Svc_Handler.h.
| ACE_Buffered_Svc_Handler< PR_ST_1, ACE_SYNCH_DECL >::ACE_Buffered_Svc_Handler | ( | ACE_Thread_Manager * | thr_mgr = 0, |
|
| ACE_Message_Queue< ACE_SYNCH_USE > * | mq = 0, |
|||
| ACE_Reactor * | reactor = ACE_Reactor::instance (), |
|||
| size_t | max_buffer_size = 0, |
|||
| ACE_Time_Value * | relative_timeout = 0 | |||
| ) |
Constructor initializes the thr_mgr and mq by passing them down to the ACE_Task base class. The reactor is passed to the ACE_Event_Handler. The max_buffer_size and relative_timeout are used to determine at what point to flush the mq. By default, there's no buffering at all. The relative_timeout value is interpreted to be in a unit that's relative to the current time returned by <ACE_OS::gettimeofday>.
Definition at line 417 of file Svc_Handler.cpp.
: ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE> (tm, mq, reactor), maximum_buffer_size_ (maximum_buffer_size), current_buffer_size_ (0), timeoutp_ (timeout) { ACE_TRACE ("ACE_Buffered_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::ACE_Buffered_Svc_Handler"); if (this->timeoutp_ != 0) { this->interval_ = *timeout; this->next_timeout_ = ACE_OS::gettimeofday () + this->interval_; } }
| ACE_Buffered_Svc_Handler< PR_ST_1, ACE_SYNCH_DECL >::~ACE_Buffered_Svc_Handler | ( | void | ) | [virtual] |
Destructor, which calls <flush>.
Definition at line 411 of file Svc_Handler.cpp.
{
this->flush ();
}
| void ACE_Buffered_Svc_Handler< PR_ST_1, ACE_SYNCH_DECL >::dump | ( | void | ) | const |
Dump the state of an object.
Reimplemented from ACE_Svc_Handler< ACE_PEER_STREAM_2, ACE_SYNCH_USE >.
Definition at line 497 of file Svc_Handler.cpp.
{
#if defined (ACE_HAS_DUMP)
ACE_TRACE ("ACE_Buffered_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::dump");
ACE_Buffered_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::dump ();
ACE_DEBUG ((LM_DEBUG,
"maximum_buffer_size_ = %d\n",
this->maximum_buffer_size_));
ACE_DEBUG ((LM_DEBUG,
"current_buffer_size_ = %d\n",
this->current_buffer_size_));
if (this->timeoutp_ != 0)
ACE_DEBUG ((LM_DEBUG,
"next_timeout_.sec = %d, next_timeout_.usec = %d\n",
this->next_timeout_.sec (),
this->next_timeout_.usec ()));
#endif /* ACE_HAS_DUMP */
}
| int ACE_Buffered_Svc_Handler< PR_ST_1, ACE_SYNCH_DECL >::flush | ( | void | ) | [virtual] |
Flush the ACE_Message_Queue, which writes all the queued ACE_Message_Blocks to the <PEER_STREAM>.
Definition at line 464 of file Svc_Handler.cpp.
{
ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, m, this->msg_queue ()->lock (), -1);
return this->flush_i ();
}
| int ACE_Buffered_Svc_Handler< PR_ST_1, ACE_SYNCH_DECL >::flush_i | ( | void | ) | [protected, virtual] |
Implement the flush operation on the ACE_Message_Queue, which writes all the queued ACE_Message_Blocks to the <PEER_STREAM>. Assumes that the caller holds the lock.
Definition at line 472 of file Svc_Handler.cpp.
{
ACE_Message_Queue_Iterator<ACE_SYNCH_USE> iterator (*this->msg_queue ());
ACE_Message_Block *mblk = 0;
ssize_t result = 0;
// Get the first <ACE_Message_Block> so that we can write everything
// out via the <send_n>.
if (iterator.next (mblk) != 0)
result = this->peer ().send_n (mblk);
// This method assumes the caller holds the queue's lock!
if (result != -1)
this->msg_queue ()->flush_i ();
if (this->timeoutp_ != 0)
// Update the next timeout period by adding the interval.
this->next_timeout_ += this->interval_;
this->current_buffer_size_ = 0;
return result;
}
| int ACE_Buffered_Svc_Handler< PR_ST_1, ACE_SYNCH_DECL >::handle_timeout | ( | const ACE_Time_Value & | time, | |
| const void * | ||||
| ) | [virtual] |
This method is not currently implemented -- this is where the integration with the <Reactor> would occur.
Reimplemented from ACE_Svc_Handler< ACE_PEER_STREAM_2, ACE_SYNCH_USE >.
Definition at line 518 of file Svc_Handler.cpp.
{
ACE_TRACE ("ACE_Buffered_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::handle_timeout");
return 0;
}
| int ACE_Buffered_Svc_Handler< PR_ST_1, ACE_SYNCH_DECL >::put | ( | ACE_Message_Block * | message_block, | |
| ACE_Time_Value * | timeout = 0 | |||
| ) | [virtual] |
Insert the ACE_Message_Block chain rooted at message_block into the ACE_Message_Queue with the designated timeout. The <flush> method will be called if this <put> causes the number of bytes to exceed the maximum buffer size or if the timeout period has elapsed.
Reimplemented from ACE_Task_Base.
Definition at line 437 of file Svc_Handler.cpp.
{
ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, m, this->msg_queue ()->lock (), -1);
// Enqueue <mb> onto the message queue.
if (this->putq (mb, tv) == -1)
return -1;
else
{
// Update the current number of bytes on the queue.
this->current_buffer_size_ += mb->total_size ();
// Flush the buffer when the number of bytes exceeds the maximum
// buffer size or when the timeout period has elapsed.
if (this->current_buffer_size_ >= this->maximum_buffer_size_
|| (this->timeoutp_ != 0
&& this->next_timeout_ <= ACE_OS::gettimeofday ()))
return this->flush_i ();
else
return 0;
}
}
size_t ACE_Buffered_Svc_Handler< ACE_PEER_STREAM_1, ACE_SYNCH_DECL >::current_buffer_size_ [protected] |
Current size in bytes of the <Message_Queue> contents.
Definition at line 321 of file Svc_Handler.h.
ACE_Time_Value ACE_Buffered_Svc_Handler< ACE_PEER_STREAM_1, ACE_SYNCH_DECL >::interval_ [protected] |
Interval of the timeout.
Definition at line 327 of file Svc_Handler.h.
size_t ACE_Buffered_Svc_Handler< ACE_PEER_STREAM_1, ACE_SYNCH_DECL >::maximum_buffer_size_ [protected] |
Maximum size the <Message_Queue> can be before we have to flush the buffer.
Definition at line 318 of file Svc_Handler.h.
ACE_Time_Value ACE_Buffered_Svc_Handler< ACE_PEER_STREAM_1, ACE_SYNCH_DECL >::next_timeout_ [protected] |
Timeout value used to control when the buffer is flushed.
Definition at line 324 of file Svc_Handler.h.
ACE_Time_Value* ACE_Buffered_Svc_Handler< ACE_PEER_STREAM_1, ACE_SYNCH_DECL >::timeoutp_ [protected] |
Timeout pointer.
Definition at line 330 of file Svc_Handler.h.
1.7.0