Blocking sockets: when, exactly, does “send()” return?

后端 未结 5 1031
耶瑟儿~
耶瑟儿~ 2020-12-07 12:44

When, exactly, does the BSD socket send() function return to the caller?

In non-blocking mode, it should return immediately, correct?

A

5条回答
  •  有刺的猬
    2020-12-07 13:02

    If there is room in the kernel buffer, then send() copies as many bytes as it can into the buffer and exits immediately, returning how many bytes were actually copied (which can be fewer than how many you requested). If there is no room in the kernel buffer, then send() blocks until either room becomes available or a timeout occurs (if one is configured).

提交回复
热议问题