Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0803d8b

Browse files
committed
Merge pull request#551 from DanielBujnik/0.11-devel-setting-source-port
Setting source port
2 parents9e0cfaa +87f6482 commit0803d8b

File tree

7 files changed

+32
-20
lines changed

7 files changed

+32
-20
lines changed

‎boost/network/protocol/http/client/connection/async_normal.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ struct http_async_connection
9595
this->method = method;
9696
boost::uint16_t port_ =port(request);
9797
string_type host_ =host(request);
98+
boost::uint16_t source_port = request.source_port();
99+
98100
resolve_(resolver_, host_, port_,
99101
request_strand_.wrap(boost::bind(
100102
&this_type::handle_resolved,this_type::shared_from_this(),
101-
host_, port_, get_body, callback,
103+
host_, port_,source_port,get_body, callback,
102104
generator, boost::arg<1>(), boost::arg<2>())));
103105
if (timeout_ >0) {
104106
timer_.expires_from_now(boost::posix_time::seconds(timeout_));
@@ -129,7 +131,7 @@ struct http_async_connection
129131
is_timedout_ =true;
130132
}
131133

132-
voidhandle_resolved(string_type host, boost::uint16_t port,bool get_body,
134+
voidhandle_resolved(string_type host, boost::uint16_t port,boost::uint16_t source_port,bool get_body,
133135
body_callback_function_type callback,
134136
body_generator_function_type generator,
135137
boost::system::error_codeconst& ec,
@@ -141,10 +143,10 @@ struct http_async_connection
141143
resolver_iterator iter =boost::begin(endpoint_range);
142144
asio::ip::tcp::endpointendpoint(iter->endpoint().address(), port);
143145
delegate_->connect(
144-
endpoint, host,
146+
endpoint, host, source_port,
145147
request_strand_.wrap(boost::bind(
146148
&this_type::handle_connected,this_type::shared_from_this(), host,
147-
port, get_body, callback, generator,
149+
port,source_port,get_body, callback, generator,
148150
std::make_pair(++iter,resolver_iterator()),
149151
placeholders::error)));
150152
}else {
@@ -154,7 +156,7 @@ struct http_async_connection
154156
}
155157
}
156158

