in reply to RE: RE: RE: Re: reading from sockets
in thread reading from sockets
I have an old book that tells me most UN*X sockets buffers are at least a few Mb. Nowadays, I'm sure they're larger, especially with the onslaught of 100Mb/s stuff. If you process quickly enough, you're unlikely to ever encounter a buffer overflow, but if you do, the server is notified by TCP that the packet was not received (since the buffer is full) so the server will attempt to send it later, up to some arbitrary amount of time. That's TCP! You don't even have to worry about it! When you read in <SOCKET>, youmay be reading in one or more packets- or you may block, since the buffer is empty. You can pretty much read in the socket buffer as you wish, without worrying about details such as setsockopt, etc. When you initially open a socket, it's empty. Only when a confirmed and triple-checked TCP packet is received is an ACK sent and the actual data part of the packet returned to your perl script via the buffer.
Yes, if you close the connection after the data you have is received, nothing lethal happens. This is perfectly legal and an easy way to speed up the program. The TCP layer will alert the server that the connection has been closed (in TCP, you can half-close connections- but that's a different story) and the server won't bother to send anything more. In this case, it's just like reading a file: read as much as you need and scrap the rest. Why would you even need to read the rest? So, closing the socket when done with it, is perfectly fine.
|
|---|