Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Fix uninitialized max_bytes var
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffail committed Apr 5, 2017
1 parent 1a8657d commit d4eabcc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SET (APPLICATION_CODENAME "${PROJECT_NAME}")
SET (APPLICATION_COPYRIGHT_YEARS "2014")
SET (APPLICATION_VERSION_MAJOR 1)
SET (APPLICATION_VERSION_MINOR 4)
SET (APPLICATION_VERSION_PATCH 2)
SET (APPLICATION_VERSION_PATCH 3)
SET (APPLICATION_VERSION_TYPE DS1)
SET (APPLICATION_VERSION_STRING "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}-${APPLICATION_VERSION_TYPE}")
SET (APPLICATION_VENDOR_ID "com.datasift")
Expand Down
31 changes: 9 additions & 22 deletions src/served/net/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ connection::connection( boost::asio::io_service & io_service
, _connection_manager(manager)
, _request_handler(handler)
, _request()
, _max_req_size_bytes(_max_req_size_bytes)
, _request_parser(new request_parser_impl(_request, _max_req_size_bytes))
, _max_req_size_bytes(max_req_size_bytes)
, _request_parser(_request, _max_req_size_bytes)
, _read_timeout(read_timeout)
, _write_timeout(write_timeout)
, _read_timer(_io_service, boost::posix_time::milliseconds(read_timeout))
Expand Down Expand Up @@ -79,24 +79,9 @@ connection::start()
}
}

void
connection::restart()
{
_status = status_type::READING;

_request.clear();
_request_parser.reset(new request_parser_impl(_request, _max_req_size_bytes));
_response.clear();

start();
}

void
connection::stop()
{
boost::system::error_code ignored_ec;
_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both,
ignored_ec);
_socket.close();
}

Expand All @@ -110,7 +95,7 @@ connection::do_read()
if (!ec)
{
request_parser_impl::status_type result;
result = _request_parser->parse(_buffer.data(), bytes_transferred);
result = _request_parser.parse(_buffer.data(), bytes_transferred);

if ( request_parser_impl::FINISHED == result )
{
Expand Down Expand Up @@ -207,15 +192,17 @@ connection::do_write()
{
// If we're still reading from the client then continue
do_read();
return;
}
else
{
// Otherwise we initiate a parser recycle.
_write_timer.cancel();
restart();
// Initiate graceful connection closure.
boost::system::error_code ignored_ec;
_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
}
}
else if ( ec != boost::asio::error::operation_aborted )

if ( ec != boost::asio::error::operation_aborted )
{
_connection_manager.stop(shared_from_this());
}
Expand Down
9 changes: 5 additions & 4 deletions src/served/net/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class connection_manager;
class connection
: public std::enable_shared_from_this<connection>
{
typedef std::shared_ptr<request_parser_impl> parser_ptr;
public:
enum status_type { READING = 0, DONE };

Expand All @@ -56,17 +55,19 @@ class connection
connection_manager & _connection_manager;
multiplexer & _request_handler;
std::array<char, 8192> _buffer;
request _request;
parser_ptr _request_parser;
response _response;
size_t _max_req_size_bytes;
int _read_timeout;
int _write_timeout;
request _request;
request_parser_impl _request_parser;
response _response;
boost::asio::deadline_timer _read_timer;
boost::asio::deadline_timer _write_timer;

public:
connection& operator=(const connection&) = delete;
connection() = delete;
connection(const connection&) = delete;

/*
* Constructs a new connection.
Expand Down

0 comments on commit d4eabcc

Please sign in to comment.