1.

Is There A Way To Check The Validity Of A Connection_hdl?

Answer»

Sometimes, not generally though, because there isn’t a way to check if a TCP connection is valid.

You can try upgrading your HDL to a full connection_ptr using websocketpp::endpoint::get_con_from_hdl. If this fails, the hdl is definitely invalid. If it succeeds it may or may not be. The only way to tell definitively is to try and send something (either a message or a ping).

If you handle errors from methods LIKE send, ping, close, etc correctly then you shouldn’t have to worry about accidentally sending to DEAD connections. The send/ping/pong/close methods will SET or throw a specific error in the case that you tried to send something but the connection was closed/gone/etc.

Sometimes, not generally though, because there isn’t a way to check if a TCP connection is valid.

You can try upgrading your hdl to a full connection_ptr using websocketpp::endpoint::get_con_from_hdl. If this fails, the hdl is definitely invalid. If it succeeds it may or may not be. The only way to tell definitively is to try and send something (either a message or a ping).

If you handle errors from methods like send, ping, close, etc correctly then you shouldn’t have to worry about accidentally sending to dead connections. The send/ping/pong/close methods will set or throw a specific error in the case that you tried to send something but the connection was closed/gone/etc.



Discussion

No Comment Found