本文整理汇总了C++中Transport::start方法的典型用法代码示例。如果您正苦于以下问题:C++ Transport::start方法的具体用法?C++ Transport::start怎么用?C++ Transport::start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transport
的用法示例。
在下文中一共展示了Transport::start方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: start
void EchoServer::start()
{
_transport.start();
EchoPacketFactory factory;
DefaultPacketStreamer streamer(&factory);
EchoServerAdapter serverAdapter;
IOComponent *ioc = _transport.listen(_spec, &streamer, &serverAdapter);
if (ioc == NULL) {
TBSYS_LOG(ERROR, "listen error.");
return;
}
_transport.wait();
}
示例2: testClose
void TCPCONNECTIONTF::testClose()
{
TCPServerAdapter adapter;
Transport *tranServer = new Transport;
char spec[] = "tcp:localhost:13345";
tranServer->start();
IOComponent *listener = tranServer->listen(spec, _streamer, &adapter);
CPPUNIT_ASSERT(listener);
//start client
Transport *tranClient = new Transport;
tranClient->start();
Connection *conn = tranClient->connect(spec, _streamer, false);
CPPUNIT_ASSERT(conn);
CPPUNIT_ASSERT(_conn->postPacket(new ConnPacket(31), _handler, NULL));
// the close() has not implement
ANET_LOG(SPAM,"Before Calling _conn->close();");
_conn->close();
ANET_LOG(SPAM,"After Calling _conn->close();");
CPPUNIT_ASSERT(_conn->isClosed());
ANET_LOG(SPAM,"After Assert(_conn->isClosed();");
tranClient->stop();
ANET_LOG(SPAM,"After Calling tranClient->stop();");
tranClient->wait();
ANET_LOG(SPAM,"After Calling tranClient->wait();");
tranServer->stop();
ANET_LOG(SPAM,"After Calling tran_server->stop();");
tranServer->wait();
ANET_LOG(SPAM,"After Calling tranClient->wait();");
delete tranClient;
delete tranServer;
listener->subRef();
conn->subRef();
}
示例3: start
void start(string addr){
cout<<"fake client start"<<endl;
trans.start();
CalPacketFactory packetFactory;
ClientPacketHandler handler(trans);
DefaultPacketStreamer ps(&packetFactory);
Connection* conns= trans.connect(addr.c_str(), &ps, true);
conns->setDefaultPacketHandler(&handler);
conns->setQueueLimit(500);
CalPacket *packet = new CalPacket(REQ);
uint32_t op1=1;
uint32_t op2=2;
packet->setOp(op1,op2);
cout<<"befor send:"<<"\n"
<<packet->toString()<<endl;
if(conns->postPacket(packet)){
cout<<"post ok"<<endl;
cout<<packet->toString()<<endl;
}else{
cout<<"post faile"<<endl;
}
trans.wait();
}
示例4: main
int main()
{
signal(SIGPIPE, sigHandler);
signal(SIGHUP, sigHandler);
Transport gClientTrans;
gClientTrans.start();
EchoServer server;
server.start();
for (int i = 0; i < 1; i++)
{
EchoClient* client = new EchoClient;
client->mClientTrans = &gClientTrans;
cout << "Round " << i << endl;
client->Run();
usleep(100000);
waitpid(-1, NULL, WNOHANG);
}
gClientTrans.stop();
gClientTrans.wait();
server.stop();
}
示例5: doProcess
void doProcess(unsigned int port, unsigned int num, CMClient& client)
{
Transport transport;
transport.start(); //using multithreads mode of anet
Thread *threads = new Thread[num];
RequestProcessor *runnables = new RequestProcessor [num];
assert(threads);
assert(runnables);
for (long i=0; i<num; i++) {
threads[i].start(runnables + i, (void*)&client);
}
HTTPPacketFactory factory;
HTTPStreamer streamer(&factory);
HTTPServerAdapter serverAdapter;
stringstream ss;
char hostname[1024];
if (gethostname(hostname, 1024) != 0) {
transport.stop();
transport.wait();
delete [] threads;
delete [] runnables;
exit(-1);
}
// ss << "tcp:" << hostname << ":" << port;
ss << "tcp:" << ":" << port;
string str = ss.str();
const char *spec = str.c_str();
IOComponent *ioc = transport.listen(spec, &streamer, &serverAdapter);
if (ioc == NULL) {
printf("create listen port error\n");
transport.stop();
transport.wait();
delete [] threads;
delete [] runnables;
return;
}
printf("webserver start ok\n");
while (!globalStopFlag) {
usleep(100000);
}
transport.stop();
transport.wait();
globalQueue._condition.lock();
while (globalQueue._queue.size()) {
HTTPRequestEntry entry = globalQueue._queue.front();
entry._packet->free();
entry._connection->subRef();
globalQueue._queue.pop();
}
globalQueue._condition.broadcast();
globalQueue._condition.unlock();
for (long i=0; i<num; i++) {
threads[i].join();
}
delete [] threads;
delete [] runnables;
}
示例6: main
int main(int argc, char *argv[]) {
if(2 > argc) {
printf("Less address!\n");
return 1;
}
Logger::logSetup();
Logger::setLogLevel(0);
char *address = argv[1];
char host[100] = {0};
char path[1024*1024] = {0};
char spec[200] = {0};
int port = -1;
sscanf(address, "http://%[-a-zA-Z0-9.]:%d%s", host, &port, path);
if(0 == host[0] || -1 == port) {
sscanf(address, "%[-a-zA-Z0-9.]:%d%s", host, &port, path);
}
if(0 == host[0] || -1 == port) {
port = 80;
sscanf(address, "http://%[-a-zA-Z0-9.]%s", host, path);
}
if(0 == host[0] || -1 == port) {
sscanf(address, "%[-a-zA-Z0-9.]%s", host, path);
}
if(0 == host[0] || -1 == port) {
printf("Wrong address!\n");
return 1;
}
if(0 == path[0]) {
path[0] = '/';
path[1] = 0;
}
sprintf(spec, "tcp:%s:%d", host, port);
Transport transport;
transport.start();
Connection *connection = NULL;
HTTPPacketFactory factory;
HTTPStreamer streamer(&factory);
connection = transport.connect(spec, &streamer);
if (NULL == connection) {
printf("Failed to connect server %s\n", spec);
exit(1);
}
HTTPPacket *requst = new HTTPPacket;
requst->setMethod(HTTPPacket::HM_GET);
requst->setURI(path);
requst->addHeader("Accept", "*/*");
requst->addHeader("Connection", "Keep-Alive");
requst->addHeader("Host", (const char*)(spec+4));
Packet *ret = connection->sendPacket(requst);
HTTPPacket *reply = NULL;
if (NULL != ret && ret->isRegularPacket()
&& (reply = dynamic_cast<HTTPPacket*>(ret)))
{
printf("------------reply from '%s' ----------\r\n", address);
printf("%s %d %s\r\n", reply->getVersion() ? "HTTP/1.1" : "HTTP/1.0",
reply->getStatusCode(), reply->getReasonPhrase());
for (HTTPPacket::ConstHeaderIterator it = reply->headerBegin();
it != reply->headerEnd(); it ++)
{
printf("%s: %s\r\n", it->first, it->second);
}
printf("\r\n");
if (reply->getBody()) {
fwrite(reply->getBody(), 1, reply->getBodyLen(), stdout);
}
printf("\n-----------end of reply-------------------\n");
} else {
printf("Fail to get reply from '%s' ----------\r\n", address);
ControlPacket *cmd = dynamic_cast<ControlPacket*>(ret);
if (cmd) {
printf("%s", cmd->what());
}
}
connection->subRef();
transport.stop();
transport.wait();
return 0;
}