UDP send behaviour after connect()

前端 未结 5 590
粉色の甜心
粉色の甜心 2021-01-05 05:31
#include   
#include   
#include   
#include   
#include   
#include 

        
5条回答
  •  余生分开走
    2021-01-05 05:54

    Your hypothesis is correct. The Linux udp(7) man page describes the situation thus:

    All fatal errors will be passed to the user as an error return even when the socket is not connected. This includes asynchronous errors received from the network. You may get an error for an earlier packet that was sent on the same socket.
    This behavior differs from many other BSD socket implementations which don't pass any errors unless the socket is connected. Linux's behavior is mandated by RFC 1122.

    When the IP_RECVERR option is enabled all errors are stored in the socket error queue and can be received by recvmsg(2) with the MSG_ERRQUEUE flag set.

提交回复
热议问题