本文整理汇总了C++中TCPConnection::disconnect_graceful方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPConnection::disconnect_graceful方法的具体用法?C++ TCPConnection::disconnect_graceful怎么用?C++ TCPConnection::disconnect_graceful使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPConnection
的用法示例。
在下文中一共展示了TCPConnection::disconnect_graceful方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connection_thread_main
void HTTPServer_Impl::connection_thread_main(TCPConnection connection)
{
try
{
std::string request;
bool bool_result = read_line(connection, request);
if (bool_result == false)
{
connection.disconnect_abortive();
return;
}
std::string headers;
bool_result = read_lines(connection, headers);
if (bool_result == false)
{
connection.disconnect_abortive();
return;
}
// Extract request command, url and version:
std::string command, url, version;
std::string::size_type pos1 = request.find(' ');
if (pos1 == std::string::npos)
throw Exception("Bad request");
command = request.substr(0, pos1);
if (command != "POST" && command != "GET")
throw Exception("Unsupported");
std::string::size_type pos2 = request.find(' ', pos1 + 1);
if (pos2 == std::string::npos)
throw Exception("Bad request");
url = request.substr(pos1+1, pos2-pos1-1);
std::string::size_type pos3 = request.find(' ', pos2 + 1);
if (pos3 != std::string::npos)
throw Exception("Bad request");
version = request.substr(pos2 + 1);
DataBuffer request_data;
// Handle request:
// Look for a request handler that will deal with the HTTP request:
MutexSection mutex_lock(&mutex);
std::vector<HTTPRequestHandler>::size_type index, size;
size = handlers.size();
bool handled = false;
for (index = 0; index < size; index++)
{
if (handlers[index].is_handling_request(command, url, headers))
{
HTTPRequestHandler handler = handlers[index];
mutex_lock.unlock();
if (command == "POST")
{
write_line(connection, "HTTP/1.1 100 Continue");
// write_line(connection, "Content-Length: 0");
write_line(connection, "");
}
std::shared_ptr<HTTPServerConnection_Impl> connection_impl(std::make_shared<HTTPServerConnection_Impl>());
connection_impl->connection = connection;
connection_impl->request_type = command;
connection_impl->request_url = url;
connection_impl->request_headers = headers;
HTTPServerConnection http_connection(connection_impl);
handler.handle_request(http_connection);
handled = true;
break;
}
}
mutex_lock.unlock();
if (!handled)
{
// No handler wants it. Reply with 404 Not Found:
std::string error_msg("404 Not Found");
write_line(connection, "HTTP/1.1 404 Not Found");
write_line(connection, "Server: ClanLib HTTP Server");
write_line(connection, "Connection: close");
write_line(connection, "Vary: *");
write_line(connection, "Content-Type: text/plain");
write_line(connection, "Content-Length: " + StringHelp::int_to_local8(error_msg.length()+2));
write_line(connection, "");
write_line(connection, error_msg);
}
connection.disconnect_graceful();
/*
if (url == "/")
{
File file("Sources/test.html", File::open_existing);
DataBuffer response(file.get_size());
file.read(response.get_data(), response.get_size(), true);
file.close();
// Send back response.
//.........这里部分代码省略.........