In the most abstract, platform agnostic way possible, can someone explain what actually determines the end of input/output a socket? Is this something the programming language itself typically handles and indicates by a special return value (for example, -1 bytes read)?
I am exposed with an IO API that will throw EOF when the known end of a stream is reached, however, for network IO, EOF is never thrown (until the Socket is closed), so when I am reading a socket, I never know when to stop reading, as, rather than -1, it will return 0 bytes read. Is 0 bytes read where I should stop reading? Or should I keep trying to read bytes, and consider it EOF/input done being read when 0 is returned so many times (polling basically)?
That solution (polling) seems quite inelegant.. but I can't think of any other way to know when to stop attempting to read input from a socket.