本文整理汇总了C++中ACE_Message_Block::rd_ptr方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_Message_Block::rd_ptr方法的具体用法?C++ ACE_Message_Block::rd_ptr怎么用?C++ ACE_Message_Block::rd_ptr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_Message_Block
的用法示例。
在下文中一共展示了ACE_Message_Block::rd_ptr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: check_destroy
int
Receiver::handle_input (ACE_HANDLE h)
{
ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, locker, this->mutex_, -1);
ACE_Message_Block *mb = 0;
ACE_NEW_RETURN (mb,
ACE_Message_Block (BUFSIZ),
-1);
int err = 0;
ssize_t res = this->peer ().recv (mb->rd_ptr (), BUFSIZ-1);
this->total_r_++;
if (res >= 0)
{
mb->wr_ptr (res);
this->total_rcv_ += res;
}
else
err = errno ;
mb->wr_ptr ()[0] = '\0';
if (loglevel == 0 || res <= 0 || err!= 0)
{
LogLocker log_lock;
ACE_DEBUG ((LM_DEBUG, "**** Receiver::handle_input () SessionId=%d****\n", index_));
ACE_DEBUG ((LM_DEBUG, "%C = %d\n", "bytes_to_read", BUFSIZ));
ACE_DEBUG ((LM_DEBUG, "%C = %d\n", "handle", h));
ACE_DEBUG ((LM_DEBUG, "%C = %d\n", "bytes_transferred", res));
ACE_DEBUG ((LM_DEBUG, "%C = %d\n", "error", err));
ACE_DEBUG ((LM_DEBUG, "%C = %s\n", "message_block", mb->rd_ptr ()));
ACE_DEBUG ((LM_DEBUG, "**** end of message ****************\n"));
}
if (err == EWOULDBLOCK)
{
err=0;
res=0;
return check_destroy ();
}
if (err !=0 || res <= 0)
{
ACE_Message_Block::release (mb);
return -1;
}
ACE_Time_Value tv = ACE_Time_Value::zero;
int qcount = this->putq (mb, & tv);
if (qcount <= 0) // failed to putq
{
ACE_Message_Block::release (mb);
return -1 ;
}
int rc = 0;
if (duplex == 0) // half-duplex , stop read
rc = this->terminate_io (ACE_Event_Handler::READ_MASK);
else // full duplex
{
if (qcount >= 20 ) // flow control, stop read
rc = this->terminate_io (ACE_Event_Handler::READ_MASK);
else
rc = this->initiate_io (ACE_Event_Handler::READ_MASK);
}
if (rc == -1)
return -1;
//initiate write
if (this->initiate_io (ACE_Event_Handler::WRITE_MASK) != 0)
return -1;
return check_destroy ();
}
示例2: do_request
int DC_Service_Request::do_request(KSG_WORK_SVR_HANDLER *handle)
{
ACE_Message_Block *mblk = handle->mblk_;
ACE_SOCK_Stream peer;
ACE_Message_Block *resp_buf;
unsigned char *msg_begin = (unsigned char*)mblk->rd_ptr();
unsigned char *out_buf;
unsigned char crc_code[4];
int data_len = mblk->length();
short pack_len;
int len;
int ret;
peer.set_handle(handle->handle_);
ACE_HEX_DUMP((LM_DEBUG,mblk->rd_ptr(),mblk->length()));
if(msg_begin[0]!=0xC0 && msg_begin[data_len]!=0xC1)
{
ACE_DEBUG((LM_ERROR,"收到数据包起始符错误..."));
return -1;
}
BUF_2_SHORT_BE(pack_len,(msg_begin+1));
if(data_len - 3 < pack_len )
{
ACE_DEBUG((LM_ERROR,"收到错误数据包长度错误..."));
return -1;
}
// check crc
/*
pack_len = GenerateCRC16(msg_begin+3,data_len-3-3);
SHORT_2_BUF_BE(pack_len,crc_code);
if(memcmp(crc_code,msg_begin+data_len-3,2)!=0)
{
ACE_DEBUG((LM_ERROR,"收到数据包CRC校验错误..."));
return 0;
}
*/
if(calc_sum(msg_begin+3,data_len-3-2)!=msg_begin[data_len-2])
{
ACE_DEBUG((LM_ERROR,"收到数据包CRC校验错误..."));
return 0;
}
ACE_NEW_RETURN(resp_buf,ACE_Message_Block(128),-1);
len = 0;
out_buf = (unsigned char*)resp_buf->wr_ptr();
out_buf[0]=0xC2;
out_buf[3]=msg_begin[3];
switch(msg_begin[3])
{
case 0x70:
ret = do_upload_serial(msg_begin,data_len,out_buf+4,len);
break;
case 0x71:
ret = do_download_blkcard(msg_begin,data_len,out_buf+4,len);
break;
default:
ret = -1;
break;
}
if(ret == 1)
{
if(len > 0)
{
// 计算CRC
out_buf[4+len]=calc_sum(out_buf+3,len+1);
len+=5;
out_buf[len++] = 0xC3;
pack_len = len - 3;
SHORT_2_BUF_BE(pack_len,(out_buf+1));
resp_buf->wr_ptr(len);
ACE_HEX_DUMP((LM_DEBUG,resp_buf->rd_ptr(),resp_buf->length()));
ACE_Time_Value tv(0);
if(peer.send_n(resp_buf,&tv) <=0 )
{
ACE_DEBUG((LM_ERROR,"发送应答包失败"));
ret = -1;
}
else
{
ret = 1;
}
}
else
ret = 0;
}
resp_buf->release();
return ret;
}
示例3: buffer
void
JAWS_Config_File_Impl::parse_file (void)
{
ACE_FILE_Connector fconnector;
ACE_FILE_IO fio;
if (fconnector.connect ( fio
, this->faddr_
, 0
, ACE_Addr::sap_any
, 0
, O_RDONLY
) == -1)
return;
ACE_Message_Block buffer (8192);
ACE_Message_Block line (4096);
ssize_t count = 0;
const ACE_TCHAR *sym_name;
const ACE_TCHAR *sym_value;
int last_line_was_read = 0;
ACE_TCHAR *end_of_current_line = 0;
ACE_TCHAR *p = 0;
while (last_line_was_read
|| (count = fio.recv (buffer.wr_ptr (), buffer.space () - 2)) >= 0)
{
end_of_current_line = 0;
// Make sure input is newline terminated if it is the last line,
// and always null terminated.
if (! last_line_was_read)
{
if (count > 0)
{
buffer.wr_ptr (count);
// Scan forward for at least one newline character
p = buffer.rd_ptr ();
while (p != buffer.wr_ptr ())
{
if (*p == '\n')
break;
p++;
}
if (p == buffer.wr_ptr ())
continue;
end_of_current_line = p;
}
else
{
if (buffer.wr_ptr ()[-1] != '\n')
{
buffer.wr_ptr ()[0] = '\n';
buffer.wr_ptr (1);
}
last_line_was_read = 1;
}
buffer.wr_ptr ()[0] = '\0';
}
if (end_of_current_line == 0)
{
end_of_current_line = buffer.rd_ptr ();
while (*end_of_current_line != '\n')
end_of_current_line++;
}
// If buffer is not pointing to a continuation line, or there is
// no more input, then can commit the scanned configuration
// line.
if (line.length () != 0
&& ((last_line_was_read && buffer.length () == 0)
|| (buffer.rd_ptr ()[0] != ' '
&& buffer.rd_ptr ()[0] != '\t')))
{
ACE_TCHAR *name = 0;
ACE_TCHAR *value = 0;
name = line.rd_ptr ();
for (p = name; *p != '\0'; p++)
{
if (*p == '=')
{
line.rd_ptr (p+1);
while (p != name && (p[-1] == ' ' || p[-1] == '\t'))
p--;
*p = '\0';
}
}
if (*name)
{
value = line.rd_ptr ();
while (*value == ' ' || *value == '\t')
value++;
p = line.wr_ptr ();
//.........这里部分代码省略.........
示例4: signal
//.........这里部分代码省略.........
// errno appropriately. This is what the WinNT proactor
// does.
if (sig_return == -1)
ACE_ERROR_RETURN ((LM_ERROR, "Error: %p\n",
"Error waiting for RT completion signals"),
-1);
//FUZZ: disable check_for_lack_ACE_OS
// RT completion signals returned.
if (sig_return != SIGRTMIN)
ACE_ERROR_RETURN ((LM_ERROR,
"Unexpected signal (%d) has been received while waiting for RT Completion Signals\n",
sig_return),
-1);
//FUZZ: enble check_for_lack_ACE_OS
// @@ Debugging.
ACE_DEBUG ((LM_DEBUG,
"Sig number found in the sig_info block : %d\n",
sig_info.si_signo));
// Is the signo returned consistent?
if (sig_info.si_signo != sig_return)
ACE_ERROR_RETURN ((LM_ERROR,
"Inconsistent signal number (%d) in the signal info block\n",
sig_info.si_signo),
-1);
// @@ Debugging.
ACE_DEBUG ((LM_DEBUG,
"Signal code for this signal delivery : %d\n",
sig_info.si_code));
// Is the signal code an aio completion one?
if ((sig_info.si_code != SI_ASYNCIO) &&
(sig_info.si_code != SI_QUEUE))
ACE_ERROR_RETURN ((LM_DEBUG,
"Unexpected signal code (%d) returned on completion querying\n",
sig_info.si_code),
-1);
// Retrive the aiocb.
aiocb* aiocb_ptr = (aiocb *) sig_info.si_value.sival_ptr;
if (aiocb_ptr == &aiocb3)
{
ACE_ASSERT (sig_info.si_code == SI_QUEUE);
ACE_DEBUG ((LM_DEBUG, "sigqueue caught... good\n"));
}
else
{
// Analyze error and return values. Return values are
// actually <errno>'s associated with the <aio_> call
// corresponding to aiocb_ptr.
int error_code = aio_error (aiocb_ptr);
if (error_code == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n",
"Invalid control block was sent to <aio_error> for completion querying"),
-1);
if (error_code != 0)
// Error occurred in the <aio_>call. Return the errno
// corresponding to that <aio_> call.
ACE_ERROR_RETURN ((LM_ERROR, "%p\n",
"An AIO call has failed"),
error_code);
// No error occurred in the AIO operation.
int nbytes = aio_return (aiocb_ptr);
if (nbytes == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n",
"Invalid control block was send to <aio_return>"),
-1);
if (number_of_compleions == 0)
{
// Print the buffer.
ACE_DEBUG ((LM_DEBUG,
"\n Number of bytes transferred : %d\n",
nbytes));
// Note... the dumps of the buffers are disabled because they
// may easily overrun the ACE_Log_Msg output buffer. If you need
// to turn the on for some reason, be careful of this.
#if 0
ACE_DEBUG ((LM_DEBUG, "The buffer : %s\n", mb1.rd_ptr ()));
#endif /* 0 */
}
else
{
// Print the buffer.
ACE_DEBUG ((LM_DEBUG,
"\n Number of bytes transferred : %d\n",
nbytes));
#if 0
ACE_DEBUG ((LM_DEBUG, "The buffer : %s\n", mb2.rd_ptr ()));
#endif /* 0 */
}
}
}
return 0;
}
示例5:
static void *
peer1 (void *)
{
ACE_UPIPE_Stream c_stream;
ACE_DEBUG ((LM_DEBUG,
"(%t) peer1 starting connect\n"));
ACE_UPIPE_Connector con;
if (con.connect (c_stream, addr) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) peer1 ACE_UPIPE_Connector failed\n"));
ACE_Message_Block *mb;
ACE_NEW_RETURN (mb,
ACE_Message_Block (20),
0);
mb->copy ("hello", 6);
if (c_stream.send (mb) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) error peer1 send\n"));
if (c_stream.recv (mb) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) error peer1 recv\n"));
ACE_ERROR ((LM_ERROR,
"(%t) peer1 ack is \"%s\"\n",
mb->rd_ptr ()));
// Free up the memory block.
mb->release ();
// Now try the send()/recv() interface.
char mytext[] = "This string is sent by peer1 as buffer";
ACE_ERROR ((LM_ERROR,
"(%t) peer1 sending text\n"));
if (c_stream.send (mytext, sizeof mytext) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) buffer send from peer1 failed\n"));
char conbuf[30]; // Buffer to receive response.
int i = 0;
for (char c = ' '; c != '!'; i++)
{
if (c_stream.recv (&c, 1) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) buffer recv from peer1 failed\n"));
else
conbuf[i] = c;
}
conbuf[i] = '\0';
ACE_DEBUG ((LM_DEBUG,
"(%t) peer1 received buffer with \"%s\"\n",
conbuf));
c_stream.close ();
return 0;
}
示例6:
ACE_Message_Block *
ACE_Message_Block::duplicate (void) const
{
ACE_TRACE ("ACE_Message_Block::duplicate");
ACE_Message_Block *nb = 0;
// Create a new <ACE_Message_Block> that contains unique copies of
// the message block fields, but a reference counted duplicate of
// the <ACE_Data_Block>.
// If there is no allocator, use the standard new and delete calls.
if (this->message_block_allocator_ == 0)
ACE_NEW_RETURN (nb,
ACE_Message_Block (0, // size
ACE_Message_Type (0), // type
0, // cont
0, // data
0, // allocator
0, // locking strategy
0, // flags
this->priority_, // priority
ACE_EXECUTION_TIME,
ACE_DEADLINE_TIME,
// Get a pointer to a
// "duplicated" <ACE_Data_Block>
// (will simply increment the
// reference count).
this->data_block ()->duplicate (),
this->data_block ()->data_block_allocator (),
this->message_block_allocator_),
0);
else // Otherwise, use the message_block_allocator passed in.
ACE_NEW_MALLOC_RETURN (nb,
static_cast<ACE_Message_Block*> (
message_block_allocator_->malloc (sizeof (ACE_Message_Block))),
ACE_Message_Block (0, // size
ACE_Message_Type (0), // type
0, // cont
0, // data
0, // allocator
0, // locking strategy
0, // flags
this->priority_, // priority
ACE_EXECUTION_TIME,
ACE_DEADLINE_TIME,
// Get a pointer to a
// "duplicated" <ACE_Data_Block>
// (will simply increment the
// reference count).
this->data_block ()->duplicate (),
this->data_block ()->data_block_allocator (),
this->message_block_allocator_),
0);
// Set the read and write pointers in the new <Message_Block> to the
// same relative offset as in the existing <Message_Block>. Note
// that we are assuming that the data_block()->base() pointer
// doesn't change when it's duplicated.
nb->rd_ptr (this->rd_ptr_);
nb->wr_ptr (this->wr_ptr_);
// Increment the reference counts of all the continuation messages.
if (this->cont_)
{
nb->cont_ = this->cont_->duplicate ();
// If things go wrong, release all of our resources and return
// 0.
if (nb->cont_ == 0)
{
nb->release ();
nb = 0;
}
}
return nb;
}
示例7: handle_input
//
// handle_input
//
int CUTS_TCPIP_Event_Handler::handle_input (ACE_HANDLE fd)
{
// Set the ACE_HANDLE as a socket stream.
ACE_SOCK_Stream stream (fd);
// @todo Since the header size is constant, we can create free list
// of the message blocks that are used to read the header from
// the stream.
// Read the event from the stream. The first chunk of the event
// is be the header information, which is of constrant size.
static const ssize_t header_size = 4 + // magic
4 + // byte order
2 + // version (x.x)
2 + // padding
16 + // UUID
4 + // event id
4; // payload size
ACE_Message_Block header (header_size);
ssize_t retcode = stream.recv_n (header.wr_ptr (), header_size);
if (retcode != header_size)
ACE_ERROR_RETURN ((LM_ERROR,
"%T (%t) - %M - invalid TCP/IP header\n"),
-1);
// Reflect the number of bytes read from the stream.
header.wr_ptr (header_size);
// Extract the header from the message block.
CUTS_TCPIP_SPEC spec;
ACE_CDR::ULong datasize;
ACE_InputCDR input (header.rd_ptr (), header_size);
// Read the SPEC and the datasize from the packet.
input >> spec;
input >> datasize;
if (!input.good_bit ())
ACE_ERROR_RETURN ((LM_ERROR,
"%T (%t) - %M - failed to read TCP/IP header\n"),
-1);
// Construct a chain of message blocks to read the payload associated
// with the received event.
ACE_Message_Block * mb = 0;
ACE_NEW_RETURN (mb, ACE_Message_Block (ACE_CDR::DEFAULT_BUFSIZE), -1);
ssize_t read_count;
ACE_Message_Block * head = mb;
ACE_Auto_Ptr <ACE_Message_Block> auto_clean (head);
for (size_t remaining = datasize; 0 != remaining; )
{
// Determine how much should be read in this attempt.
read_count =
ACE_CDR::DEFAULT_BUFSIZE < remaining ?
ACE_CDR::DEFAULT_BUFSIZE : remaining;
// Read the data from the stream.
retcode = stream.recv_n (mb->wr_ptr (), read_count);
if (retcode != read_count)
ACE_ERROR_RETURN ((LM_ERROR,
"%T - %M - %m\n"),
-1);
// Substract the amount from the remaining count.
mb->wr_ptr (read_count);
remaining -= read_count;
if (0 != remaining)
{
// Allocate a new block for the chain.
ACE_Message_Block * temp = 0;
ACE_NEW_RETURN (temp,
ACE_Message_Block (ACE_CDR::DEFAULT_BUFSIZE),
-1);
// Insert new block in the chain and move forward.
mb->cont (temp);
mb = temp;
}
}
// Since we have made it this far, we have successfully read the
// event and its payload from the socket. Now, pass the message
// the object manger, so it can dispatch it accordingly.
if (this->obj_mgr_ != 0)
{
iCCM::TCPIP_Servant * svnt = 0;
//.........这里部分代码省略.........
示例8: svc
int Task::svc (void)
{
// This is the function that our service threads run once they are spawned.
ACE_DEBUG ((LM_DEBUG, " (%P|%t) %s Task::svc () -- once per servicing thread\n", d_nameOfTask));
// First, we wait until all of our peer service threads have arrived
// at this point also.
d_barrier.wait ();
ACE_Message_Block *messageBlock;
while (1) {
// And now we loop almost infinitely.
// getq () will block until a Message_Block is available to be read,
// or an error occurs.
if ( this->getq (messageBlock, 0) == -1) {
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "Task::svc () getq"), -1);
}
if (messageBlock->msg_type () == ACE_Message_Block::MB_HANGUP) {
// If the Message_Block is of type MB_HANGUP, then we're being asked
// to shut down nicely.
ACE_DEBUG ((LM_DEBUG, " (%P|%t) %s Task::svc () -- HANGUP block received\n", d_nameOfTask));
// So, we duplicate the Block, and put it back into the Message_Queue,
// in case there are some more peer service threads still running.
if (this->putq (messageBlock->duplicate ()) == -1) {
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "Task::svc () putq"), -1);
}
// We release our copy of the Block.
messageBlock->release ();
// And we break out of the nearly infinitely loop, and
// head towards close () ourselves.
break;
}
// If we're here, then we've received a Message_Block that was
// not informing us to quit, so we're assuming it's a valid
// meaningful Block.
ACE_DEBUG ((LM_DEBUG, " (%P|%t) %s Task::svc () -- Normal block received\n", d_nameOfTask));
// We grab the read-pointer from the Block, and display it through a DEBUG statement.
ACE_DEBUG ((LM_DEBUG, " (%P|%t) %s Task::svc () -- %s\n", d_nameOfTask, messageBlock->rd_ptr () ));
// We pretend that this takes to time to process the Block.
// If you're on a fast machine, you might have to raise this
// value to actually witness different threads handling
// blocks for each Task.
ACE_OS::sleep (ACE_Time_Value (0, 250));
// Since we're part of a Stream, we duplicate the Block, and
// send it on to the next Task.
if (put_next (messageBlock->duplicate ()) == -1) {
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "Task::svc () put_next"), -1);
}
// And then we release our copy of it.
messageBlock->release ();
}
return 0;
}
示例9: svc
int GadgetStreamController::svc(void)
{
while (true) {
GadgetMessageIdentifier id;
ssize_t recv_cnt = 0;
if ((recv_cnt = peer().recv_n (&id, sizeof(GadgetMessageIdentifier))) <= 0) {
GERROR("GadgetStreamController, unable to read message identifier\n");
return -1;
}
if (id.id == GADGET_MESSAGE_CLOSE) {
stream_.close(1); //Shutdown gadgets and wait for them
GDEBUG("Stream closed\n");
GDEBUG("Closing writer task\n");
this->writer_task_.close(1);
GDEBUG("Writer task closed\n");
continue;
}
GadgetMessageReader* r = readers_.find(id.id);
if (!r) {
GERROR("Unrecognized Message ID received: %d\n", id.id);
return GADGET_FAIL;
}
ACE_Message_Block* mb = r->read(&peer());
if (!mb) {
GERROR("GadgetMessageReader returned null pointer\n");
return GADGET_FAIL;
}
//We need to handle some special cases to make sure that we can get a stream set up.
if (id.id == GADGET_MESSAGE_CONFIG_FILE) {
GadgetContainerMessage<GadgetMessageConfigurationFile>* cfgm =
AsContainerMessage<GadgetMessageConfigurationFile>(mb);
if (!cfgm) {
GERROR("Failed to cast message block to configuration file\n");
mb->release();
return GADGET_FAIL;
} else {
if (this->configure_from_file(std::string(cfgm->getObjectPtr()->configuration_file)) != GADGET_OK) {
GERROR("GadgetStream configuration failed\n");
mb->release();
return GADGET_FAIL;
} else {
mb->release();
continue;
}
}
} else if (id.id == GADGET_MESSAGE_CONFIG_SCRIPT) {
std::string xml_config(mb->rd_ptr(), mb->length());
if (this->configure(xml_config) != GADGET_OK) {
GERROR("GadgetStream configuration failed\n");
mb->release();
return GADGET_FAIL;
} else {
mb->release();
continue;
}
}
ACE_Time_Value wait = ACE_OS::gettimeofday() + ACE_Time_Value(0,10000); //10ms from now
if (stream_.put(mb) == -1) {
GERROR("Failed to put stuff on stream, too long wait, %d\n", ACE_OS::last_error () == EWOULDBLOCK);
mb->release();
return GADGET_FAIL;
}
}
return GADGET_OK;
}
示例10: peerAddr
void
DSession::handle_write_dgram(const TRB_Asynch_Write_Dgram::Result &result)
{
{
ACE_GUARD (ACE_SYNCH_MUTEX, monitor, this->lock_);
this->io_count_w_--;
int loglevel = cfg.loglevel();
ACE_Message_Block *mb = result.message_block ();
size_t xfer_bytes = result.bytes_transferred();
char * last = mb->rd_ptr();
char * first = last - xfer_bytes;
u_long error = result.error ();
const ACE_Addr & addr = result.remote_address ();
ACE_INET_Addr peerAddr ((u_short)0);
if (addr.get_type () == peerAddr.get_type ())
{ // copy the remote_address_ into addr
peerAddr.set_addr (addr.get_addr(),
addr.get_size());
}
if (cfg.loglevel () == 0)
{
LogLocker log_lock;
//mb.rd_ptr () [0] = '\0';
mb->rd_ptr (mb->rd_ptr () - result.bytes_transferred ());
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) **** %s=%d handle_write_dgram() ****\n"),
this->get_name(),
this->index()));
this->print_address (result.remote_address());
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %d\n"),
ACE_TEXT ("bytes_to_write"),
result.bytes_to_write ()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %d\n"),
ACE_TEXT ("handle"),
result.handle ()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %d\n"),
ACE_TEXT ("bytes_transfered"),
result.bytes_transferred ()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %d\n"),
ACE_TEXT ("error"),
error));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("message_block:\n")));
ACE_HEX_DUMP ((LM_DEBUG, first, xfer_bytes));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("**** end of message ****************\n")));
}
else if (error != 0)
{
LogLocker log_lock;
this->print_address (result.remote_address());
ACE_OS::last_error (error);
ACE_Log_Msg::instance ()->errnum (error);
ACE_Log_Msg::instance ()->log (LM_ERROR,
ACE_TEXT ("(%t) %s=%d WRITE ERROR=%d %p\n"),
this->get_name (),
this->index (),
error,
ACE_TEXT (":"));
}
else if (loglevel == 1)
{
LogLocker log_lock;
this->print_address (result.remote_address());
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) %s=%d WRITE=%d bytes ok\n"),
this->get_name (),
this->index (),
result.bytes_transferred ()));
}
if (error == 0 && result.bytes_transferred () > 0)
{
this->total_snd_ += result.bytes_transferred ();
//.........这里部分代码省略.........
示例11: if
int
Worker_Task::svc (void)
{
// The <ACE_Task::svc_run()> method automatically adds us to the
// process-wide <ACE_Thread_Manager> when the thread begins.
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) starting svc() method\n")));
// 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 = 0; ; count++)
{
ACE_Message_Block *mb = 0;
if (-1 == this->msg_queue ()->dequeue_head (mb))
ACE_ERROR_BREAK ((LM_ERROR,
ACE_TEXT ("(%t) %p\n"),
ACE_TEXT ("Worker_Task dequeue_head")));
size_t length = mb->length ();
// If there's a next() Task then "logically" copy the message by
// calling <duplicate> and send it on down the pipeline. Note
// that this doesn't actually make a copy of the message
// contents (i.e., the Data_Block portion), it just makes a copy
// of the header and reference counts the data.
if (this->next () != 0)
{
if (-1 == this->put_next (mb->duplicate ()))
ACE_ERROR_BREAK ((LM_ERROR,
ACE_TEXT ("(%t) %p\n"),
ACE_TEXT ("Worker_Task put_next")));
}
// If there's no next() Task to send to, then we'll consume the
// message here.
else if (length > 0)
{
int current_count = ACE_OS::atoi ((ACE_TCHAR *)(mb->rd_ptr ()));
int i;
if (count != current_count)
ACE_ERROR_BREAK ((LM_ERROR,
ACE_TEXT ("(%t) count from block should be %d ")
ACE_TEXT ("but is %d\n"),
count, current_count));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) enqueueing %d duplicates\n"),
current_count));
ACE_Message_Block *dup;
// Enqueue <current_count> duplicates with msg_priority == 1.
for (i = current_count; i > 0; i--)
{
ACE_ALLOCATOR_RETURN (dup,
mb->duplicate (),
-1);
// Set the priority to be greater than "normal"
// messages. Therefore, all of these messages should go
// to the "front" of the queue, i.e., ahead of all the
// other messages that are being enqueued by other
// threads.
dup->msg_priority (ACE_DEFAULT_MESSAGE_BLOCK_PRIORITY + 1);
int enqueue_prio_result =
this->msg_queue ()->enqueue_prio
(dup,
// Don't block indefinitely if we flow control...
(ACE_Time_Value *) &ACE_Time_Value::zero);
if (enqueue_prio_result == -1)
ACE_ERROR_BREAK ((LM_ERROR,
ACE_TEXT ("(%t) Pass %d %p\n"),
i,
ACE_TEXT ("Worker_Task enqueue_prio")));
}
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) dequeueing %d duplicates\n"),
current_count));
// Dequeue the same <current_count> duplicates.
for (i = current_count; i > 0; i--)
{
if (-1 == this->msg_queue ()->dequeue_head (dup))
ACE_ERROR_BREAK ((LM_ERROR,
ACE_TEXT ("(%t) Dup %d, %p\n"),
i,
ACE_TEXT ("Worker_Task dequeue dups")));
if (count != ACE_OS::atoi ((ACE_TCHAR *)(dup->rd_ptr ())))
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%t) line %l, Dup %d, block's count ")
ACE_TEXT ("is %d but should be %d\n"),
i,
ACE_OS::atoi ((ACE_TCHAR *)(dup->rd_ptr ())),
count));
//.........这里部分代码省略.........
示例12: if
void
DSession::handle_read_dgram (const TRB_Asynch_Read_Dgram::Result &result)
{
{
ACE_GUARD (ACE_SYNCH_MUTEX, monitor, this->lock_ );
this->io_count_r_--;
int loglevel = cfg.loglevel();
ACE_Message_Block *mb = result.message_block ();
size_t xfer_bytes = result.bytes_transferred();
char * last = mb->wr_ptr();
char * first = last - xfer_bytes;
u_long error = result.error ();
if (loglevel == 0)
{
LogLocker log_lock;
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) **** %s=%d handle_read_dgram() ****\n"),
this->get_name(),
this->index()));
this->print_address (result.remote_address());
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %d\n"),
ACE_TEXT ("bytes_to_read"),
result.bytes_to_read ()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %d\n"),
ACE_TEXT ("handle"),
result.handle ()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %d\n"),
ACE_TEXT ("bytes_transfered"),
result.bytes_transferred ()));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%s = %d\n"),
ACE_TEXT ("error"),
error));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("message_block:\n")));
ACE_HEX_DUMP ((LM_DEBUG, first, xfer_bytes));
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("**** end of message ****************\n")));
}
else if (error != 0)
{
LogLocker log_lock;
this->print_address (result.remote_address());
ACE_OS::last_error (error);
ACE_Log_Msg::instance ()->errnum (error);
ACE_Log_Msg::instance ()->log (LM_ERROR,
ACE_TEXT ("(%t) %s=%d READ ERROR=%d %p\n"),
this->get_name (),
this->index (),
error,
ACE_TEXT (":"));
}
else if (loglevel == 1)
{
LogLocker log_lock;
this->print_address (result.remote_address());
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) %s=%d READ=%d bytes ok\n"),
this->get_name (),
this->index (),
result.bytes_transferred ()));
}
do_delay (cfg.delay()); // delay milliseconds
if (error == 0 && result.bytes_transferred () > 0)
{
this->total_rcv_ += result.bytes_transferred ();
}
else
{
mb->msg_type (ACE_Message_Block::MB_HANGUP);
mb->wr_ptr (mb->rd_ptr());
}
//.........这里部分代码省略.........
示例13: if
int
JAWS_Parse_Headers::parse_headers (JAWS_Header_Info *info,
ACE_Message_Block &mb)
{
for (;;)
{
if (mb.rd_ptr () == mb.wr_ptr ())
break;
char *p = mb.rd_ptr ();
if (info->end_of_line ()
&& (*p != ' ' && *p != '\t'))
{
int r = this->parse_header_name (info, mb);
if (r == 1)
return info->end_of_headers ();
continue;
}
else
{
int r = this->parse_header_value (info, mb);
if (r == 1)
{
if (info->end_of_headers ())
return 1;
break;
}
continue;
}
}
// If we arrive here, it means either there is nothing more to read,
// or parse_header_value ran into difficulties (like maybe the
// header value was too long).
if (mb.rd_ptr () != mb.base ())
{
mb.crunch ();
return 0;
}
else if (mb.length () < mb.size ())
{
return 0;
}
else if (mb.length () == mb.size ())
{
// This is one of those cases that should rarely ever happen.
// If we get here, the header type name is over 8K long. We
// flag this as a bad thing.
// In HTTP/1.1, I have to remember that a bad request means the
// connection needs to be closed and the client has to
// reinitiate the connection.
info->status (JAWS_Header_Info::STATUS_CODE_TOO_LONG);
return 1;
}
else if (mb.length () > mb.size ())
{
ACE_DEBUG ((LM_DEBUG, "JAWS_Parse_Headers: buffer overrun!!\n"));
info->status (JAWS_Header_Info::STATUS_CODE_TOO_LONG);
return 1;
}
ACE_DEBUG ((LM_DEBUG, "JAWS_Parse_Headers -- shouldn't be here!\n"));
return 1;
}
示例14: appendBody
int Request::appendBody(const char* buf, const size_t bufSize)
{
ACE_ASSERT(buf);
ACE_ASSERT(bufSize > 0);
// 아래를 안해 주면 대용량 처리할 때 문제가 된다.
// bufSize 는 recv Buffer 사이즈로 4K 정도이다.
// 메모리 할당/해제 회수를 줄일려면 아래를 실행 해 주어야 한다.
if (pRawBody == NULL)
{
// 아래를 안해 주면 대용량 처리할 때 문제가 된다.
// 메모리 할당/해제 회수를 줄일려면 아래를 실행 해 주어야 한다.
size_t newSize = std::max(bufSize, contentLength);
// chunk 인 경우 빨리 버퍼를 충분히 할당하기 위해. (2007.1.3)
// 빈번한 버퍼 크기 확장을 막기 위해, 초기 최소 사이즈를 제한
newSize = std::max(newSize, (size_t)CHUNK_INIT_BUFFSIZE);
pRawBody = pMBManager->alloc(newSize);
if(pRawBody == NULL)
{
PAS_ERROR("Request::appendBody, AllocMessageBlock fail!!");
return -1;
}
}
ACE_ASSERT(pRawBody != NULL);
if(pRawBody->space() < bufSize)
{
// 기존 수신데이터 사이즈에 따른 셋팅 - 기존 사이즈의 배수로 증가.
size_t newSize = std::max((pRawBody->size() + (bufSize * 2)), (pRawBody->size() * 2));
PAS_DEBUG2("Request::appendBody OldSize[%d] NewSize[%d]", pRawBody->size(), newSize);
// 버퍼 사이즈 변경(resize)
ACE_Message_Block* pTmpBlock = pRawBody;
pRawBody = pMBManager->alloc(newSize);
if(pRawBody == NULL)
{
PAS_ERROR("Request::appendBody, AllocMessageBlock fail!!");
return -1;
}
// 임시 버퍼로 부터 데이터 복원
int resultCopy = pRawBody->copy(pTmpBlock->rd_ptr(), pTmpBlock->length());
if(resultCopy < 0)
{
PAS_ERROR("Response::appendBody >> 기존 데이터 복사 실패");
}
// 임시 버퍼 삭제
pMBManager->free(pTmpBlock);
}
// append
int resultCopy = pRawBody->copy(buf, bufSize);
if(resultCopy < 0)
{
PAS_ERROR("Response::appendBody >> 신규 데이터 복사 실패");
return -1;
}
// re-calculate
bodyLeng = pRawBody->length();
return 0;
}
示例15: while
int
JAWS_Parse_Headers::parse_header_value (JAWS_Header_Info *info,
ACE_Message_Block &mb)
{
// break --> return 1;
// continue --> return 0;
char *q = mb.rd_ptr ();
if (info->last_header_data () == 0)
{
// Ignoring this header (it is too long or something).
q = this->skipset ("\n", mb.rd_ptr (), mb.wr_ptr ());
if (q == mb.wr_ptr ())
{
info->end_of_line (0);
mb.rd_ptr (q);
// Move the rd_ptr back one character if the last thing we
// see is a carriage return. Assert: wr_ptr > rd_ptr.
if (q[-1] == '\r')
mb.rd_ptr (q-1);
return 1;
}
if (*q == '\0')
{
// We are in the middle of binary data. Get out!
mb.rd_ptr (q);
info->end_of_line (1);
info->end_of_headers (1);
return 1;
}
// Move past the newline, set the end of line flag
if (*q == '\n')
{
info->end_of_line (1);
q++;
}
mb.rd_ptr (q);
return 0;
}
else
{
if (info->end_of_line ())
{
// Skip over leading linear white space
q = this->skipcset (" \t", mb.rd_ptr (), mb.wr_ptr ());
if (q == mb.wr_ptr ())
{
// need more input
info->end_of_line (1);
mb.rd_ptr (q-1);
return 1;
}
if (*q != '\n')
info->append_last_header_value (' ');
}
// Append to last header value character by character
while (q < mb.wr_ptr ())
{
if (*q == '\n')
break;
info->append_last_header_value (*q);
q++;
}
// Need more input
if (q == mb.wr_ptr ())
{
mb.rd_ptr (q);
info->end_of_line (0);
return 1;
}
// Reached a newline
if (*q == '\n')
{
// Reduce by one character if line discipline is "\r\n"
if (info->append_last_header_value () == '\r')
info->reduce_last_header_value ();
// Move past newline, set end of line flag
mb.rd_ptr (q+1);
info->end_of_line (1);
return 0;
}
}
// NOT REACHED
return 1;
}