当前位置: 首页>>代码示例>>C++>>正文


C++ TcpConnectionPtr::fd方法代码示例

本文整理汇总了C++中TcpConnectionPtr::fd方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpConnectionPtr::fd方法的具体用法?C++ TcpConnectionPtr::fd怎么用?C++ TcpConnectionPtr::fd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TcpConnectionPtr的用法示例。


在下文中一共展示了TcpConnectionPtr::fd方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: onConnection

void HttpServer::onConnection(const TcpConnectionPtr& conn)
{
     LOG_INFO("HttpServer::onConnection get one client %d", conn->fd());
     if (conn->connected())
     {
         conn->setContext(HttpContext());
     }
}
开发者ID:lizhenghn123,项目名称:zl_reactor,代码行数:8,代码来源:HttpServer.cpp

示例2: response

void HttpServer::response(const TcpConnectionPtr& conn, const HttpRequest& req)
{
    const string& connection = req.getHeader("Connection");
    bool close = connection == "close" || (req.version() == HTTP_VERSION_1_0 && connection != "Keep-Alive");

    HttpResponse response(close);
    response.setStatusCode(HttpStatusOk);
    response.setServerName("MyHttpServer");

    methodCallback(req, &response);    // callback, for init response

    ByteBuffer buf;
    response.compileToBuffer(&buf);
    //printf("[%s]\n", buf.toString().c_str());
    conn->send(&buf);

    LOG_INFO("HttpServer::response send data [%d]", conn->fd());
    if (response.closeConnection())
    {
        LOG_INFO("HttpServer::response close this[%d]", conn->fd());
        conn->shutdown();
    }
}
开发者ID:lizhenghn123,项目名称:zl_reactor,代码行数:23,代码来源:HttpServer.cpp

示例3: onMessage

void HttpServer::onMessage(const TcpConnectionPtr& conn, ByteBuffer *buf, Timestamp receiveTime)
{
     LOG_INFO("HttpServer::onConnection recv data [%d][%s]", conn->fd(), buf->toString().c_str());

     HttpContext *context = zl::stl::any_cast<HttpContext>(conn->getMutableContext());
     assert(context);
     if(!context->parseRequest(buf, receiveTime))
     {
         conn->send("HTTP/1.1 400 Bad Request\r\n\r\n");
         conn->send("HTTP/1.1 400 Bad Request\r\n\r\n");
         conn->shutdown();
     }

     if (context->gotAll())
     {
         LOG_INFO("HttpServer::onMessage  parse request over.");
         response(conn, context->request());
         context->reset();  // process request and return response, then reset, for long-connection
     }
}
开发者ID:lizhenghn123,项目名称:zl_reactor,代码行数:20,代码来源:HttpServer.cpp

示例4: onMessage

 void onMessage(const TcpConnectionPtr& conn, ByteBuffer *buf, Timestamp time)
 {
     string msg(buf->retrieveAllAsString());
     printf("onMessage(): recv a message [%s]\n", msg.c_str());
     LOG_INFO("[%d] recv %d bytes at %s", conn->fd(), msg.size(), time.toString().c_str());
 }
开发者ID:lizhenghn123,项目名称:zl_reactor,代码行数:6,代码来源:TcpClient_test.cpp

示例5: defaultMessageCallback

void defaultMessageCallback(const TcpConnectionPtr& conn, ByteBuffer* buf, Timestamp receiveTime)
{
    LOG_INFO("defaultMessageCallback : [%d][%s]", conn->fd(), buf->toString().c_str());
}
开发者ID:YuuFish,项目名称:zl_reactor,代码行数:4,代码来源:TcpConnection.cpp

示例6: onMessage

	void SpcServer::onMessage(TcpConnectionPtr conn){
		string msg=conn->receive();
		cout << msg << endl;
		MyTask task(msg, conn->fd());
		_threadPool.addTask(std::bind(& MyTask::execute, task));
	}
开发者ID:gardness,项目名称:SpC_Framework,代码行数:6,代码来源:SpcServer.cpp


注:本文中的TcpConnectionPtr::fd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。