Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shutdown before close #347

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ crow_all.h

# conan.io
build/

.idea
cmake-build-debug
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ addons:
- g++-4.9
- g++-5
- clang-3.6
- libboost1.55-all-dev
- libboost-all-dev
- python-pip

install:
Expand Down
3 changes: 3 additions & 0 deletions include/crow/http_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ namespace crow
{
cancel_deadline_timer();
parser_.done();
adaptor_.shutdown_recv();
adaptor_.close();
is_reading = false;
CROW_LOG_DEBUG << this << " from read(1)";
Expand Down Expand Up @@ -520,6 +521,7 @@ namespace crow
{
if (close_connection_)
{
adaptor_.shutdown_send();
adaptor_.close();
CROW_LOG_DEBUG << this << " from write(1)";
check_destroy();
Expand Down Expand Up @@ -559,6 +561,7 @@ namespace crow
{
return;
}
adaptor_.shutdown_both();
adaptor_.close();
});
CROW_LOG_DEBUG << this << " timer added: " << timer_cancel_key_.first << ' ' << timer_cancel_key_.second;
Expand Down
36 changes: 36 additions & 0 deletions include/crow/socket_adaptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ namespace crow
socket_.close(ec);
}

void shutdown_both()
{
boost::system::error_code ec;
socket_.shutdown(boost::asio::socket_base::shutdown_type::shutdown_both, ec);
}

void shutdown_send()
{
boost::system::error_code ec;
socket_.shutdown(boost::asio::socket_base::shutdown_type::shutdown_send, ec);
}

void shutdown_recv()
{
boost::system::error_code ec;
socket_.shutdown(boost::asio::socket_base::shutdown_type::shutdown_receive, ec);
}

template <typename F>
void start(F f)
{
Expand Down Expand Up @@ -94,6 +112,24 @@ namespace crow
raw_socket().close(ec);
}

void shutdown_both()
{
boost::system::error_code ec;
raw_socket().shutdown(boost::asio::socket_base::shutdown_type::shutdown_both, ec);
}

void shutdown_send()
{
boost::system::error_code ec;
raw_socket().shutdown(boost::asio::socket_base::shutdown_type::shutdown_send, ec);
}

void shutdown_recv()
{
boost::system::error_code ec;
raw_socket().shutdown(boost::asio::socket_base::shutdown_type::shutdown_receive, ec);
}

boost::asio::io_service& get_io_service()
{
return raw_socket().get_io_service();
Expand Down