Discussion:
[asio-users] Safety of using udp::async_send_to/async_receive_from on the same serviceIO thread
Gheorghe Marinca
2012-09-03 18:50:54 UTC
Permalink
Hy,

I use the same socket in my udp server in order to receive data from
clients on some port, and later after processing of requests respond to to
clients using ip::ud::socket
::*async_send_to*<http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio/reference/basic_datagram_socket/async_send_to.html>

Receive is done async with
*async_receive_from*<http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio/reference/basic_datagram_socket/async_receive_from.html>also.
The socket uses same ioService (it's the same socket after all)
The documentation does not state clearly if one can have at a moment the
same udp socket receive datagrams from client A (in async way) and possibly
send another datagram to client B (async sent) at the same time
I suspect this could lead to problems though and any input is appreciated.
I ended up using same socket for replay because I could not bind another
socket to the same server port while replaying to another client.
Igor R
2012-09-03 19:03:49 UTC
Permalink
I use the same socket in my udp server in order to receive data from clients
on some port, and later after processing of requests respond to to clients
using ip::ud::socket ::async_send_to
Receive is done async with async_receive_from also. The socket uses same
ioService (it's the same socket after all)
The documentation does not state clearly if one can have at a moment the
same udp socket receive datagrams from client A (in async way) and possibly
send another datagram to client B (async sent) at the same time
I suspect this could lead to problems though and any input is appreciated. I
ended up using same socket for replay because I could not bind another
socket to the same server port while replaying to another client.
It is safe to send and receive to/from the same socket simultaneously,
as long as you do this from one thread.
Note that it's not safe to issue multiple composed async.reads (or
writes) without waiting for the completion handler of the previous
one.
Gheorghe Marinca
2012-09-03 19:14:22 UTC
Permalink
"Note that it's not safe to issue multiple composed async.reads (or
writes) without waiting for the completion handler of the previous
one".

So the restriction is only to free function async_read/write (that works
with streams, which UDP is not I guess)
In my case as I've said I use ip::ud::socket
::async_send_to/async_receive_from without waiting for operation to
complete.
Post by Gheorghe Marinca
Post by Gheorghe Marinca
I use the same socket in my udp server in order to receive data from
clients
Post by Gheorghe Marinca
on some port, and later after processing of requests respond to to
clients
Post by Gheorghe Marinca
using ip::ud::socket ::async_send_to
Receive is done async with async_receive_from also. The socket uses same
ioService (it's the same socket after all)
The documentation does not state clearly if one can have at a moment the
same udp socket receive datagrams from client A (in async way) and
possibly
Post by Gheorghe Marinca
send another datagram to client B (async sent) at the same time
I suspect this could lead to problems though and any input is
appreciated. I
Post by Gheorghe Marinca
ended up using same socket for replay because I could not bind another
socket to the same server port while replaying to another client.
It is safe to send and receive to/from the same socket simultaneously,
as long as you do this from one thread.
Note that it's not safe to issue multiple composed async.reads (or
writes) without waiting for the completion handler of the previous
one.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Loading...