boost::asio close TCP connection cleany
Hy..I've seen in the tutorial that client side disconnect is called simply by a break in the read loop. I would like to know which is the step-by-step instruction to close correctly a TCP connection (both server and client side) and where I have to put them. I've seen the close and shutdown functions, but I don't know where call them. Finally...what I can do when an EOF error happens?? thank you..
Hy..I've seen in the tutorial that client side disconnect is called simply by a break in the read loop. I would like to know which is the step-by-step instruction to close correctly a TCP connection (both server and client side) and where I have to put them. I've seen the close and shutdown functions, but I don't know where call them.
It depends on the structure of your code and on what you do exactly. For example, if you've got a chain "send-handler-send-...", and you use shared_from_this idiom, and this chain ends at some stage of your program -- you shouldn't do anything more, as your connection object along with its socket will destroy & close automatically, thanks to the shared_from_this idiom. OTOH, if your chain is "infinite", eg. it's a receiving socket, which should always be listening for incoming data -- then you should close it explicitly by calling socket.close().
Finally...what I can do when an EOF error happens??
It means that the connection has been closed.
Thanks...I'm in the second scenario...I don't use async call, so in the client
I have 2 thread,1 for read and one for write...both inside an infinite loop...
Ok I catch the EOF error...and after?I have to call close, shutdown..?
________________________________
Da: Igor R
Hy..I've seen in the tutorial that client side disconnect is called simply by a break in the read loop. I would like to know which is the step-by-step instruction to close correctly a TCP connection (both server and client side) and where I have to put them. I've seen the close and shutdown functions, but I don't know where call them.
It depends on the structure of your code and on what you do exactly. For example, if you've got a chain "send-handler-send-...", and you use shared_from_this idiom, and this chain ends at some stage of your program -- you shouldn't do anything more, as your connection object along with its socket will destroy & close automatically, thanks to the shared_from_this idiom. OTOH, if your chain is "infinite", eg. it's a receiving socket, which should always be listening for incoming data -- then you should close it explicitly by calling socket.close().
Finally...what I can do when an EOF error happens??
It means that the connection has been closed. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I don't use async call, so in the client I have 2 thread,1 for read and one for write...both inside an infinite loop...
Well, the primary question in this situation is why you use asio? The main asio advantage is proactor-oriented design, which allows you make simple and scalable application, without locking and explicit multithreading. If the whole design of your application is around multithreading and sync. i/o, and it's not supposed to be portable -- I'm afraid you'd be better off with simple plain sockets.
Ok I catch the EOF error...and after?I have to call close, shutdown..?
Yes, you can close() the socket on your side, or just destroy it - depending on the design of your program.
participants (2)
-
Igor R
-
Marco Piacentini