socket相关4
|
Function |
SYNOPSIS
#include <sys/socket.h>
setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen);
DESCRIPTION
The
The level argument specifies the protocol level at which the option resides. To set options at the socket level, specify the level argument as SOL_SOCKET. To set options at other levels, supply the appropriate protocol number for the protocol controlling the option. For example, to indicate that an option is interpreted by the TCP (Transport Control Protocol), set level to the protocol number of TCP.
The following options are supported for
- SO_DEBUG
-
Provides the ability to turn on recording of debugging information. This option takes an int value in the optval argument. This is a BOOL option.
- SO_BROADCAST
-
Permits sending of broadcast messages, if this is supported by the protocol. This option takes an int value in the optval argument. This is a BOOL option.
- SO_REUSEADDR
-
Specifies that the rules used in validating addresses supplied to
bind() should allow reuse of local addresses, if this is supported by the protocol. This option takes an int value in the optval argument. This is a BOOL option. - SO_KEEPALIVE
-
Keeps connections active by enabling periodic transmission of messages, if this is supported by the protocol.
If the connected socket fails to respond to these messages, the connection is broken and processes writing to that socket are notified with an ENETRESET errno. This option takes an int value in the optval argument. This is a BOOL option.
- SO_LINGER
-
Specifies whether the socket lingers on
close() if data is present. If SO_LINGER is set, the system blocks the process duringclose() until it can transmit the data or until the end of the interval indicated by the l_linger member, whichever comes first. If SO_LINGER is not specified, andclose() is issued, the system handles the call in a way that allows the process to continue as quickly as possible. This option takes a linger structure in the optval argument. - SO_OOBINLINE
-
Specifies whether the socket leaves received out-of-band data (data marked urgent) in line. This option takes an int value in optval argument. This is a BOOL option.
- SO_SNDBUF
-
Sets send buffer size information. This option takes an int value in the optval argument.
- SO_RCVBUF
-
Sets receive buffer size information. This option takes an int value in the optval argument.
- SO_DONTROUTE
-
Specifies whether outgoing messages bypass the standard routing facilities. The destination must be on a directly-connected network, and messages are directed to the appropriate network interface according to the destination address. The effect, if any, of this option depends on what protocol is in use. This option takes an int value in the optval argument. This is a BOOL option.
- TCP_NODELAY
-
Specifies whether the Nagle algorithm used by TCP for send coalescing is to be disabled. This option takes an int value in the optval argument. This is a BOOL option.
For boolean options, a zero value indicates that the option is disabled and a non-zero value indicates that the option is enabled.
PARAMETERS
- s
-
Specifies a socket for which an option should be set.
- level
-
Identifies whether the operation applies to the socket itself or to the underlying protocol being used. The socket itself is identified by the symbolic constant SOL_SOCKET. Other protocol levels require the protocol number for the appropriate protocol controlling the option.
- optname
-
Specifies a single option to which the request applies.
- optval
-
Specifies a value for the option.
- optlen
-
Specifies the length of the option value.
RETURN VALUES
If successful,
- EBADF
-
s is not a valid descriptor
- ENOTSOCK
-
s is not a socket descriptor
- ENOPROTOOPT
-
optname is unknown at indicated level
- EFAULT
-
optval is an invalid pointer
CONFORMANCE
UNIX 98, with exceptions.
MULTITHREAD SAFETY LEVEL
MT-Safe.
PORTING ISSUES
The following BSD options are not supported: SO_ACCEPTCONN, SO_RCVLOWAT, SO_RCVTIMEO, SO_SNDLOWAT, SO_SNDTIMEO, SO_TYPE.
AVAILABILITY
MKS Toolkit for Professional Developers
MKS Toolkit for Enterprise Developers
MKS Toolkit for Enterprise Developers 64-Bit Edition
SEE ALSO
- Functions:
close() ,getsockopt() ,ioctl() ,read() ,socket()
MKS Toolkit 9.0 Documentation Build 78.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律