reduce compile time by using fwd decls
This commit is contained in:
parent
de790c7c19
commit
8c4c1a56fd
@ -26,6 +26,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "BaseParser.h"
|
||||
#include "ExtractorStructs.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
BaseParser::BaseParser(ExtractorCallbacks* ec, ScriptingEnvironment& se) :
|
||||
extractor_callbacks(ec), scriptingEnvironment(se), luaState(NULL), use_turn_restrictions(true) {
|
||||
|
@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef BASEPARSER_H_
|
||||
#define BASEPARSER_H_
|
||||
|
||||
#include "ExtractorCallbacks.h"
|
||||
// #include "ExtractorCallbacks.h"
|
||||
#include "ScriptingEnvironment.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
@ -41,6 +41,10 @@ extern "C" {
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
class ExtractorCallbacks;
|
||||
struct ExtractionWay;
|
||||
struct ImportNode;
|
||||
|
||||
class BaseParser : boost::noncopyable {
|
||||
public:
|
||||
BaseParser(ExtractorCallbacks* ec, ScriptingEnvironment& se);
|
||||
|
@ -25,8 +25,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "ExtractionContainers.h"
|
||||
#include "ExtractionHelperFunctions.h"
|
||||
#include "ExtractorCallbacks.h"
|
||||
|
||||
#include "../DataStructures/Coordinate.h"
|
||||
|
||||
#include <cfloat>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/regex.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
ExtractorCallbacks::ExtractorCallbacks() {externalMemory = NULL; stringMap = NULL; }
|
||||
ExtractorCallbacks::ExtractorCallbacks(ExtractionContainers * ext, StringMap * strMap) {
|
||||
externalMemory = ext;
|
||||
|
@ -28,20 +28,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef EXTRACTORCALLBACKS_H_
|
||||
#define EXTRACTORCALLBACKS_H_
|
||||
|
||||
#include "ExtractionContainers.h"
|
||||
#include "ExtractionHelperFunctions.h"
|
||||
#include "ExtractorStructs.h"
|
||||
|
||||
#include "../DataStructures/Coordinate.h"
|
||||
|
||||
#include <cfloat>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/regex.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
class ExtractionContainers;
|
||||
|
||||
class ExtractorCallbacks{
|
||||
private:
|
||||
|
@ -25,7 +25,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "ExtractorCallbacks.h"
|
||||
#include "ExtractorStructs.h"
|
||||
#include "PBFParser.h"
|
||||
#include "../DataStructures/Coordinate.h"
|
||||
#include "../DataStructures/HashTable.h"
|
||||
#include "../Util/MachineInfo.h"
|
||||
#include "../Util/OpenMPWrapper.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
PBFParser::PBFParser(const char * fileName, ExtractorCallbacks* ec, ScriptingEnvironment& se) : BaseParser( ec, se ) {
|
||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
||||
|
@ -29,24 +29,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#define PBFPARSER_H_
|
||||
|
||||
#include "BaseParser.h"
|
||||
|
||||
#include "../DataStructures/Coordinate.h"
|
||||
#include "../DataStructures/HashTable.h"
|
||||
#include "../DataStructures/ConcurrentQueue.h"
|
||||
#include "../Util/MachineInfo.h"
|
||||
#include "../Util/OpenMPWrapper.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
#include <osmpbf/fileformat.pb.h>
|
||||
#include <osmpbf/osmformat.pb.h>
|
||||
|
||||
#include <zlib.h>
|
||||
#include <fstream>
|
||||
|
||||
class PBFParser : public BaseParser {
|
||||
|
||||
@ -73,7 +63,11 @@ class PBFParser : public BaseParser {
|
||||
};
|
||||
|
||||
public:
|
||||
PBFParser(const char * fileName, ExtractorCallbacks* ec, ScriptingEnvironment& se);
|
||||
PBFParser(
|
||||
const char * fileName,
|
||||
ExtractorCallbacks* ec,
|
||||
ScriptingEnvironment& se
|
||||
);
|
||||
virtual ~PBFParser();
|
||||
|
||||
inline bool ReadHeader();
|
||||
|
@ -25,7 +25,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "ExtractionHelperFunctions.h"
|
||||
#include "ExtractorStructs.h"
|
||||
#include "ScriptingEnvironment.h"
|
||||
#include "../DataStructures/ImportNode.h"
|
||||
#include "../Util/OpenMPWrapper.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
ScriptingEnvironment::ScriptingEnvironment() {}
|
||||
ScriptingEnvironment::ScriptingEnvironment(const char * fileName) {
|
||||
|
@ -28,14 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef SCRIPTINGENVIRONMENT_H_
|
||||
#define SCRIPTINGENVIRONMENT_H_
|
||||
|
||||
#include "ExtractionHelperFunctions.h"
|
||||
#include "ExtractorStructs.h"
|
||||
#include "../DataStructures/ImportNode.h"
|
||||
#include "../Util/LuaUtil.h"
|
||||
#include "../Util/OpenMPWrapper.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -30,6 +30,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "ExtractorStructs.h"
|
||||
#include "../DataStructures/HashTable.h"
|
||||
#include "../DataStructures/InputReaderFactory.h"
|
||||
#include "../DataStructures/Coordinate.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../Util/StringUtil.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
|
@ -28,18 +28,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef XMLPARSER_H_
|
||||
#define XMLPARSER_H_
|
||||
|
||||
#include "ExtractorCallbacks.h"
|
||||
#include "BaseParser.h"
|
||||
#include "../DataStructures/Coordinate.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../Util/StringUtil.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <libxml/xmlreader.h>
|
||||
|
||||
|
||||
class XMLParser : public BaseParser {
|
||||
public:
|
||||
XMLParser(const char* filename, ExtractorCallbacks* ec, ScriptingEnvironment& se);
|
||||
XMLParser(
|
||||
const char* filename,
|
||||
ExtractorCallbacks* ec,
|
||||
ScriptingEnvironment& se
|
||||
);
|
||||
bool ReadHeader();
|
||||
bool Parse();
|
||||
|
||||
|
237
Server/Connection.cpp
Normal file
237
Server/Connection.cpp
Normal file
@ -0,0 +1,237 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "Connection.h"
|
||||
#include "RequestHandler.h"
|
||||
#include "RequestParser.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/iostreams/filtering_stream.hpp>
|
||||
#include <boost/iostreams/filter/gzip.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace http {
|
||||
|
||||
Connection::Connection(
|
||||
boost::asio::io_service& io_service,
|
||||
RequestHandler& handler
|
||||
) :
|
||||
strand(io_service),
|
||||
TCP_socket(io_service),
|
||||
request_handler(handler),
|
||||
request_parser(new RequestParser())
|
||||
{ }
|
||||
|
||||
Connection::~Connection() {
|
||||
delete request_parser;
|
||||
}
|
||||
|
||||
boost::asio::ip::tcp::socket& Connection::socket() {
|
||||
return TCP_socket;
|
||||
}
|
||||
|
||||
/// Start the first asynchronous operation for the connection.
|
||||
void Connection::start() {
|
||||
TCP_socket.async_read_some(
|
||||
boost::asio::buffer(incoming_data_buffer),
|
||||
strand.wrap( boost::bind(
|
||||
&Connection::handle_read,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void Connection::handle_read(
|
||||
const boost::system::error_code& e,
|
||||
std::size_t bytes_transferred
|
||||
) {
|
||||
if( !e ) {
|
||||
CompressionType compression_type(noCompression);
|
||||
boost::tribool result;
|
||||
boost::tie(result, boost::tuples::ignore) = request_parser->Parse(
|
||||
request,
|
||||
incoming_data_buffer.data(),
|
||||
incoming_data_buffer.data() + bytes_transferred,
|
||||
&compression_type
|
||||
);
|
||||
|
||||
if( result ) {
|
||||
request.endpoint = TCP_socket.remote_endpoint().address();
|
||||
request_handler.handle_request(request, reply);
|
||||
|
||||
Header compression_header;
|
||||
std::vector<char> compressed_output;
|
||||
std::vector<boost::asio::const_buffer> output_buffer;
|
||||
switch(compression_type) {
|
||||
case deflateRFC1951:
|
||||
compression_header.name = "Content-Encoding";
|
||||
compression_header.value = "deflate";
|
||||
reply.headers.insert(
|
||||
reply.headers.begin(),
|
||||
compression_header
|
||||
);
|
||||
compressBufferCollection(
|
||||
reply.content,
|
||||
compression_type,
|
||||
compressed_output
|
||||
);
|
||||
reply.setSize(compressed_output.size());
|
||||
output_buffer = reply.HeaderstoBuffers();
|
||||
output_buffer.push_back(
|
||||
boost::asio::buffer(compressed_output)
|
||||
);
|
||||
boost::asio::async_write(
|
||||
TCP_socket,
|
||||
output_buffer,
|
||||
strand.wrap(
|
||||
boost::bind(
|
||||
&Connection::handle_write,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error
|
||||
)
|
||||
)
|
||||
);
|
||||
break;
|
||||
case gzipRFC1952:
|
||||
compression_header.name = "Content-Encoding";
|
||||
compression_header.value = "gzip";
|
||||
reply.headers.insert(
|
||||
reply.headers.begin(),
|
||||
compression_header
|
||||
);
|
||||
compressBufferCollection(
|
||||
reply.content,
|
||||
compression_type,
|
||||
compressed_output
|
||||
);
|
||||
reply.setSize(compressed_output.size());
|
||||
output_buffer = reply.HeaderstoBuffers();
|
||||
output_buffer.push_back(
|
||||
boost::asio::buffer(compressed_output)
|
||||
);
|
||||
boost::asio::async_write(
|
||||
TCP_socket,
|
||||
output_buffer,
|
||||
strand.wrap(
|
||||
boost::bind(
|
||||
&Connection::handle_write,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error
|
||||
)
|
||||
)
|
||||
);
|
||||
break;
|
||||
case noCompression:
|
||||
boost::asio::async_write(
|
||||
TCP_socket,
|
||||
reply.toBuffers(),
|
||||
strand.wrap(
|
||||
boost::bind(
|
||||
&Connection::handle_write,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error
|
||||
)
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
} else if (!result) {
|
||||
reply = Reply::StockReply(Reply::badRequest);
|
||||
boost::asio::async_write(
|
||||
TCP_socket,
|
||||
reply.toBuffers(),
|
||||
strand.wrap(
|
||||
boost::bind(
|
||||
&Connection::handle_write,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error
|
||||
)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
TCP_socket.async_read_some(
|
||||
boost::asio::buffer(incoming_data_buffer),
|
||||
strand.wrap(
|
||||
boost::bind(
|
||||
&Connection::handle_read,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle completion of a write operation.
|
||||
void Connection::handle_write(const boost::system::error_code& e) {
|
||||
if (!e) {
|
||||
// Initiate graceful connection closure.
|
||||
boost::system::error_code ignoredEC;
|
||||
TCP_socket.shutdown(
|
||||
boost::asio::ip::tcp::socket::shutdown_both,
|
||||
ignoredEC
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void Connection::compressBufferCollection(
|
||||
std::vector<std::string> uncompressed_data,
|
||||
CompressionType compression_type,
|
||||
std::vector<char> & compressed_data
|
||||
) {
|
||||
boost::iostreams::gzip_params compression_parameters;
|
||||
|
||||
compression_parameters.level = boost::iostreams::zlib::best_speed;
|
||||
if ( deflateRFC1951 == compression_type ) {
|
||||
compression_parameters.noheader = true;
|
||||
}
|
||||
|
||||
BOOST_ASSERT( compressed_data.empty() );
|
||||
boost::iostreams::filtering_ostream compressing_stream;
|
||||
|
||||
compressing_stream.push(
|
||||
boost::iostreams::gzip_compressor(compression_parameters)
|
||||
);
|
||||
compressing_stream.push(
|
||||
boost::iostreams::back_inserter(compressed_data)
|
||||
);
|
||||
|
||||
BOOST_FOREACH( const std::string & line, uncompressed_data) {
|
||||
compressing_stream << line;
|
||||
}
|
||||
|
||||
compressing_stream.reset();
|
||||
}
|
||||
}
|
@ -29,27 +29,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#define CONNECTION_H
|
||||
|
||||
#include "Http/CompressionType.h"
|
||||
#include "RequestHandler.h"
|
||||
#include "RequestParser.h"
|
||||
#include "Http/Reply.h"
|
||||
#include "Http/Request.h"
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/iostreams/filtering_stream.hpp>
|
||||
#include <boost/iostreams/filter/gzip.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
|
||||
// #include <zlib.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class RequestHandler;
|
||||
|
||||
namespace http {
|
||||
|
||||
class RequestParser;
|
||||
|
||||
/// Represents a single connection from a client.
|
||||
class Connection : public boost::enable_shared_from_this<Connection>,
|
||||
private boost::noncopyable {
|
||||
@ -57,262 +53,36 @@ public:
|
||||
explicit Connection(
|
||||
boost::asio::io_service& io_service,
|
||||
RequestHandler& handler
|
||||
) : strand(io_service), TCP_socket(io_service), request_handler(handler) { }
|
||||
);
|
||||
|
||||
boost::asio::ip::tcp::socket& socket() {
|
||||
return TCP_socket;
|
||||
}
|
||||
~Connection();
|
||||
|
||||
boost::asio::ip::tcp::socket& socket();
|
||||
|
||||
/// Start the first asynchronous operation for the connection.
|
||||
void start() {
|
||||
TCP_socket.async_read_some(
|
||||
boost::asio::buffer(incoming_data_buffer),
|
||||
strand.wrap( boost::bind(
|
||||
&Connection::handle_read,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred)
|
||||
)
|
||||
);
|
||||
}
|
||||
void start();
|
||||
|
||||
private:
|
||||
void handle_read(
|
||||
const boost::system::error_code& e,
|
||||
std::size_t bytes_transferred
|
||||
) {
|
||||
if( !e ) {
|
||||
CompressionType compression_type(noCompression);
|
||||
boost::tribool result;
|
||||
boost::tie(result, boost::tuples::ignore) = request_parser.Parse(
|
||||
request,
|
||||
incoming_data_buffer.data(),
|
||||
incoming_data_buffer.data() + bytes_transferred,
|
||||
&compression_type
|
||||
);
|
||||
|
||||
if( result ) {
|
||||
request.endpoint = TCP_socket.remote_endpoint().address();
|
||||
request_handler.handle_request(request, reply);
|
||||
|
||||
Header compression_header;
|
||||
std::vector<char> compressed_output;
|
||||
std::vector<boost::asio::const_buffer> output_buffer;
|
||||
switch(compression_type) {
|
||||
case deflateRFC1951:
|
||||
compression_header.name = "Content-Encoding";
|
||||
compression_header.value = "deflate";
|
||||
reply.headers.insert(
|
||||
reply.headers.begin(),
|
||||
compression_header
|
||||
);
|
||||
compressBufferCollection(
|
||||
reply.content,
|
||||
compression_type,
|
||||
compressed_output
|
||||
);
|
||||
reply.setSize(compressed_output.size());
|
||||
output_buffer = reply.HeaderstoBuffers();
|
||||
output_buffer.push_back(
|
||||
boost::asio::buffer(compressed_output)
|
||||
);
|
||||
boost::asio::async_write(
|
||||
TCP_socket,
|
||||
output_buffer,
|
||||
strand.wrap(
|
||||
boost::bind(
|
||||
&Connection::handle_write,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error
|
||||
)
|
||||
)
|
||||
);
|
||||
break;
|
||||
case gzipRFC1952:
|
||||
compression_header.name = "Content-Encoding";
|
||||
compression_header.value = "gzip";
|
||||
reply.headers.insert(
|
||||
reply.headers.begin(),
|
||||
compression_header
|
||||
);
|
||||
compressBufferCollection(
|
||||
reply.content,
|
||||
compression_type,
|
||||
compressed_output
|
||||
);
|
||||
reply.setSize(compressed_output.size());
|
||||
output_buffer = reply.HeaderstoBuffers();
|
||||
output_buffer.push_back(
|
||||
boost::asio::buffer(compressed_output)
|
||||
);
|
||||
boost::asio::async_write(
|
||||
TCP_socket,
|
||||
output_buffer,
|
||||
strand.wrap(
|
||||
boost::bind(
|
||||
&Connection::handle_write,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error
|
||||
)
|
||||
)
|
||||
);
|
||||
break;
|
||||
case noCompression:
|
||||
boost::asio::async_write(
|
||||
TCP_socket,
|
||||
reply.toBuffers(),
|
||||
strand.wrap(
|
||||
boost::bind(
|
||||
&Connection::handle_write,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error
|
||||
)
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
} else if (!result) {
|
||||
reply = Reply::StockReply(Reply::badRequest);
|
||||
boost::asio::async_write(
|
||||
TCP_socket,
|
||||
reply.toBuffers(),
|
||||
strand.wrap(
|
||||
boost::bind(
|
||||
&Connection::handle_write,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error
|
||||
)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
TCP_socket.async_read_some(
|
||||
boost::asio::buffer(incoming_data_buffer),
|
||||
strand.wrap(
|
||||
boost::bind(
|
||||
&Connection::handle_read,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/// Handle completion of a write operation.
|
||||
void handle_write(const boost::system::error_code& e) {
|
||||
if (!e) {
|
||||
// Initiate graceful connection closure.
|
||||
boost::system::error_code ignoredEC;
|
||||
TCP_socket.shutdown(
|
||||
boost::asio::ip::tcp::socket::shutdown_both,
|
||||
ignoredEC
|
||||
);
|
||||
}
|
||||
}
|
||||
void handle_write(const boost::system::error_code& e);
|
||||
|
||||
void compressBufferCollection(
|
||||
std::vector<std::string> uncompressed_data,
|
||||
CompressionType compression_type,
|
||||
std::vector<char> & compressed_data
|
||||
) {
|
||||
boost::iostreams::gzip_params compression_parameters;
|
||||
|
||||
compression_parameters.level = boost::iostreams::zlib::best_speed;
|
||||
if ( deflateRFC1951 == compression_type ) {
|
||||
compression_parameters.noheader = true;
|
||||
}
|
||||
|
||||
BOOST_ASSERT( compressed_data.empty() );
|
||||
boost::iostreams::filtering_ostream compressing_stream;
|
||||
|
||||
compressing_stream.push(
|
||||
boost::iostreams::gzip_compressor(compression_parameters)
|
||||
);
|
||||
compressing_stream.push(
|
||||
boost::iostreams::back_inserter(compressed_data)
|
||||
);
|
||||
|
||||
BOOST_FOREACH( const std::string & line, uncompressed_data) {
|
||||
compressing_stream << line;
|
||||
}
|
||||
|
||||
compressing_stream.reset();
|
||||
}
|
||||
|
||||
// Big thanks to deusty who explains how to use gzip compression by
|
||||
// the right call to deflateInit2():
|
||||
// http://deusty.blogspot.com/2007/07/gzip-compressiondecompression.html
|
||||
// void compressCharArray(
|
||||
// const char * in_data,
|
||||
// size_t in_data_size,
|
||||
// std::vector<unsigned char> & buffer,
|
||||
// CompressionType type
|
||||
// ) {
|
||||
// const size_t BUFSIZE = 128 * 1024;
|
||||
// unsigned char temp_buffer[BUFSIZE];
|
||||
|
||||
// z_stream strm;
|
||||
// strm.zalloc = Z_NULL;
|
||||
// strm.zfree = Z_NULL;
|
||||
// strm.opaque = Z_NULL;
|
||||
// strm.total_out = 0;
|
||||
// strm.next_in = (unsigned char *)(in_data);
|
||||
// strm.avail_in = in_data_size;
|
||||
// strm.next_out = temp_buffer;
|
||||
// strm.avail_out = BUFSIZE;
|
||||
// strm.data_type = Z_ASCII;
|
||||
|
||||
// switch(type){
|
||||
// case deflateRFC1951:
|
||||
// deflateInit(&strm, Z_BEST_SPEED);
|
||||
// break;
|
||||
// case gzipRFC1952:
|
||||
// deflateInit2(
|
||||
// &strm,
|
||||
// Z_DEFAULT_COMPRESSION,
|
||||
// Z_DEFLATED,
|
||||
// (15+16),
|
||||
// 9,
|
||||
// Z_DEFAULT_STRATEGY
|
||||
// );
|
||||
// break;
|
||||
// default:
|
||||
// BOOST_ASSERT_MSG(false, "should not happen");
|
||||
// break;
|
||||
// }
|
||||
|
||||
// int deflate_res = Z_OK;
|
||||
// do {
|
||||
// if ( 0 == strm.avail_out ) {
|
||||
// buffer.insert(buffer.end(), temp_buffer, temp_buffer + BUFSIZE);
|
||||
// strm.next_out = temp_buffer;
|
||||
// strm.avail_out = BUFSIZE;
|
||||
// }
|
||||
// deflate_res = deflate(&strm, Z_FINISH);
|
||||
|
||||
// } while (deflate_res == Z_OK);
|
||||
|
||||
// BOOST_ASSERT_MSG(
|
||||
// deflate_res == Z_STREAM_END,
|
||||
// "compression not properly finished"
|
||||
// );
|
||||
|
||||
// buffer.insert(
|
||||
// buffer.end(),
|
||||
// temp_buffer,
|
||||
// temp_buffer + BUFSIZE - strm.avail_out
|
||||
// );
|
||||
// deflateEnd(&strm);
|
||||
// }
|
||||
);
|
||||
|
||||
boost::asio::io_service::strand strand;
|
||||
boost::asio::ip::tcp::socket TCP_socket;
|
||||
RequestHandler& request_handler;
|
||||
boost::array<char, 8192> incoming_data_buffer;
|
||||
Request request;
|
||||
RequestParser request_parser;
|
||||
RequestParser * request_parser;
|
||||
Reply reply;
|
||||
};
|
||||
|
||||
|
@ -43,4 +43,3 @@ namespace http {
|
||||
}
|
||||
|
||||
#endif //HTTP_HEADER_H
|
||||
|
||||
|
@ -25,8 +25,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "APIGrammar.h"
|
||||
#include "RequestHandler.h"
|
||||
#include "DataStructures/RouteParameters.h"
|
||||
|
||||
#include "../Library/OSRM.h"
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../Util/StringUtil.h"
|
||||
#include "../typedefs.h"
|
||||
|
@ -28,16 +28,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef REQUEST_HANDLER_H
|
||||
#define REQUEST_HANDLER_H
|
||||
|
||||
#include "APIGrammar.h"
|
||||
#include "DataStructures/RouteParameters.h"
|
||||
#include "Http/Reply.h"
|
||||
#include "Http/Request.h"
|
||||
#include "../Library/OSRM.h"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
template <typename Iterator, class HandlerT>
|
||||
struct APIGrammar;
|
||||
struct RouteParameters;
|
||||
class OSRM;
|
||||
|
||||
class RequestHandler : private boost::noncopyable {
|
||||
|
||||
public:
|
||||
|
@ -25,6 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "Http/Request.h"
|
||||
#include "RequestParser.h"
|
||||
|
||||
namespace http {
|
||||
|
@ -30,13 +30,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "Http/CompressionType.h"
|
||||
#include "Http/Header.h"
|
||||
#include "Http/Request.h"
|
||||
|
||||
#include <boost/logic/tribool.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
namespace http {
|
||||
|
||||
struct Request;
|
||||
|
||||
class RequestParser {
|
||||
public:
|
||||
RequestParser();
|
||||
|
@ -31,7 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "Util/GitDescription.h"
|
||||
#include "Util/InputFileUtil.h"
|
||||
#include "Util/OpenMPWrapper.h"
|
||||
// #include "Util/OpenMPWrapper.h"
|
||||
#include "Util/ProgramOptions.h"
|
||||
#include "Util/SimpleLogger.h"
|
||||
#include "Util/UUID.h"
|
||||
|
Loading…
Reference in New Issue
Block a user