I am writing an interface under Linux that receives data from a TCP socket. The user provides a buffer in which the received data is stored. If the provided buffer is small, I just want to return an error. The first problem is to determine if the buffer was sufficient. The recv () function returns me the number of bytes actually written to the buffer. If I use the MSG_TRUNC flag specified on the recv () man page, it still returns the same to me. The second problem is dropping data still queued in the socket. Therefore, if I determined that my Buffer provided was small, I just want to erase everything that remains on the socket. Are there any other ways to do this other than closing and opening the socket again or just getting it until there is nothing left? Best wishes <
One suggestion was to simply return until there was nothing left (I will return 0) - but did it end up waiting for the set timeout (in this case, 5 seconds?), Because every time I call recv, is it waiting for data or a timeout?
source
share