fix udp_socket proxy issue

This commit is contained in:
Arvid Norberg 2013-11-20 01:19:42 +00:00
parent d120dc1bc4
commit d736b158a0
2 changed files with 23 additions and 13 deletions

View File

@ -70,7 +70,7 @@ namespace libtorrent
udp_socket(io_service& ios, connection_queue& cc);
~udp_socket();
enum flags_t { dont_drop = 1, peer_connection = 2 };
enum flags_t { dont_drop = 1, peer_connection = 2, dont_queue = 4 };
bool is_open() const
{
@ -86,9 +86,11 @@ namespace libtorrent
void unsubscribe(udp_socket_observer* o);
// this is only valid when using a socks5 proxy
void send_hostname(char const* hostname, int port, char const* p, int len, error_code& ec);
void send_hostname(char const* hostname, int port, char const* p
, int len, error_code& ec, int flags = 0);
void send(udp::endpoint const& ep, char const* p, int len, error_code& ec, int flags = 0);
void send(udp::endpoint const& ep, char const* p, int len
, error_code& ec, int flags = 0);
void bind(udp::endpoint const& ep, error_code& ec);
void close();
int local_port() const { return m_bind_port; }
@ -154,7 +156,8 @@ namespace libtorrent
}
private:
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING \
|| defined TORRENT_ERROR_LOGGING
// necessary for logging member offsets
public:
#endif
@ -171,8 +174,10 @@ namespace libtorrent
// and they will be added later
bool m_observers_locked;
void call_handler(error_code const& ec, udp::endpoint const& ep, char const* buf, int size);
void call_handler(error_code const& ec, const char* host, char const* buf, int size);
void call_handler(error_code const& ec, udp::endpoint const& ep
, char const* buf, int size);
void call_handler(error_code const& ec, const char* host
, char const* buf, int size);
void call_drained_handler();
void call_writable_handler();
@ -292,7 +297,8 @@ namespace libtorrent
{
rate_limited_udp_socket(io_service& ios, connection_queue& cc);
void set_rate_limit(int limit) { m_rate_limit = limit; }
bool send(udp::endpoint const& ep, char const* p, int len, error_code& ec, int flags = 0);
bool send(udp::endpoint const& ep, char const* p, int len
, error_code& ec, int flags = 0);
private:

View File

@ -130,7 +130,7 @@ udp_socket::~udp_socket()
#endif
void udp_socket::send_hostname(char const* hostname, int port
, char const* p, int len, error_code& ec)
, char const* p, int len, error_code& ec, int flags)
{
CHECK_MAGIC;
@ -158,12 +158,15 @@ void udp_socket::send_hostname(char const* hostname, int port
return;
}
if (m_queue.size() > 1000) return;
if (m_queue.size() > 1000 || (flags & dont_queue)) return;
m_queue.push_back(queued_packet());
queued_packet& qp = m_queue.back();
qp.ep.port(port);
qp.hostname = allocate_string_copy(hostname);
address target = address::from_string(hostname, ec);
if (ec) qp.ep.address(target);
else qp.hostname = allocate_string_copy(hostname);
qp.buf.insert(qp.buf.begin(), p, p + len);
qp.flags = 0;
}
@ -193,7 +196,7 @@ void udp_socket::send(udp::endpoint const& ep, char const* p, int len
if (m_queue_packets)
{
if (m_queue.size() > 1000) return;
if (m_queue.size() > 1000 || (flags & dont_queue)) return;
m_queue.push_back(queued_packet());
queued_packet& qp = m_queue.back();
@ -1364,12 +1367,13 @@ void udp_socket::drain_queue()
error_code ec;
if (p.hostname)
{
udp_socket::send_hostname(p.hostname, p.ep.port(), &p.buf[0], p.buf.size(), ec);
udp_socket::send_hostname(p.hostname, p.ep.port(), &p.buf[0]
, p.buf.size(), ec, p.flags | dont_queue);
free(p.hostname);
}
else
{
udp_socket::send(p.ep, &p.buf[0], p.buf.size(), ec, p.flags);
udp_socket::send(p.ep, &p.buf[0], p.buf.size(), ec, p.flags | dont_queue);
}
m_queue.pop_front();
}