157-
voidhandle_connected(string_type host, boost::uint16_t port,bool get_body,
159+
voidhandle_connected(string_type host, boost::uint16_t port,boost::uint16_t source_port,bool get_body,
158160
body_callback_function_type callback,
159161
body_generator_function_type generator,
160162
resolver_iterator_pair endpoint_range,
@@ -174,10 +176,10 @@ struct http_async_connection
174176
resolver_iterator iter =boost::begin(endpoint_range);
175177
asio::ip::tcp::endpointendpoint(iter->endpoint().address(), port);
176178
delegate_->connect(
177-
endpoint, host,
179+
endpoint, host, source_port,
178180
request_strand_.wrap(boost::bind(
179181
&this_type::handle_connected,this_type::shared_from_this(),
180-
host, port, get_body, callback, generator,
182+
host, port,source_port,get_body, callback, generator,
181183
std::make_pair(++iter,resolver_iterator()),
182184
placeholders::error)));
183185
}else {

‎boost/network/protocol/http/client/connection/connection_delegate.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace http {
1313
namespaceimpl {
1414

1515
structconnection_delegate {
16-
virtualvoidconnect(asio::ip::tcp::endpoint &endpoint, std::string host,
16+
virtualvoidconnect(asio::ip::tcp::endpoint &endpoint, std::string host, boost::uint16_t source_port,
1717
function<void(system::error_codeconst &)> handler) = 0;
1818
virtualvoidwrite(
1919
asio::streambuf &command_streambuf,

‎boost/network/protocol/http/client/connection/normal_delegate.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace impl {
1919
structnormal_delegate : connection_delegate {
2020
normal_delegate(asio::io_service &service);
2121

22-
virtualvoidconnect(asio::ip::tcp::endpoint &endpoint, std::string host,
22+
virtualvoidconnect(asio::ip::tcp::endpoint &endpoint, std::string host, boost::uint16_t source_port,
2323
function<void(system::error_codeconst &)> handler);
2424
virtualvoidwrite(
2525
asio::streambuf &command_streambuf,

‎boost/network/protocol/http/client/connection/normal_delegate.ipp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ boost::network::http::impl::normal_delegate::normal_delegate(
1919
: service_(service) {}
2020

2121
voidboost::network::http::impl::normal_delegate::connect(
22-
asio::ip::tcp::endpoint &endpoint, std::string host,
22+
asio::ip::tcp::endpoint &endpoint, std::string host, boost::uint16_t source_port,
2323
function<void(system::error_codeconst &)> handler) {
2424

2525
// TODO(dberris): review parameter necessity.
2626
(void)host;
27-
28-
socket_.reset(newasio::ip::tcp::socket(service_));
27+
28+
socket_.reset(newasio::ip::tcp::socket(service_,asio::ip::tcp::endpoint(asio::ip::tcp::v4(), source_port)));
2929
socket_->async_connect(endpoint, handler);
3030
}
3131

‎boost/network/protocol/http/client/connection/ssl_delegate.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct ssl_delegate : connection_delegate,
2929
optional<std::string> private_key_file,
3030
optional<std::string> ciphers,long ssl_options);
3131

32-
virtualvoidconnect(asio::ip::tcp::endpoint &endpoint, std::string host,
32+
virtualvoidconnect(asio::ip::tcp::endpoint &endpoint, std::string host, boost::uint16_t source_port,
3333
function<void(system::error_codeconst &)> handler);
3434
virtualvoidwrite(
3535
asio::streambuf &command_streambuf,
@@ -49,7 +49,8 @@ struct ssl_delegate : connection_delegate,
4949
optional<std::string> ciphers_;
5050
long ssl_options_;
5151
scoped_ptr<asio::ssl::context> context_;
52-
scoped_ptr<asio::ssl::stream<asio::ip::tcp::socket> > socket_;
52+
scoped_ptr<asio::ip::tcp::socket> tcp_socket_;
53+
scoped_ptr<asio::ssl::stream<asio::ip::tcp::socket&> > socket_;
5354
bool always_verify_peer_;
5455

5556
ssl_delegate(ssl_delegateconst &);// = delete

‎boost/network/protocol/http/client/connection/ssl_delegate.ipp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ boost::network::http::impl::ssl_delegate::ssl_delegate(
2929
always_verify_peer_(always_verify_peer) {}
3030

3131
voidboost::network::http::impl::ssl_delegate::connect(
32-
asio::ip::tcp::endpoint &endpoint, std::string host,
32+
asio::ip::tcp::endpoint &endpoint, std::string host, boost::uint16_t source_port,
3333
function<void(system::error_codeconst &)> handler) {
3434
context_.reset(
3535
newasio::ssl::context(service_, asio::ssl::context::sslv23_client));
@@ -59,8 +59,11 @@ void boost::network::http::impl::ssl_delegate::connect(
5959
if (private_key_file_)
6060
context_->use_private_key_file(*private_key_file_,
6161
boost::asio::ssl::context::pem);
62+
63+
tcp_socket_.reset(newasio::ip::tcp::socket(service_,asio::ip::tcp::endpoint(asio::ip::tcp::v4(), source_port)));
6264
socket_.reset(
63-
new asio::ssl::stream<asio::ip::tcp::socket>(service_, *context_));
65+
new asio::ssl::stream<asio::ip::tcp::socket&>(*(tcp_socket_.get()), *context_));
66+
6467
if (always_verify_peer_)
6568
socket_->set_verify_callback(boost::asio::ssl::rfc2818_verification(host));
6669
socket_->lowest_layer().async_connect(

‎boost/network/protocol/http/impl/request.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,26 @@ template <class Tag>
5555
structbasic_request :publicbasic_message<Tag> {
5656

5757
mutable boost::network::uri::uri uri_;
58+
boost::uint16_t source_port_;
5859
typedef basic_message<Tag> base_type;
5960

6061
public:
6162
typedeftypename sync_only<Tag>::type tag;
6263
typedeftypename string<tag>::type string_type;
6364
typedef boost::uint16_t port_type;
6465

65-
explicitbasic_request(string_typeconst& uri_) : uri_(uri_) {}
66+
explicitbasic_request(string_typeconst& uri_) : uri_(uri_), source_port_(0) {}
6667

67-
explicitbasic_request(boost::network::uri::uriconst& uri_) : uri_(uri_) {}
68+
explicitbasic_request(boost::network::uri::uriconst& uri_) : uri_(uri_), source_port_(0) {}
6869

6970
voiduri(string_typeconst& new_uri) { uri_ = new_uri; }
7071

7172
voiduri(boost::network::uri::uriconst& new_uri) { uri_ = new_uri; }
7273

73-
basic_request() : base_type() {}
74+
basic_request() : base_type(), source_port_(0) {}
7475

7576
basic_request(basic_requestconst& other)
76-
: base_type(other), uri_(other.uri_) {}
77+
: base_type(other), uri_(other.uri_), source_port_(other.source_port_) {}
7778

7879
basic_request&operator=(basic_request rhs) {
7980
rhs.swap(*this);
@@ -85,6 +86,7 @@ struct basic_request : public basic_message<Tag> {
8586
basic_request<Tag>&this_ref(*this);
8687
base_ref.swap(this_ref);
8788
boost::swap(other.uri_,this->uri_);
89+
boost::swap(other.source_port_,this->source_port_);
8890
}
8991

9092
string_typeconsthost()const {return uri_.host(); }
@@ -110,6 +112,10 @@ struct basic_request : public basic_message<Tag> {
110112
voiduri(string_typeconst& new_uri)const { uri_ = new_uri; }
111113

112114
boost::network::uri::uriconst&uri()const {return uri_; }
115+
116+
voidsource_port(const boost::uint16_t port) { source_port_ = port; }
117+
118+
boost::uint16_tsource_port()const {return source_port_; }
113119
};
114120

115121
/** This is the implementation of a POD request type

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp