本文整理汇总了C++中ACE_Message_Block::cont方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_Message_Block::cont方法的具体用法?C++ ACE_Message_Block::cont怎么用?C++ ACE_Message_Block::cont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_Message_Block
的用法示例。
在下文中一共展示了ACE_Message_Block::cont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
ACE_Message_Block* head = new ACE_Message_Block(BUFSIZ);
ACE_Message_Block* mblk = head;
while(1)
{
size_t nbytesRead = 0;
ssize_t nbytes = ACE::read_n(ACE_STDIN, mblk->wr_ptr(), mblk->size(), &nbytesRead);
mblk->wr_ptr(nbytesRead); // Need to adjust the ptr by user if we directly modify the momoey in the message block ...
mblk->cont(new ACE_Message_Block(BUFSIZ));
mblk = mblk->cont();
// nbytes will be zero if encount EOF or error
// even nbytes is zero the nbytesRead could still not be zero
if (nbytes <= 0)
{
log("Receive EOF\n");
break;
}
}
for (mblk = head; mblk != 0; mblk = mblk->cont())
{
ACE::write_n(ACE_STDOUT, mblk->rd_ptr(), mblk->length());
}
head->release(); // Thie releases all the memory in the chain.
return 0;
}
示例2: release_cfentries
void release_cfentries(ACE_Message_Block& mb_hdr)
{
ACE_Message_Block* cf = mb_hdr.cont();
mb_hdr.cont(mb_hdr.cont()->cont());
cf->cont(0);
cf->release();
}
示例3: sizeof
int
Task::handle_input( ACE_HANDLE h )
{
const size_t size = 2000;
ACE_Message_Block * mb = new ACE_Message_Block( size );
ACE_Message_Block * pfrom = new ACE_Message_Block( sizeof( ACE_INET_Addr ) );
ACE_INET_Addr * addr = new ( pfrom->wr_ptr() ) ACE_INET_Addr();
int res = 0;
if ( mcast_handler_ && ( h == mcast_handler_->get_handle() ) ) {
mb->msg_type( constants::MB_MCAST );
res = mcast_handler_->recv( mb->wr_ptr(), size, *addr );
}
if ( res == (-1) ) {
DWORD err = GetLastError();
(void)err;
ACE_Message_Block::release( mb );
ACE_Message_Block::release( pfrom );
return 0;
}
mb->length( res );
mb->cont( pfrom );
putq( mb );
return 0;
}
示例4: readdatagram
int UDPGenerator::readdatagram(int header_size)
{
ACE_Message_Block* msg = 0;/*{{{*/
ACE_NEW_RETURN (msg, ACE_Message_Block (1024), -1);
msg->size (header_size); // size of header to read is 20 bytes
// create a message block to read the message body
ACE_Message_Block* body = 0;
ACE_NEW_RETURN (body, ACE_Message_Block (1024), -1);
// The message body will not exceed 1024 bytes, at least not in this test.
msg->cont (body);
// ok lets do the asynch read
size_t number_of_bytes_recvd = 0;
int res = rd_.recv (
msg,
number_of_bytes_recvd,
0,
PF_INET,
this->act_);
/*}}}*/
switch (res)/*{{{*/
{
case 0:
// this is a good error. The proactor will call our handler when the
// read has completed.
break;
case 1:
// actually read something, we will handle it in the handler callback
ACE_DEBUG ((LM_DEBUG, "********************\n"));
ACE_DEBUG ((LM_DEBUG,
"%s = %d\n",
"bytes recieved immediately",
number_of_bytes_recvd));
ACE_DEBUG ((LM_DEBUG, "********************\n"));
res = 0;
break;
case -1:
// Something else went wrong.
ACE_ERROR ((LM_ERROR,
"%p\n",
"ACE_Asynch_Read_Dgram::recv"));
// the handler will not get called in this case so lets clean up our msg
msg->release ();
break;
default:
// Something undocumented really went wrong.
ACE_ERROR ((LM_ERROR,
"%p\n",
"ACE_Asynch_Read_Dgram::recv"));
msg->release ();
break;
}/*}}}*/
return res;
}
示例5: if
void
PConnection::trace_buffers(const Buffer_Info& buf_info,
size_t xfer_bytes,
bool flg_read)
{
int iovcnt = buf_info.get_iov_count ();
if (iovcnt < 0) // ACE_Message_Block
{
ACE_Message_Block * mb = buf_info.get_message_block_ptr();
for (int i=0;
xfer_bytes != 0 && mb != 0 ;
mb = mb->cont (), ++i)
{
char * ptr = flg_read ? mb->wr_ptr () : mb->rd_ptr ();
size_t len = flg_read ? mb->length () : (ptr - mb->base ());
if (len > xfer_bytes)
len = xfer_bytes;
ptr -= len;
xfer_bytes -=len;
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("message_block [%d] length=%d:\n"), i, (int)len));
ACE_HEX_DUMP ((LM_DEBUG, ptr, len));
}
}
else if (iovcnt > 0) // iovec
{
iovec *iov = buf_info.get_iov ();
for (int i=0; xfer_bytes != 0 && i < iovcnt; ++i)
{
char * ptr = (char*) iov[i].iov_base;
size_t len = iov[i].iov_len;
if (len > xfer_bytes)
len = xfer_bytes;
ptr -= len;
xfer_bytes -=len;
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("iov[%d] length=%d:\n"), i, (int)len));
ACE_HEX_DUMP ((LM_DEBUG, ptr, len));
}
}
else // simple buffer
{
char *ptr = buf_info.get_buffer ();
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("buffer length=%d:\n"), (int)xfer_bytes));
ACE_HEX_DUMP ((LM_DEBUG, ptr, xfer_bytes));
}
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("**** end of buffers ****************\n")));
}
示例6: handle_input
int AC_Input_Handler::handle_input (ACE_HANDLE handle) {
ACE_Message_Block *mblk = 0;
Logging_Handler logging_handler (handle);
if (logging_handler.recv_log_record (mblk) != -1)
{
if (output_handler_->put (mblk->cont ()) != -1)
{
mblk->cont (0);
mblk->release ();
return 0; // Success return.
}
else
{
mblk->release ();
}
}
return -1; // Error return.
}
示例7: scheduleSend
int TCPConnectionHandler::scheduleSend (ACE_Message_Block * buffer)
{
// link buffer to the end of buffers list
if (buffers_)
{
ACE_Message_Block *lastBuffer = buffers_;
while (lastBuffer->cont ())
lastBuffer = lastBuffer->cont () ;
lastBuffer->cont (buffer);
}
else
buffers_ = buffer;
if (0 > sendBuffers ())
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT (" (%P) %p\n"),
ACE_TEXT ("Cannot schedule TCP send.")),
-1);
return 0;
}
示例8: get_file
//get file and store it into ACE message block.
bool ZIP_Wrapper::get_file (char* archive_path, char* filename,
ACE_Message_Block &file)
{
bool return_code = true;
unzFile uf=0;
uf = unzOpen(archive_path);
/* locate the desired file in the zip file and set it as current file*/
int j=unzLocateFile(uf, filename, 0);
if (j==UNZ_END_OF_LIST_OF_FILE)
{
DANCE_ERROR (DANCE_LOG_ERROR,
(LM_DEBUG, ACE_TEXT("File not found in zip archive")));
return false;
}
else if (j==UNZ_OK)
{
int k=unzOpenCurrentFile(uf);
if (k!=UNZ_OK)
{
DANCE_ERROR (DANCE_LOG_ERROR,
(LM_DEBUG, ACE_TEXT("Error in opening the current")
ACE_TEXT(" file using unzOpenCurrentFile")));
return false;
}
else
{
int num_read = 0;
ACE_Message_Block* head = &file;
//read the file into the ACE_Message_Block
do
{
if (head->space () == 0)
{
ACE_Message_Block* next = 0;
ACE_NEW_RETURN (next, ACE_Message_Block (BUFSIZ), false);
head = head->cont ();
}
num_read = unzReadCurrentFile(archive_path, head->wr_ptr(),
head->space());
if (num_read > 0)
head->wr_ptr (num_read);
} while (num_read > 0);
if (num_read < 0)
return_code = false;
unzCloseCurrentFile(uf);
unzClose(uf);
return return_code;
}
}
return return_code;
}
示例9: put
virtual int put (ACE_Message_Block *mblk, ACE_Time_Value *)
{
for (ACE_Message_Block *temp = mblk; temp != 0; temp = temp->cont ())
{
if (temp->msg_type () != ACE_Message_Block::MB_STOP)
{
format_data(temp);
}
}
return put_next (mblk);
}
示例10: sizeof
void
displayChain(ACE_Message_Block* chain)
{
//std::cout << "DISPLAYING CHAIN" << std::endl;
for (ACE_Message_Block* current = chain; current; current = current->cont()) {
if (current->length() > 0) {
//std::cout << "DISPLAYING BLOCK" << std::endl;
ACE_TCHAR buffer[4096];
ACE::format_hexdump(current->base(), current->length(), buffer, sizeof(buffer));
std::cout << buffer << std::endl;
}
}
}
示例11:
int
Sender::initiate_write_stream (ACE_Message_Block &mb)
{
// send the odd to the first connection, and the even to the second
// connection.
ACE_Message_Block *odd_mb = &mb;
ACE_Message_Block *even_mb = mb.cont ();
split_odd_even_chains (odd_mb, even_mb);
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Sender::initiate_write_stream - (ODD ) writev %d\n"),
odd_mb->total_length ()));
if (this->ws_[ODD].writev (*odd_mb, odd_mb->total_length ()) == -1)
{
free_chunks_chain (odd_mb);
if (even_mb)
free_chunks_chain (even_mb);
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("Sender::ACE_Asynch_Stream::writev")),
-1);
}
++this->io_count_;
if (even_mb)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Sender::initiate_write_stream - (EVEN) writev %d\n"),
even_mb->total_length ()));
if (this->ws_[EVEN].writev (*even_mb, even_mb->total_length ()) == -1)
{
free_chunks_chain (even_mb);
ACE_ERROR_RETURN((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("Sender::ACE_Asynch_Stream::writev")),
-1);
}
++this->io_count_;
}
return 0;
}
示例12: 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;
}
示例13: SendInternal
void ProactorService::SendInternal(char* pBuffer, int bufferSize)
{
ACE_Message_Block* pBlock = NULL;
ACE_NEW_NORETURN(pBlock, ACE_Message_Block(bufferSize));
pBlock->copy((const char*)pBuffer, bufferSize);
if(NULL == pBlock->cont())
{
m_AsyncWriter.write(*pBlock, pBlock->length());
}
else
{
m_AsyncWriter.writev(*pBlock, pBlock->total_length());
}
}
示例14:
static void
run_test (SVC_HANDLER &svc_handler,
size_t iterations)
{
// Create a whole slew of message blocks and pass them to the
// <svc_handler>.
for (size_t i = 0; i < iterations; i++)
{
ACE_Message_Block *mb;
ACE_NEW (mb,
ACE_Message_Block (sizeof (ACE_LIB_TEXT("hello "))));
ACE_Message_Block *cb1;
ACE_NEW (cb1,
ACE_Message_Block (sizeof (ACE_LIB_TEXT("there\n"))));
ACE_Message_Block *cb2;
ACE_NEW (cb2,
ACE_Message_Block (sizeof (ACE_LIB_TEXT("there\n"))));
mb->copy ("hello ",
ACE_OS::strlen (ACE_LIB_TEXT("hello ")));
cb1->copy ("there ",
ACE_OS::strlen (ACE_LIB_TEXT("there ")));
mb->cont (cb1);
cb2->copy ("doug\n",
ACE_OS::strlen (ACE_LIB_TEXT("doug\n")));
cb1->cont (cb2);
// Note that this is a buffered call!
if (svc_handler.put (mb) == -1)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("put")));
}
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("final flush\n")));
// Make sure to flush everything out before we exit.
if (svc_handler.flush () == -1)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("flush")));
}
示例15: ACE_Message_Block
ssize_t
MulticastSendStrategy::async_send(const iovec iov[], int n)
{
#if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS)
if (!async_init_) {
if (-1 == async_writer_.open(*this, link_->socket().get_handle(), 0 /*completion_key*/,
link_->get_proactor())) {
return -1;
}
async_init_ = true;
}
ACE_Message_Block* mb = 0;
size_t total_length = 0;
for (int i = n - 1; i >= 0; --i) {
ACE_Message_Block* next =
new ACE_Message_Block(static_cast<const char*>(iov[i].iov_base),
iov[i].iov_len);
next->wr_ptr(iov[i].iov_len);
total_length += iov[i].iov_len;
next->cont(mb);
mb = next;
}
size_t bytes_sent = 0;
ssize_t result = async_writer_.send(mb, bytes_sent, 0 /*flags*/,
this->link_->config()->group_address_);
if (result < 0) {
mb->release();
return result;
}
// framework needs to think we sent the entire datagram
return total_length;
#else
ACE_UNUSED_ARG(iov);
ACE_UNUSED_ARG(n);
return -1;
#endif
}