In linux, how can i determine the state of a TCP socket? I searched many in this theme, but i does not finded real usable solution. I the most chases says: write something into the socket and it will fail if connection closed. But what if the content of stream is bound, and a may not write anything junk into the stream? I a other aspect the netstat can determine the socket state, but if i would like to implement the netstat based solution, it will be very expensive. I must resolv the fileDescriptor to socketID, than read all record from /proc/net/tcp, find the fitting line and test state is established. It is not so efficient if this method must be periodically called. It there some other shorthand solution for this problem?
问问题
124 次