本文整理汇总了C++中ACE_Message_Block::copy方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_Message_Block::copy方法的具体用法?C++ ACE_Message_Block::copy怎么用?C++ ACE_Message_Block::copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_Message_Block
的用法示例。
在下文中一共展示了ACE_Message_Block::copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: recv_line
int RASocket::recv_line(ACE_Message_Block& buffer)
{
char byte;
for (;;)
{
ssize_t n = peer().recv(&byte, sizeof(byte));
if (n < 0)
{
return -1;
}
if (n == 0)
{
// EOF, connection was closed
errno = ECONNRESET;
return -1;
}
ACE_ASSERT(n == sizeof(byte));
if (byte == '\n')
break;
else if (byte == '\r') /* Ignore CR */
continue;
else if (buffer.copy(&byte, sizeof(byte)) == -1)
return -1;
}
const char null_term = '\0';
if (buffer.copy(&null_term, sizeof(null_term)) == -1)
return -1;
return 0;
}
示例2: rescuerHandSake
int UDPGenerator::rescuerHandSake(
const ACE_TCHAR * remotehost,
u_short remoteport)
{
ACE_DEBUG ((LM_DEBUG, "Sender::initiate_write called\n"));
const size_t max_payload_size = 4 + ACE_CDR::MAX_ALIGNMENT; //pading
u_short myid = htons(5);
u_short mysize = htons(0);
ACE_Message_Block* body = 0;
ACE_NEW_RETURN(body, ACE_Message_Block(4), -1);
body->copy((const char *)&myid, 2);
body->copy((const char *)&mysize, 2);
size_t number_of_bytes_sent = 0;
ACE_INET_Addr serverAddr(remoteport, remotehost);
int res = this->wd_.send(
body, number_of_bytes_sent,
0,
serverAddr,
this->act_);
switch (res)
{
case 0:
// this is a good error. The proactor will call our handler when the
// send has completed.
break;
case 1:
// actually sent something, we will handle it in the handler callback
ACE_DEBUG ((LM_DEBUG, "********************\n"));
ACE_DEBUG ((LM_DEBUG,
"%s = %d\n",
"bytes sent immediately",
number_of_bytes_sent));
ACE_DEBUG ((LM_DEBUG, "********************\n"));
res = 0;
break;
case -1:
// Something else went wrong.
ACE_ERROR ((LM_ERROR,
"%p\n",
"ACE_Asynch_Write_Dgram::recv"));
// the handler will not get called in this case so lets clean up our msg
body->release ();
break;
default:
// Something undocumented really went wrong.
ACE_ERROR ((LM_ERROR,
"%p\n",
"ACE_Asynch_Write_Dgram::recv"));
body->release ();
break;
}
return res;
}
示例3:
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;
}
示例4: SendPacket
int WorldSocket::SendPacket(WorldPacket const& pct)
{
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
if (closing_)
return -1;
// Dump outgoing packet.
if (sPacketLog->CanLogPacket())
sPacketLog->LogPacket(pct, SERVER_TO_CLIENT);
// Create a copy of the original packet; this is to avoid issues if a hook modifies it.
sScriptMgr->OnPacketSend(this, WorldPacket(pct));
Flexi::ServerPktHeader header(pct.size()+2, pct.GetOpcode());
m_Crypt.EncryptSend ((uint8*)header.header, header.getHeaderLength());
if (m_OutBuffer->space() >= pct.size() + header.getHeaderLength() && msg_queue()->is_empty())
{
// Put the packet on the buffer.
if (m_OutBuffer->copy((char*) header.header, header.getHeaderLength()) == -1)
ACE_ASSERT (false);
if (!pct.empty())
if (m_OutBuffer->copy((char*) pct.contents(), pct.size()) == -1)
ACE_ASSERT (false);
}
else
{
// Enqueue the packet.
ACE_Message_Block* mb;
ACE_NEW_RETURN(mb, ACE_Message_Block(pct.size() + header.getHeaderLength()), -1);
mb->copy((char*) header.header, header.getHeaderLength());
if (!pct.empty())
mb->copy((const char*)pct.contents(), pct.size());
if (msg_queue()->enqueue_tail(mb, (ACE_Time_Value*)&ACE_Time_Value::zero) == -1)
{
sLog->outError("WorldSocket::SendPacket enqueue_tail failed");
mb->release();
return -1;
}
}
return 0;
}
示例5: 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;
}
示例6:
int
PSession::initiate_write (u_long offset_low, u_long offset_high,
const char * data,
size_t len)
{
ACE_Message_Block *mb = 0;
u_int blksize = this->config().s_blksize();
if (blksize < len)
{
blksize=len;
}
ACE_NEW_RETURN (mb,
ACE_Message_Block (blksize),
-1);
if (mb == 0)
{
this->do_cancel ();
return -1;
}
mb->reset ();
mb->copy (data, len);
//mb->wr_ptr (mb->space());
return this->initiate_write (offset_low, offset_high, *mb);
}
示例7: handle_input
// Implement its handle_input() hook method to perform the "Half-Async"
int Echo_Svc_Handler::handle_input(ACE_HANDLE)
{
ACE_DEBUG((LM_DEBUG,
"(%t) Echo_Svc_Handler::handle_input\n"));
// Reads the client data [ACE_SOCK_Stream] until the end of a line is reached
char buf[ACE_DEFAULT_MAX_SOCKET_BUFSIZ];
ssize_t recv_cnt;
recv_cnt = this->peer().recv(buf, sizeof(buf));
if (recv_cnt <= 0) {
ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t) connection closed \n")));
return -1;
}
// Puts the client data into a message [ACE_Message_Block]
ACE_Message_Block *mb = 0;
ACE_NEW_RETURN(mb,
ACE_Message_Block(recv_cnt),
-1);
mb->copy(buf, recv_cnt);
// Calls Echo_Task::put(), which uses ACE_Task::putq() to enqueue the message
// for subsequent processing by a thread in the pool of threads that are running
// the Echo_Task::svc() hook method.
echo_task_->putq(mb);
return 0;
}
示例8: svc
virtual int svc ()
{
//int i =0;
ACE_Message_Block *mblk;
int len = 0;
while(!fin.eof())
{
fin.getline(file_buf, LineSize);
len = ACE_OS::strlen( file_buf );
ACE_NEW_RETURN (mblk, ACE_Message_Block (len+200), 0);
if (file_buf[len-1] == '\r')
{
len = len - 1;
}
mblk->copy (file_buf, len+1 );
// 通过put_next函数,将消息传递给下一个过滤器
put_next (mblk);
}
ACE_NEW_RETURN(mblk, ACE_Message_Block (0, ACE_Message_Block::MB_STOP), 0);
put_next (mblk);
fin.close();
ACE_DEBUG ((LM_DEBUG, "read svc return .\n"));
return 0;
}
示例9:
/*****************************************************************************
Function: sendEsRtpPacket
Description:
Input: pRtpData 解析成ES流后的一包数据
unDataSize ES流的一包数据的长度
Output:
Return: N/A
*****************************************************************************/
void CPs2EsProcessor::sendEsRtpPacket(const char* pRtpData, unsigned int unDataSize)
{
//CHECK_POINTER_VOID(pRtpData);
if (0 == unDataSize)
{
//BP_RUN_LOG_ERR(IVS_FAIL, "Send Es rtp packet fail, data size invalid", "size=%u, serviceID=%s.", unDataSize, m_strServiceID.c_str());
return;
}
ACE_Message_Block *pRtpBlock = CMediaBlockBuffer::instance().allocMediaBlock();
if (NULL == pRtpBlock)
{
//BP_RUN_LOG_ERR(IVS_ALLOC_MEMORY_ERROR, "Alloc media block fail.", "serviceID=%s.", m_strServiceID.c_str());
return;
}
NALU_HEADER naluheader = *(NALU_HEADER*)pRtpBlock->rd_ptr();
pRtpBlock->reset();
pRtpBlock->copy(pRtpData, unDataSize);
ST_FRAME_DATA frameData;
frameData.iFrameDataType = naluheader.TYPE;
frameData.iStreamType = _PAY_LOAD_TYPE_H264;
//m_Mutex.Lock();
if(NULL != m_fDataCallBack)
{
m_fDataCallBack(m_pUser, pRtpBlock,&frameData);
}
//m_Mutex.UnLock();
CMediaBlockBuffer::instance().freeMediaBlock(pRtpBlock);
return;
}
示例10: sizeof
static void *
connector (void *)
{
ACE_UPIPE_Stream c_stream;
ACE_OS::sleep (5);
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) connector starting connect\n")));
ACE_UPIPE_Connector con;
if (con.connect (c_stream, addr) == -1)
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) connector ACE_UPIPE_Connector failed\n")));
ACE_Message_Block *mb = 0;
ACE_NEW_RETURN (mb, ACE_Message_Block (sizeof ("hello thanks") * sizeof (char)), 0);
mb->copy ("hello");
if (c_stream.send (mb) == -1)
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) error connector send\n")));
if (c_stream.recv (mb) == -1)
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) error connector recv\n")));
ACE_TEST_ASSERT (ACE_OS::strcmp (mb->rd_ptr (), "thanks") == 0);
// Free up the memory block.
mb->release ();
// Now try the send()/recv() interface.
char mytext[] = "This string is sent by connector as a buffer";
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) connector sending text\n")));
if (c_stream.send (mytext, sizeof (mytext)) == -1)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) buffer send from connector failed\n")));
char conbuf[BUFSIZ]; // Buffer to receive response.
int i = 0;
for (char c = ' '; c != '!'; i++)
{
if (c_stream.recv (&c, 1) == -1)
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) buffer recv from connector failed\n")));
else
conbuf[i] = c;
}
conbuf[i] = '\0';
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) conbuf = %s\n"), conbuf));
ACE_TEST_ASSERT (ACE_OS::strcmp (conbuf, "this is the acceptor response!") == 0);
c_stream.close ();
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) exiting thread\n")));
return 0;
}
示例11: acc
static void *
peer2 (void *)
{
ACE_UPIPE_Acceptor acc (addr);
ACE_UPIPE_Stream s_stream;
// Spawn a peer1 thread.
if (ACE_Thread_Manager::instance ()->spawn (ACE_THR_FUNC (peer1),
(void *) 0,
THR_NEW_LWP | THR_DETACHED) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"spawn"),
0);
ACE_DEBUG ((LM_DEBUG,
"(%t) peer2 starting accept\n"));
if (acc.accept (s_stream) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) ACE_UPIPE_Acceptor.accept failed\n"));
ACE_Message_Block *mb = 0;
if (s_stream.recv (mb) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) peer2 recv failed\n"));
ACE_DEBUG ((LM_DEBUG, "(%t) peer2 recv is \"%s\"\n",
mb->rd_ptr ()));
mb->wr_ptr (mb->rd_ptr ());
mb->copy ("thanks", 7);
if (s_stream.send (mb) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) peer2 send failed\n"));
char s_buf[42];
ACE_DEBUG ((LM_DEBUG,
"(%t) peer2 sleeping on recv\n"));
if (s_stream.recv (s_buf, sizeof s_buf) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) peer2 recv failed\n"));
else
ACE_DEBUG ((LM_DEBUG,
"(%t) peer2 received buffer with \"%s\"\n",
s_buf));
ACE_OS::strcpy (s_buf,
"this is the peer2 response!");
if (s_stream.send (s_buf, 30) == -1)
ACE_ERROR ((LM_ERROR,
"(%t) peer2 send failed\n"));
s_stream.close ();
return 0;
}
示例12: QueuePacket
int PacketQueue::QueuePacket(FieldPacket* packet)
{
ACE_Message_Block* mb;
ACE_NEW_RETURN(mb, ACE_Message_Block(sizeof(packet)), -1);
mb->copy((const char*)&packet, sizeof(packet));
ACE_Time_Value tv;
return this->enqueue(mb, &tv);
}
示例13: handle_input
// Called when input is available from the client
//
// We can handle requests until the peer closes on, potentially, many connections simultaneously.
// We do this asynchronously, acoiding blocking I/O operations which are bad because they block all connection processing.
//
int ClientService::handle_input(ACE_HANDLE fileDescriptor)
{
const size_t inputSize = 4096;
char buffer[inputSize];
ssize_t receivedBytes;
ssize_t sentBytes;
if ((receivedBytes = m_socket.recv(buffer, sizeof(buffer))) <= 0)
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Connection closed\n")));
return -1;
}
sentBytes = m_socket.send(buffer, static_cast<size_t>(receivedBytes));
if (sentBytes == receivedBytes)
{
return 0;
}
if (sentBytes == -1 && ACE_OS::last_error() != EWOULDBLOCK)
{
ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) %p\n"), ACE_TEXT("send")), 0);
}
if (sentBytes == -1)
{
sentBytes = 0;
}
//
ACE_Message_Block* message;
size_t remaining = static_cast<size_t>(receivedBytes - sentBytes);
ACE_NEW_RETURN(message, ACE_Message_Block(remaining), -1);
message->copy(&buffer[sentBytes], remaining);
bool isEmpty = m_queue.is_empty();
ACE_Time_Value nowait(ACE_OS::gettimeofday());
if (m_queue.enqueue_tail(message, &nowait) == -1)
{
ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) %p; discarding data\n"), ACE_TEXT("enqueue failed")));
message->release();
return 0;
}
if (isEmpty)
{
return this->reactor()->register_handler(this, ACE_Event_Handler::WRITE_MASK);
}
return 0;
}
示例14:
void
HTTP_Client_Connection::on_open(ACE_Message_Block& mb)
{
std::string request = "GET / HTTP/1.1\r\n" \
"Host: localhost\r\n" \
"\r\n";
mb.copy(request.c_str(), request.size());
this->write(mb);
}
示例15: BuildCmd
// 直接传入拼装完成的内容部分,组成CMD,传递文件使用
CCmd* CNSSOperator::BuildCmd(const std::string& strLinkID, int iNetElementType, unsigned short iReqID, const char* pData, int length) const
{
CCmd* pCmd = NULL;
HW_NEW(pCmd, CCmd); //lint !e774
CHECK_POINTER(pCmd, NULL);
pCmd->SetNetElemType(iNetElementType);
pCmd->SetNetLinkID(strLinkID);
pCmd->SetServiceID(SERVICE_COMMU);
pCmd->SetReqID(iReqID);
pCmd->SetCmdType(CMD_SEND);
// 生成事务ID
std::string strTransID = CMKTransID::Instance().GenerateTransID();
pCmd->SetTransID(strTransID);
// NSS头
TNssMsgHeader m_header;
memset(&m_header, 0, sizeof(TNssMsgHeader));
m_header.usiProtocolVersion = 0x0100;
m_header.usiMsgType = iReqID;
m_header.uiSeqID = 0;
m_header.uiTraceID = 0;
strncpy(m_header.szTransactionNo, strTransID.c_str(), MaxTransactionNoLength - 1);
m_header.uiRspCode = 0;
m_header.uiPacketLength = sizeof(TNssMsgHeader) + static_cast<IVS_UINT32>(length);
// 转换网络字节序
m_header.usiProtocolVersion = ntohs(m_header.usiProtocolVersion);
m_header.usiMsgType = ntohs(m_header.usiMsgType);
m_header.uiSeqID = ntohl(m_header.uiSeqID);
m_header.uiTraceID = ntohl(m_header.uiTraceID);
m_header.uiRspCode = ntohl(m_header.uiRspCode);
m_header.uiPacketLength = ntohl(m_header.uiPacketLength);
// 定义ACE的消息缓冲,这个在cmd里面去释放,这里不释放
ACE_Message_Block* pMsgBlock = new ACE_Message_Block(sizeof(TNssMsgHeader) + static_cast<IVS_UINT32>(length)); //lint !e429
pMsgBlock->copy((char*)&m_header, sizeof(TNssMsgHeader));
pMsgBlock->copy(pData, static_cast<IVS_UINT32>(length));
// 设置数据到CMD,数据应该由CMD统一释放掉
pCmd->SetMsgBlock(pMsgBlock);//lint !e613
return pCmd;//lint !e429
}