本文整理汇总了C++中std::tr1::shared_ptr::cb方法的典型用法代码示例。如果您正苦于以下问题:C++ shared_ptr::cb方法的具体用法?C++ shared_ptr::cb怎么用?C++ shared_ptr::cb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::tr1::shared_ptr
的用法示例。
在下文中一共展示了shared_ptr::cb方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildStream
///gets called when a complete 24 byte header is actually received: uses the UUID within to match up appropriate sockets
void buildStream(TcpSstHeaderArray *buffer,
TCPSocket *socket,
std::tr1::shared_ptr<TCPStreamListener::Data> data,
const boost::system::error_code &error,
std::size_t bytes_transferred) {
if (error || std::memcmp(buffer->begin(),TCPStream::STRING_PREFIX(),TCPStream::STRING_PREFIX_LENGTH)!=0) {
SILOG(tcpsst,warning,"Connection received with incomprehensible header");
} else {
boost::asio::ip::tcp::no_delay option(data->mNoDelay);
socket->set_option(option);
UUID context=UUID(buffer->begin()+(TCPStream::TcpSstHeaderSize-16),16);
IncompleteStreamMap::iterator where=sIncompleteStreams.find(context);
unsigned int numConnections=(((*buffer)[TCPStream::STRING_PREFIX_LENGTH]-'0')%10)*10+(((*buffer)[TCPStream::STRING_PREFIX_LENGTH+1]-'0')%10);
if (numConnections>data->mMaxSimultaneousSockets) numConnections=data->mMaxSimultaneousSockets;
if (where==sIncompleteStreams.end()) {
sIncompleteStreams[context].mNumSockets=numConnections;
where=sIncompleteStreams.find(context);
assert(where!=sIncompleteStreams.end());
}
if ((int)numConnections!=where->second.mNumSockets) {
SILOG(tcpsst,warning,"Single client disagrees on number of connections to establish: "<<numConnections<<" != "<<where->second.mNumSockets);
sIncompleteStreams.erase(where);
} else {
where->second.mSockets.push_back(socket);
if (numConnections==(unsigned int)where->second.mSockets.size()) {
MultiplexedSocketPtr shared_socket(
MultiplexedSocket::construct<MultiplexedSocket>(&data->ios,context,where->second.mSockets,data->cb,data->mSendBufferSize));
MultiplexedSocket::sendAllProtocolHeaders(shared_socket,UUID::random());
sIncompleteStreams.erase(where);
Stream::StreamID newID=Stream::StreamID(1);
TCPStream * strm=new TCPStream(shared_socket,newID);
TCPSetCallbacks setCallbackFunctor(&*shared_socket,strm);
data->cb(strm,setCallbackFunctor);
if (setCallbackFunctor.mCallbacks==NULL) {
SILOG(tcpsst,error,"Client code for stream "<<newID.read()<<" did not set listener on socket");
shared_socket->closeStream(shared_socket,newID);
}
} else {
sStaleUUIDs.push_back(context);
}
}
}
delete buffer;
}
示例2: buildStream
//.........这里部分代码省略.........
delete socket;
return;
}
std::string head = line.substr(0, colon);
std::string val = line.substr(colon+2);
headers[head] = val;
// Advance to get past the \r\n
offset += 2;
}
if (headers.find("Host") == headers.end() ||
headers.find("Origin") == headers.end() ||
headers.find("Sec-WebSocket-Key1") == headers.end() ||
headers.find("Sec-WebSocket-Key2") == headers.end())
{
SILOG(tcpsst,warning,"Connection request didn't specify all required fields.");
delete socket;
return;
}
std::string host = headers["Host"];
std::string origin = headers["Origin"];
std::string protocol = "wssst1";
if (headers.find("Sec-WebSocket-Protocol") != headers.end())
protocol = headers["Sec-WebSocket-Protocol"];
std::string key1 = headers["Sec-WebSocket-Key1"];
std::string key2 = headers["Sec-WebSocket-Key2"];
std::string key3 = buffer_str.substr(bytes_transferred - 8);
assert(key3.size() == 8);
std::string reply_str = getWebSocketSecReply(key1, key2, key3);
bool binaryStream=protocol.find("sst")==0;
bool base64Stream=!binaryStream;
boost::asio::ip::tcp::no_delay option(data->mNoDelay);
socket->set_option(option);
IncompleteStreamMap::iterator where=sIncompleteStreams.find(context);
unsigned int numConnections=1;
for (std::string::iterator i=protocol.begin(),ie=protocol.end();i!=ie;++i) {
if (*i>='0'&&*i<='9') {
char* endptr=NULL;
const char *start=protocol.c_str();
size_t offset=(i-protocol.begin());
start+=offset;
numConnections=strtol(start,&endptr,10);
size_t numberlen=endptr-start;
if (numConnections>data->mMaxSimultaneousSockets) {
numConnections=data->mMaxSimultaneousSockets;
char numcon[256];
sprintf(numcon,"%d",numConnections);
protocol=protocol.substr(0,offset)+numcon+protocol.substr(offset+numberlen);
}
break;
}
}
if (where==sIncompleteStreams.end()){
sIncompleteStreams[context].mNumSockets=numConnections;
where=sIncompleteStreams.find(context);
assert(where!=sIncompleteStreams.end());
// Setup a timer to clean up the sockets if we don't complete it in time
data->strand->post(
Duration::seconds(10),
std::tr1::bind(&handleBuildStreamTimeout, context)
);
}
if ((int)numConnections!=where->second.mNumSockets) {
SILOG(tcpsst,warning,"Single client disagrees on number of connections to establish: "<<numConnections<<" != "<<where->second.mNumSockets);
sIncompleteStreams.erase(where);
}else {
where->second.mSockets.push_back(socket);
where->second.mWebSocketResponses[socket] = reply_str;
if (numConnections==(unsigned int)where->second.mSockets.size()) {
MultiplexedSocketPtr shared_socket(
MultiplexedSocket::construct<MultiplexedSocket>(data->strand,context,data->cb,base64Stream));
shared_socket->initFromSockets(where->second.mSockets,data->mSendBufferSize);
std::string port=shared_socket->getASIOSocketWrapper(0).getLocalEndpoint().getService();
std::string resource_name='/'+context.toString();
MultiplexedSocket::sendAllProtocolHeaders(shared_socket,origin,host,port,resource_name,protocol, where->second.mWebSocketResponses);
sIncompleteStreams.erase(where);
Stream::StreamID newID=Stream::StreamID(1);
TCPStream * strm=new TCPStream(shared_socket,newID);
TCPSetCallbacks setCallbackFunctor(&*shared_socket,strm);
data->cb(strm,setCallbackFunctor);
if (setCallbackFunctor.mCallbacks==NULL) {
SILOG(tcpsst,error,"Client code for stream "<<newID.read()<<" did not set listener on socket");
shared_socket->closeStream(shared_socket,newID);
}
}else{
sStaleUUIDs.push_back(context);
}
}
}