本文整理汇总了C++中ACE_Message_Block::length方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_Message_Block::length方法的具体用法?C++ ACE_Message_Block::length怎么用?C++ ACE_Message_Block::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_Message_Block
的用法示例。
在下文中一共展示了ACE_Message_Block::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
int
Thread_Pool::svc (void)
{
// Keep looping, reading a message out of the queue, until we get a
// message with a length == 0, which signals us to quit.
for (int count = 1; ; count++)
{
ACE_Message_Block *mb = 0;
int result = this->getq (mb);
ACE_TEST_ASSERT (result != -1 || errno == ESHUTDOWN);
if (result == -1 && errno == ESHUTDOWN)
{
// The queue has been deactivated, so let's bail out.
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) in iteration %d, queue len = %d, ")
ACE_TEXT ("queue deactivated, exiting\n"),
count,
this->msg_queue ()->message_count ()));
break;
}
size_t length = mb->length ();
if (length > 0)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) in iteration %d, queue len = %d, ")
ACE_TEXT ("length = %d, text = \"%*s\"\n"),
count,
this->msg_queue ()->message_count (),
length,
length - 1,
mb->rd_ptr ()));
// We're responsible for deallocating this.
mb->release ();
if (length == 0)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) in iteration %d, queue len = %d, ")
ACE_TEXT ("got \"empty\" message, exiting\n"),
count,
this->msg_queue ()->message_count ()));
break;
}
}
// Note that the <ACE_Task::svc_run> method automatically removes us
// from the <ACE_Thread_Manager> when the thread exits.
return 0;
}
示例2:
int
HTTP_SSL_Client_Session::on_read_complete(ACE_Message_Block& mb, const TRB_Asynch_Read_Stream::Result& result)
{
ACE_OS::write_n(ACE_STDOUT, mb.rd_ptr(), mb.length()); //@
//static int i = 0;
//::printf("%d, ", i++);
return 0;
}
示例3:
void
JAWS_Asynch_IO::receive_file (JAWS_IO_Handler *ioh,
const char *filename,
void *initial_data,
unsigned int initial_data_length,
unsigned int entire_length)
{
JAWS_TRACE ("JAWS_Asynch_IO::receive_file");
ioh->idle ();
JAWS_Asynch_IO_Handler *aioh =
dynamic_cast<JAWS_Asynch_IO_Handler *> (ioh);
ACE_Message_Block *mb = 0;
ACE_Filecache_Handle *handle;
ACE_NEW (handle, ACE_Filecache_Handle (filename, entire_length, ACE_NOMAP));
int result = handle->error ();
if (result == ACE_Filecache_Handle::ACE_SUCCESS)
{
ACE_OS::memcpy (handle->address (),
initial_data,
initial_data_length);
int bytes_to_read = entire_length - initial_data_length;
ACE_NEW (mb, ACE_Message_Block ((char *)handle->address ()
+ initial_data_length, bytes_to_read));
if (mb == 0)
{
errno = ENOMEM;
result = -1;
}
else
{
ACE_Asynch_Read_Stream ar;
if (ar.open (*(aioh->handler ()), aioh->handle ()) == -1
|| ar.read (*mb, mb->size () - mb->length (), handle) == -1)
result = -1;
}
}
if (result != ACE_Filecache_Handle::ACE_SUCCESS)
{
this->handler_->receive_file_error (result);
delete mb;
delete handle;
}
}
示例4: process_command
int RASocket::process_command (const std::string& command)
{
if (command.length() == 0)
return 0;
sLog->outRemote("Got command: %s", command.c_str());
// handle quit, exit and logout commands to terminate connection
if (command == "quit" || command == "exit" || command == "logout")
{
(void) send("Bye\r\n");
return -1;
}
CliCommandHolder* cmd = new CliCommandHolder(this, command.c_str(), &RASocket::zprint, &RASocket::commandFinished);
sWorld->QueueCliCommand(cmd);
// wait for result
ACE_Message_Block* mb;
for (;;)
{
if (getq(mb) == -1)
return -1;
if (mb->msg_type() == ACE_Message_Block::MB_BREAK)
{
mb->release();
break;
}
if (size_t(peer().send(mb->rd_ptr(), mb->length())) != mb->length())
{
mb->release();
return -1;
}
mb->release();
}
return 0;
}
示例5:
static void *
consumer (void *args)
{
ACE_Message_Queue<ACE_MT_SYNCH> *msg_queue =
reinterpret_cast<ACE_Message_Queue<ACE_MT_SYNCH> *> (args);
u_long cur_priority = 27;
ACE_UNUSED_ARG (cur_priority);
// To suppress ghs warning about unused local variable
// "cur_priority".
int local_count = 0;
// Keep looping, reading a message out of the queue, until we get a
// message with a length == 0, which signals us to quit.
for (char c = 'z'; ; c--)
{
ACE_Message_Block *mb = 0;
int result = msg_queue->dequeue_head (mb);
if (result == -1)
break;
local_count++;
size_t length = mb->length ();
if (length > 0)
{
// This isn't a "shutdown" message, so process it
// "normally."
ACE_TEST_ASSERT (c == *mb->rd_ptr ());
ACE_TEST_ASSERT (mb->msg_priority () < cur_priority);
cur_priority = mb->msg_priority ();
}
// Free up the buffer memory and the Message_Block. Note that
// the destructor of Message Block will delete the the actual
// buffer.
mb->release ();
if (length == 0)
// This was a "shutdown" message, so break out of the loop.
break;
}
ACE_TEST_ASSERT (local_count == message_count);
return 0;
}
示例6:
int
Sender::initiate_write_stream ()
{
if (this->flg_cancel_ != 0)
{
return -1;
}
if (this->get_ref_cnt_w() != 0)
{
return 0; // todo: queue it
}
u_int blksize = this->config().s_blksize();
u_int limit = this->config().xfer_limit();
u_int winsize = this->config().w_size();
if (limit != 0 && this->total_snd_ >= limit)
{
this->shutdown_i ();
return 0;
}
u_long delta = this->total_snd_- this->total_rcv_;
if (delta > winsize)
return 0;
ACE_Message_Block *mb = 0;
ACE_NEW_RETURN (mb,
ACE_Message_Block (blksize+1),
-1);
mb->copy(complete_message);
mb->copy("\0");
mb->wr_ptr(mb->base() + blksize);
if (this->stream_.write (*mb, mb->length ()) == -1)
{
mb->release ();
this->cancel_i();
return -1;
}
this->ref_cnt_w_++;
this->total_w_++;
return 0;
}
示例7:
void
DSession::handle_user_operation(const TRB_Asynch_User_Result& result)
{
ACE_Message_Block *mb =result.get_message_block_ptr ();
ACE_ASSERT (mb != 0);
ACE_ASSERT (this->index() == (int) result.act ());
{
ACE_GUARD (ACE_SYNCH_MUTEX, monitor, this->lock_);
this->post_count_--;
{
LogLocker log_lock;
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) **** %s=%d handle_message() ****\n"),
this->get_name(),
this->index()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %d\n"),
ACE_TEXT ("length"),
mb->length()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %d\n"),
ACE_TEXT ("act"),
(int) result.act ()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %s\n"),
ACE_TEXT ("message_block"),
mb->rd_ptr ()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("**** end of message ****************\n")));
}
mb->release();
if (this->io_count_r_ != 0 ||
this->io_count_w_ != 0 ||
this->post_count_ != 0 )
return;
}
delete this;
}
示例8: nowait
// Listing 6 code/ch07
int
ClientService::handle_output (ACE_HANDLE)
{
ACE_Message_Block *mb;
ACE_Time_Value nowait (ACE_OS::gettimeofday ());
while (-1 != this->getq (mb, &nowait))
{
ssize_t send_cnt =
this->peer ().send (mb->rd_ptr (), mb->length ());
if (send_cnt == -1)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%P|%t) %p\n"),
ACE_TEXT ("send")));
else
mb->rd_ptr (static_cast<size_t> (send_cnt));
if (mb->length () > 0)
{
this->ungetq (mb);
break;
}
mb->release ();
}
return (this->msg_queue ()->is_empty ()) ? -1 : 0;
}
示例9: sendBuffers
int TCPConnectionHandler::sendBuffers ()
{
int result = 0;
if (buffers_)
if (0 < (result = peer_.send_n (buffers_))) // remove sent blocks
{
totalSent_ += result;
while (buffers_ &&
static_cast< size_t > (result) >= buffers_->length ())
{
ACE_Message_Block *buffer = buffers_;
result -= buffers_->length ();
buffers_= buffers_->cont ();
buffer->cont (0);
buffer->release ();
}
if (buffers_) // some buffers were not sent, truncate data
buffers_->rd_ptr (result);
}
return result;
}
示例10: send
int Test_Service_Handler::send()
{
ACE_Guard<ACE_Recursive_Thread_Mutex> guard(mtx_);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("(%t) %s_Handler(%@)::send() fd=%d\n"),
is_caller_ ? "Client" : "Server" ,
this,
this->handle()));
//AL:
if (!cancel_called_)
{
//AL: not thread safe
//static std::string pkt = pkt_header;
//pkt += pkt_payload;
size_t len_header = ACE_OS::strlen(pkt_header);
size_t len_payload = ACE_OS::strlen(pkt_payload);
ACE_Message_Block *mb = 0;
ACE_NEW_RETURN(mb, ACE_Message_Block(len_header+len_payload), -1);
mb->copy(pkt_header, len_header);
mb->copy(pkt_payload, len_payload);
int ret = writer_.write(*mb, mb->length());
if (ret == 0)
{
write_count_++;
return 0;
}
mb->release();
}
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT("(%t) %s_Handler(%@)::send failed\n"),
is_caller_ ? "Client" : "Server" ,
this));
//AL: delete_if_reqd();
this->cancel();
return -1;
}
示例11: tv
// New stuff added to the message queue. Try to dequeue a message.
int
Peer_Handler::handle_output (ACE_HANDLE)
{
ACE_Message_Block *mb = 0;
ACE_Time_Value tv (ACE_Time_Value::zero);
// Forward the message to the remote peer receiver.
if (this->getq (mb, &tv) != -1)
{
if (this->wr_stream_.write (*mb,
mb->length ()) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p Write initiate.\n", "Peer_Handler"), -1);
}
return 0;
}
示例12: cdr
template<> ACE_Message_Block *
lifecycle_frame_serializer::pack( const LifeCycleData& v )
{
ACE_OutputCDR ace_cdr;
OutputCDR cdr(ace_cdr);
LifeCycleFrame frame( boost::apply_visitor( internal::lifecycle_command_visitor(), v ) );
internal::lifecycle_serializer::serialize(cdr, frame);
unsigned int size = boost::apply_visitor( internal::lifecycle_serializer_visitor(cdr), v );
ACE_UNUSED_ARG(size);
ACE_Message_Block * mb = cdr.begin()->clone();
mb->length( cdr.length() );
return mb;
}
示例13:
int
PConnection::do_initiate_write_stream (ACE_Message_Block &mb)
{
size_t nbytes = mb.length();
if (this->start_asynch_write (mb, nbytes) == 0)
{
this->ref_cnt_w_++;
this->total_w_++;
return 0;
}
this->free_msg (&mb);
this->cancel ();
return -1;
}
示例14:
template <class BARRIER> int
Worker_Task<BARRIER>::svc (void)
{
// Note that the <ACE_Task::svc_run> method automatically adds us to
// the Thread_Manager when the thread begins.
// Keep looping, reading a message out of the queue, until we get a
// message with a length == 0, which signals us to quit.
for (int iter = 1; ;iter++)
{
ACE_Message_Block *mb = 0;
int result = this->getq (mb);
if (result == -1)
{
ACE_ERROR ((LM_ERROR,
"(%t) in iteration %d\n",
"error waiting for message in iteration",
iter));
break;
}
size_t length = mb->length ();
this->service (mb,iter);
if (length == 0)
{
ACE_DEBUG ((LM_DEBUG,
"(%t) in iteration %d got quit, exit!\n",
iter));
mb->release ();
break;
}
this->barrier_.wait ();
this->output (mb);
mb->release ();
}
// Note that the <ACE_Task::svc_run> method automatically removes us
// from the Thread_Manager when the thread exits.
return 0;
}
示例15: switch
int
Peer_Handler::await_events (void)
{
ACE_Message_Block *mb = 0;
ssize_t n = this->recv (mb);
switch (n)
{
case 0:
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("gatewayd has closed down\n")),
-1);
/* NOTREACHED */
case -1:
if (errno == EWOULDBLOCK)
// A short-read, we'll come back and finish it up later on!
return 0;
else
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("recv")),
-1);
/* NOTREACHED */
default:
{
// We got a valid event, so let's process it now! At the
// moment, we just print out the event contents...
Event *event = (Event *) mb->rd_ptr ();
this->total_bytes_ += mb->length ();
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("route id = %d, cur len = %d, total len = %d\n"),
event->header_.connection_id_,
event->header_.len_,
this->total_bytes_));
if (Options::instance ()->enabled (Options::VERBOSE))
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("data_ = %*s\n"),
event->header_.len_ - 2,
event->data_));
mb->release ();
return 0;
}
}
}