本文整理汇总了C++中TcpServer::sendMsg方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpServer::sendMsg方法的具体用法?C++ TcpServer::sendMsg怎么用?C++ TcpServer::sendMsg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpServer
的用法示例。
在下文中一共展示了TcpServer::sendMsg方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: iptoa
// returns false if blocked, true otherwise
bool Msg28::doSendLoop ( ) {
// only send once if we should
//if ( m_hostId >= 0 && m_numRequests >= MAX_OUT_MSG28 ) return true;
if ( m_hostId>=0 && m_numRequests>=1 && m_hostId2 == -1) return true;
// nothing to do if we sent a request to each host
//int32_t numHosts = g_hostdb.getNumHosts();
if ( m_numRequests >= m_sendTotal ) return true;
// send to ourselves last iff m_ourselvesLast is true
int32_t total = m_numHosts ;
if ( m_ourselvesLast ) total++;
// . now send it to all! allow up to 16 outstanding requests.
// . only allow 1 outstanding, and do ourselves last in case of
// save & exit...
for ( int32_t i = m_i ; i < total &&
m_numRequests - m_numReplies < MAX_OUT_MSG28 ; i++ ){
// skip it for next call, but stick to the last host, that's us
if ( i != m_numHosts ) m_i++;
// if we have a range and i is not in it, skip, but watch
// out when i==m_numHosts, because that is when we send the
// request to ourselves, provided we are in the range
if ( m_hostId >= 0 && m_hostId2 >= 0 && i < m_numHosts )
if ( i < m_hostId || i > m_hostId2 ) continue;
// do not send to ourselves until sent to others
if ( m_ourselvesLast && i == g_hostdb.m_hostId && i<m_numHosts)
continue;
// if we are now sending to ourselves, check to make sure
// all replies are back and we ourselves are in the docid range
// if one was given
if ( m_ourselvesLast && i == total-1 ) {
// and we must have gotten back all the replies...
// or at least error messages like ETIMEDOUT
if ( m_numReplies < m_sendTotal - 1 ) continue;
// and we must be in range, if one was given
if ( m_hostId >= 0 && m_hostId2 >= 0 ) {
if ( g_hostdb.m_hostId < m_hostId ) continue;
if ( g_hostdb.m_hostId > m_hostId2 ) continue;
}
}
// count it
m_numRequests++;
// get the ith host
Host *h = g_hostdb.getHost ( i );
if ( m_sendToProxy )
h = g_hostdb.getProxy(i);
// . if we are the "last i", that means us
// . we do ourselves last in case of a "save & exit" request
if ( i == m_numHosts ) {
h = g_hostdb.getHost(g_hostdb.m_hostId);
if (m_sendToProxy)
h = g_hostdb.getProxy(g_hostdb.m_hostId);
}
// did we have one explicitly given?
// ... and make sure we are not a range of hostids...
if ( m_hostId >= 0 && m_hostId2 == -1 ) {
h = g_hostdb.getHost (m_hostId);
if ( m_sendToProxy )
h = g_hostdb.getProxy ( m_hostId );
}
// debug
log(LOG_INIT,"admin: sending to hostid #%"INT32".",h->m_hostId);
// timeout is int16_ter if host is dead
int32_t timeout = 30000; // 30 seconds
// only 7 seconds if it is dead seemingly
if ( g_hostdb.isDead ( h ) ) timeout = 7000;
// continue;
// . launch it
// . returns false if blocked, true otherwise
// . sets g_errno on error
TcpServer *tcp = &g_httpServer.m_tcp;
if ( tcp->sendMsg ( h->m_ip ,
h->m_httpPort,
m_buf ,
m_bufSize ,
m_bufLen ,
m_bufLen ,
this , // state
gotReply ,
timeout , // 5000, timeout
100*1024 , // maxTextDocLen
100*1024 )){ // maxOtherDocLen
log("admin: Could not send configuration request "
"to hostId #%"INT32" (%s:%"INT32"): %s.",h->m_hostId,
iptoa(h->m_ip),(int32_t)h->m_port,mstrerror(g_errno));
g_errno = 0;//return true;
m_numReplies++;
}
// all done if only one host... and not a range
if ( m_hostId >= 0 && m_hostId2 == -1 ) break;
// it blocked
//return false;
}
// return false if we blocked
//if ( m_numReplies < m_numRequests ) return false;
// do not finish until we got them all
if ( m_numReplies < m_sendTotal ) return false;
return true;
}