c++ - Is tcp socket can notice the exception of network broken? -


i have tcp link server socket on linux. , used select() function monitor if there data, if there have, use recv data.

now want know if network broken(such cable removed). can't exception monitor exception.

fd_set( m_socket, &except_fds );  int result = select( m_socket + 1, &fds, 0, &except_fds, timeout == -1 ? 0 : &tv ); 

what confused me there similar implementation (java.net.socket) on android, can catch exception if set phone flight mode.

is select() implementation platform specific?

in short, if method can used monitor network broken? if not, there solution this?

what confused me there similar implementation (java.net.socket) on android, can catch exception if set phone flight mode.

not similar. java.net.socket not use select(), except read timeouts on platforms don't support so_rcvtimeo.

is select() implementation platform specific?

of course.

in short, if method can used monitor network broken?

no.

if not, there solution this?

the way can reliably detect broken tcp connection try write it. eventually, after taking account buffering , retries, write() or send() , friends return -1 errno == econnreset.


Comments

Popular posts from this blog

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -