improve support for HTTP where one direction of the socket is shut down

This commit is contained in:
Arvid Norberg 2015-01-03 22:38:17 +00:00
parent 8b98261df1
commit d68471805e
3 changed files with 28 additions and 1 deletions

View File

@ -1,3 +1,4 @@
* improve support for HTTP where one direction of the socket is shut down.
* remove internal fields from web_seed_entry * remove internal fields from web_seed_entry
* separate crypto library configuration <crypto> and whether to support * separate crypto library configuration <crypto> and whether to support
bittorrent protocol encryption <encryption> bittorrent protocol encryption <encryption>

View File

@ -89,7 +89,8 @@ namespace libtorrent
std::string const& url() const { return m_url; } std::string const& url() const { return m_url; }
virtual void get_specific_peer_info(peer_info& p) const; virtual void get_specific_peer_info(peer_info& p) const;
virtual void disconnect(error_code const& ec, peer_connection_interface::operation_t op, int error = 0); virtual void disconnect(error_code const& ec
, peer_connection_interface::operation_t op, int error = 0);
virtual void write_request(peer_request const& r); virtual void write_request(peer_request const& r);

View File

@ -119,6 +119,31 @@ void web_peer_connection::disconnect(error_code const& ec
{ {
if (is_disconnecting()) return; if (is_disconnecting()) return;
if (op == peer_connection_interface::op_sock_write
&& ec == boost::system::errc::broken_pipe)
{
#ifdef TORRENT_LOGGING
// a write operation failed with broken-pipe. This typically happens
// with HTTP 1.0 servers that close their incoming channel of the TCP
// stream whenever they're done reading one full request. Instead of
// us bailing out and failing the entire request just because our
// write-end was closed, ignore it and keep reading until the read-end
// also is closed.
peer_log("*** WRITE-DIRECTION CLOSED");
#endif
// prevent the peer from trying to send anything more
m_send_buffer.clear();
m_recv_buffer.free_disk_buffer();
// when the web server closed our write-end of the socket (i.e. its
// read-end), if it's an HTTP 1.0 server. we will stop sending more
// requests. We'll close the connection once we receive the last bytes,
// and our read end is closed as well.
incoming_choke();
return;
}
if (op == peer_connection_interface::op_connect if (op == peer_connection_interface::op_connect
&& m_web && m_web
&& !m_web->endpoints.empty()) && !m_web->endpoints.empty())