aboutsummaryrefslogtreecommitdiff
path: root/src/net/socks.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/net/socks.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/net/socks.cpp b/src/net/socks.cpp
index 53154369b..9b81c6c2e 100644
--- a/src/net/socks.cpp
+++ b/src/net/socks.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2018, The Monero Project
+// Copyright (c) 2018-2019, The Monero Project
//
// All rights reserved.
//
@@ -193,7 +193,7 @@ namespace socks
else if (bytes < self.buffer().size())
self.done(socks::error::bad_write, std::move(self_));
else
- boost::asio::async_read(self.proxy_, get_buffer(self), completed{std::move(self_)});
+ boost::asio::async_read(self.proxy_, get_buffer(self), self.strand_.wrap(completed{std::move(self_)}));
}
}
};
@@ -215,13 +215,13 @@ namespace socks
if (error)
self.done(error, std::move(self_));
else
- boost::asio::async_write(self.proxy_, get_buffer(self), read{std::move(self_)});
+ boost::asio::async_write(self.proxy_, get_buffer(self), self.strand_.wrap(read{std::move(self_)}));
}
}
};
client::client(stream_type::socket&& proxy, socks::version ver)
- : proxy_(std::move(proxy)), buffer_size_(0), buffer_(), ver_(ver)
+ : proxy_(std::move(proxy)), strand_(proxy_.get_io_service()), buffer_size_(0), buffer_(), ver_(ver)
{}
client::~client() {}
@@ -296,7 +296,7 @@ namespace socks
if (self && !self->buffer().empty())
{
client& alias = *self;
- alias.proxy_.async_connect(proxy_address, write{std::move(self)});
+ alias.proxy_.async_connect(proxy_address, alias.strand_.wrap(write{std::move(self)}));
return true;
}
return false;
@@ -307,10 +307,26 @@ namespace socks
if (self && !self->buffer().empty())
{
client& alias = *self;
- boost::asio::async_write(alias.proxy_, write::get_buffer(alias), read{std::move(self)});
+ boost::asio::async_write(alias.proxy_, write::get_buffer(alias), alias.strand_.wrap(read{std::move(self)}));
return true;
}
return false;
}
+
+ void client::async_close::operator()(boost::system::error_code error)
+ {
+ if (self_ && error != boost::system::errc::operation_canceled)
+ {
+ const std::shared_ptr<client> self = std::move(self_);
+ self->strand_.dispatch([self] ()
+ {
+ if (self && self->proxy_.is_open())
+ {
+ self->proxy_.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
+ self->proxy_.close();
+ }
+ });
+ }
+ }
} // socks
} // net