Jori
Jori

Reputation: 1152

Put data back in socket buffer

Short question, didn't seem to find anything useful here or on Google: in the Winsock2 API, is it possible to put data back in the sockets internal buffer when you have retrieved it using recv() for example, so that is seems it was never actually read from the buffer?

Upvotes: 1

Views: 822

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 597111

No, it is not possible to inject data back into the socket's internal buffer. Either use the MSG_PEEK flag to read data without removing it from the socket's buffer, or else read the socket data into your own buffer, and then do whatever you want with your buffer. You could have your reading I/O logic always look for data in your buffer first, and then read more data from the socket only when your buffer does not have enough data to satisfy the read operation. Any data you inject back into your buffer will be seen by subsequent read operations.

Upvotes: 2

o_weisman
o_weisman

Reputation: 604

You can use the MSG_PEEK flag in your recv() call

Upvotes: 1

Related Questions