What are SO_SNDBUF and SO_RCVBUF

前端 未结 5 2094
无人共我
无人共我 2020-11-30 23:14

Can you explain me what exactly are SO_SNDBUF and SO_RCVBUF options?

OK, for some reason the OS buffers the outgoing/incomming data but I\'

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 23:40

    Above answers didn't answer all questions, especially about the relationship between Socket buffer and TCP buffer.

    I think they are different things in different layer. TCP buffer is the consumer of Socket buffer.

    Socket buffers (input & output) is an IO buffer that is accessed by System calls from the application code in user space. For example, with output buffer, the application code can

    • Send data immediately before the buffer is full and be blocked when buffer is full.
    • Set the buffer size.
    • Flush the data in buffer to the underlying storage (TCP send buffer).
    • Close the output buffer by close the stream.

    TCP buffers (send & receive) are in kernel space that only OS can access. For example, with TCP send buffer, the TCP protocol implementation can

    • Send packets and accept ACK.
    • Guarantee delivery and ordering of packets.
    • Control congestion by resizing the inflight packets window.

    By the way, UDP protocol doesn't have buffer but UDP socket can still have IO buffer.

    These are my understanding and I'm more than happy to get any feedback/modification/correction.

提交回复
热议问题