@@ -45,7 +45,11 @@ namespace toolkit {
4545
4646// 默认的socket flags:不触发SIGPIPE,非阻塞发送 [AUTO-TRANSLATED:fefc4946]
4747// Default socket flags: do not trigger SIGPIPE, non-blocking send
48- #define SOCKET_DEFAULE_FLAGS (FLAG_NOSIGNAL | FLAG_DONTWAIT )
48+ #define SOCKET_DEFAULT_FLAGS (FLAG_NOSIGNAL | FLAG_DONTWAIT )
49+ // Backward compatibility alias for the legacy misspelled macro name.
50+ #ifndef SOCKET_DEFAULE_FLAGS
51+ #define SOCKET_DEFAULE_FLAGS SOCKET_DEFAULT_FLAGS
52+ #endif
4953
5054// 发送超时时间,如果在规定时间内一直没有发送数据成功,那么将触发onErr事件 [AUTO-TRANSLATED:9c5d8d87]
5155// Send timeout time, if no data is sent successfully within the specified time, the onErr event will be triggered
@@ -649,7 +653,36 @@ class Socket : public std::enable_shared_from_this<Socket>, public noncopyable,
649653
650654 * [AUTO-TRANSLATED:2b11445c]
651655 */
652- void setSendFlags (int flags = SOCKET_DEFAULE_FLAGS);
656+ void setSendFlags (int flags = SOCKET_DEFAULT_FLAGS);
657+
658+ // Install a UDP-specific recv buffer before the socket starts receiving.
659+ // This is intended for setup-time tuning, not runtime reconfiguration
660+ // after IO callbacks are active.
661+ /* *
662+ * Replace the UDP recv buffer before the socket fd is created/attached.
663+ * This is intended for setup-time customization of special UDP transports
664+ * and must not be used as a runtime reconfiguration hook.
665+ *
666+ * IMPORTANT: custom SocketRecvBuffer implementations must remain
667+ * compatible with the batched UDP receive path used by Socket::onRead().
668+ * For the active receive batch, both &buffer->getBuffer(0) and
669+ * &buffer->getAddress(0) are treated as pointers to contiguous arrays
670+ * that can be indexed up to count - 1, and the referenced storage must
671+ * remain valid for the duration of the receive operation.
672+ *
673+ * Passing a SocketRecvBuffer that does not satisfy this layout/lifetime
674+ * contract is unsupported and may lead to undefined behavior.
675+ *
676+ * @return Whether the configuration was accepted.
677+ */
678+ bool setUdpRecvBuffer (const SocketRecvBuffer::Ptr &buffer);
679+
680+ // Suppress the UDP ECONNREFUSED read warning on sockets that intentionally
681+ // communicate with transient peers, such as QUIC sessions that may receive
682+ // a late ICMP port-unreachable after the peer has already closed. This is
683+ // a narrow transport-specific knob and should not be enabled casually by
684+ // ordinary upper-layer business code.
685+ void setIgnoreUdpConnRefused (bool ignore);
653686
654687 /* *
655688 * 关闭套接字
@@ -734,11 +767,10 @@ class Socket : public std::enable_shared_from_this<Socket>, public noncopyable,
734767 ssize_t send_l (Buffer::Ptr buf, bool is_buf_sock, bool try_flush = true );
735768 void connect_l (const std::string &url, uint16_t port, const onErrCB &con_cb_in, float timeout_sec, const std::string &local_ip, uint16_t local_port);
736769 bool fromSock_l (SockNum::Ptr sock);
737-
738770private:
739771 // send socket时的flag [AUTO-TRANSLATED:e364a1bf]
740772 // Flag for sending socket
741- int _sock_flags = SOCKET_DEFAULE_FLAGS ;
773+ int _sock_flags = SOCKET_DEFAULT_FLAGS ;
742774 // 最大发送缓存,单位毫秒,距上次发送缓存清空时间不能超过该参数 [AUTO-TRANSLATED:3bd6dba3]
743775 // Maximum send buffer, in milliseconds, the time since the last send buffer was cleared cannot exceed this parameter
744776 uint32_t _max_send_buffer_ms = SEND_TIME_OUT_SEC * 1000 ;
@@ -823,6 +855,13 @@ class Socket : public std::enable_shared_from_this<Socket>, public noncopyable,
823855 // Object count statistics
824856 ObjectStatistic<Socket> _statistic;
825857
858+ // Optional per-socket recv path used by a small number of UDP transports.
859+ // This must be configured before the socket fd is created or any IO
860+ // callbacks are attached.
861+ SocketRecvBuffer::Ptr _read_buffer;
862+ bool _udp_recv_buffer_frozen = false ;
863+ std::atomic<bool > _ignore_udp_conn_refused{false };
864+
826865 // 链接缓存地址,防止tcp reset 导致无法获取对端的地址 [AUTO-TRANSLATED:f8847463]
827866 // Connection cache address, to prevent TCP reset from causing the inability to obtain the peer's address
828867 struct sockaddr_storage _local_addr;
0 commit comments