本文整理汇总了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());
}
}
示例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();
}
}
示例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
}
}
示例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());
}
示例5: defaultMessageCallback
void defaultMessageCallback(const TcpConnectionPtr& conn, ByteBuffer* buf, Timestamp receiveTime)
{
LOG_INFO("defaultMessageCallback : [%d][%s]", conn->fd(), buf->toString().c_str());
}
示例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));
}