use std::tuple to return multiple return values, hope for copy elision. Also, removes two cases of parameter reassignment
This commit is contained in:
parent
fb3bc22c64
commit
9dfe6d1e85
@ -67,9 +67,8 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
|||||||
// no error detected, let's parse the request
|
// no error detected, let's parse the request
|
||||||
CompressionType compression_type(noCompression);
|
CompressionType compression_type(noCompression);
|
||||||
osrm::tribool result;
|
osrm::tribool result;
|
||||||
std::tie(result, std::ignore) =
|
std::tie(result, compression_type) = RequestParser().Parse(
|
||||||
RequestParser().Parse(request, incoming_data_buffer.data(),
|
request, incoming_data_buffer.data(), incoming_data_buffer.data() + bytes_transferred);
|
||||||
incoming_data_buffer.data() + bytes_transferred, compression_type);
|
|
||||||
|
|
||||||
// the request has been parsed
|
// the request has been parsed
|
||||||
if (result == osrm::tribool::yes)
|
if (result == osrm::tribool::yes)
|
||||||
|
@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#ifndef CONNECTION_H
|
#ifndef CONNECTION_H
|
||||||
#define CONNECTION_H
|
#define CONNECTION_H
|
||||||
|
|
||||||
// #include "RequestParser.h"
|
|
||||||
#include "Http/CompressionType.h"
|
#include "Http/CompressionType.h"
|
||||||
#include "Http/Reply.h"
|
#include "Http/Reply.h"
|
||||||
#include "Http/Request.h"
|
#include "Http/Request.h"
|
||||||
@ -38,30 +37,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <boost/version.hpp>
|
#include <boost/version.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
//workaround for incomplete std::shared_ptr compatibility in old boost versions
|
// workaround for incomplete std::shared_ptr compatibility in old boost versions
|
||||||
#if BOOST_VERSION < 105300 || defined BOOST_NO_CXX11_SMART_PTR
|
#if BOOST_VERSION < 105300 || defined BOOST_NO_CXX11_SMART_PTR
|
||||||
|
|
||||||
namespace boost {
|
namespace boost
|
||||||
template<class T>
|
|
||||||
const T* get_pointer(std::shared_ptr<T> const& p)
|
|
||||||
{
|
{
|
||||||
return p.get();
|
template <class T> const T *get_pointer(std::shared_ptr<T> const &p) { return p.get(); }
|
||||||
}
|
|
||||||
|
|
||||||
template<class T>
|
template <class T> T *get_pointer(std::shared_ptr<T> &p) { return p.get(); }
|
||||||
T* get_pointer(std::shared_ptr<T>& p)
|
|
||||||
{
|
|
||||||
return p.get();
|
|
||||||
}
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RequestHandler;
|
class RequestHandler;
|
||||||
|
|
||||||
namespace http
|
namespace http
|
||||||
|
@ -36,23 +36,22 @@ RequestParser::RequestParser() : state_(method_start), header({"", ""}) {}
|
|||||||
|
|
||||||
void RequestParser::Reset() { state_ = method_start; }
|
void RequestParser::Reset() { state_ = method_start; }
|
||||||
|
|
||||||
std::tuple<osrm::tribool, char *>
|
std::tuple<osrm::tribool, CompressionType>
|
||||||
RequestParser::Parse(Request &req, char *begin, char *end, http::CompressionType &compression_type)
|
RequestParser::Parse(Request &req, char *begin, char *end)
|
||||||
{
|
{
|
||||||
while (begin != end)
|
while (begin != end)
|
||||||
{
|
{
|
||||||
osrm::tribool result = consume(req, *begin++, compression_type);
|
osrm::tribool result = consume(req, *begin++);
|
||||||
if (result == osrm::tribool::yes || result == osrm::tribool::no)
|
if (result == osrm::tribool::yes || result == osrm::tribool::no)
|
||||||
{
|
{
|
||||||
return std::make_tuple(result, begin);
|
return std::make_tuple(result, compression_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
osrm::tribool result = osrm::tribool::indeterminate;
|
osrm::tribool result = osrm::tribool::indeterminate;
|
||||||
return std::make_tuple(result, begin);
|
return std::make_tuple(result, compression_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
osrm::tribool
|
osrm::tribool RequestParser::consume(Request &req, char input)
|
||||||
RequestParser::consume(Request &req, char input, http::CompressionType &compression_type)
|
|
||||||
{
|
{
|
||||||
switch (state_)
|
switch (state_)
|
||||||
{
|
{
|
||||||
|
@ -48,11 +48,10 @@ class RequestParser
|
|||||||
RequestParser();
|
RequestParser();
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
std::tuple<osrm::tribool, char *>
|
std::tuple<osrm::tribool, CompressionType> Parse(Request &req, char *begin, char *end);
|
||||||
Parse(Request &req, char *begin, char *end, CompressionType &compression_type);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
osrm::tribool consume(Request &req, char input, CompressionType &compression_type);
|
osrm::tribool consume(Request &req, char input);
|
||||||
|
|
||||||
inline bool isChar(int c);
|
inline bool isChar(int c);
|
||||||
|
|
||||||
@ -88,6 +87,7 @@ class RequestParser
|
|||||||
} state_;
|
} state_;
|
||||||
|
|
||||||
Header header;
|
Header header;
|
||||||
|
CompressionType compression_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace http
|
} // namespace http
|
||||||
|
Loading…
Reference in New Issue
Block a user