Maximum buffer length for sendto?

前端 未结 3 1304
南方客
南方客 2020-12-09 06:01

How do you get the maximum number of bytes that can be passed to a sendto(..) call for a socket opened as a UDP port?

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-09 06:34

    On Mac OS X there are different values for sending (SO_SNDBUF) and receiving (SO_RCVBUF). This is the size of the send buffer (man getsockopt):

    getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (int *)&optval, &optlen);
    

    Trying to send a bigger message (on Leopard 9216 octets on UDP sent via the local loopback) will result in "Message too long / EMSGSIZE".

提交回复
热议问题