简体   繁体   中英

What is the real buffer in socket method recv(bufsize) in python and recv(char *buf) in c?

In python, the method is:

socket.recv(bufsize[, flags])

In C, the method is:

int recv( _In_ SOCKET s, _Out_ char *buf, _In_ int len, _In_ int flags)

What is the buffer here in these two method?

I thought that it was the receive window size or receive buffer if I create a TCP socket. But when I captured the test tcp messages I found I was wrong.

I guess the buffer is the socket buffer. When the tcp messages are coming and first come into tcp's buffer (in the transport layer). And then the tcp's receive window begins to slide for receiving data and deliver them to the socket buffer (the real buffer in two methods above) if the messages are correct. Finally the data is delivered to app.

Am I right?

There are 2 types of buffer here:

  1. The buffer mentioned in recv() is in the user space which is in the running process's memory.
  2. The kernel also maintains a buffer in kernel space. When you call recv() , the data will be copied from kernel space to user space.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM