snowyu / libtorrent

Automatically exported from code.google.com/p/libtorrent
Other
1 stars 0 forks source link

session::listen_on doesn't return error_code when the bind address doesn't exist on the machine #656

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. On my machine I have only one Ethernet adapter with inet address: 10.0.2.15.
2. If I call session::listen_on in the following way (pseudo code): 
ses.listen_on(pair(55503, 55503), ec, "10.240.254.113", 
session::listen_reuse_address), the error code ec will show success after the 
function call.
3.

What is the expected output? What do you see instead?
I would expect to see some error returned the error code.
I see that there is no error reported.

What version of the product are you using? On what operating system?
I'm using libtorrent svn revision 9768 on Ubuntu 12.04.4 LTS x64.

Please provide any additional information below.
As far as I debugged the issue the session_impl::setup_listener call correctly 
returns error that the bind fails, but the session_impl::open_listen_port 
doesn't get into account the returned error and continue the execution. Just 
before the call to set_socket_buffer_size (at the end of 
session_impl::open_listen_port) the error_code is cleared and thus the 
listen_on call finishes without error. As far as I checked the last libtorrent 
version (svn revision 10184), the behavior is the same. 

Original issue reported on code.google.com by frea...@gmail.com on 4 Aug 2014 at 7:49

GoogleCodeExporter commented 9 years ago
Does this seem like a reasonable patch?

http://dpaste.com/0GKV9W6

if so, would you mind testing it?

Original comment by arvid.no...@gmail.com on 7 Aug 2014 at 5:21

GoogleCodeExporter commented 9 years ago
I tested it. The listen_on function returns correct error now. There is still 
one problem though (IMO). The listen_on function returns the error but after 
the m_udp_socket.bind even though the call to setup_listener also returns the 
error. The thing is that setup_listener allocates the socket internally and 
then returns the error. After the call to setup_listener there is a check if 
the socket is valid "if (s.sock)" and it is pushed to the m_listen_sockets 
which invalidates the check that you have added "if (m_listen_sockets.empty() 
&& ec)" and prevents it to do early return in case of error.

Original comment by frea...@gmail.com on 7 Aug 2014 at 1:29