4929|6

70

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

setsockopt 的源代码 [复制链接]

哪位大大知道setsockopt的源代码是怎么实现的?帮忙说说
谢过先

最新回复

* * TCP_NODELAY is a mechanism to turn off the use of this algorithm. * If this option is turned on and there is data to be sent out, TCP * bypasses the congestion-avoidance algorithm: any available data * segments are sent out if there is enough space in the send window. * * .SS "TCP_MAXSEG -- Changing TCP MSS for the connection" * Specify the TCP_MAXSEG option to decrease the maximum allowable size of an * outgoing TCP segment. This option cannot be used to increase the MSS. * .CS * setsockopt (sock, IPPROTO_TCP, TCP_MAXSEG, &optval, sizeof (optval)); * .CE * The value at is an integer set to the desired MSS (eg. 1024). * * When a TCP socket is created, the MSS is initialized to the default MSS * value which is determined by the configuration parameter `TCP_MSS_DFLT' (512 * by default). When a connection request is received from the other end with * an MSS option, the MSS is modified depending on the value of the received * MSS and on the results of Path MTU Discovery (which is enabled by default). * The MSS may be set as high as the outgoing interface MTU (1460 for an * Ethernet). Therefore, after a call to `socket' but before a connection is * established, an application can only decrease the MSS from its default of 512. * After a connection is established, the application can decrease the MSS from * whatever value was selected. * * .SS "SO_DEBUG -- Debugging the  underlying protocol" * Specify the SO_DEBUG option to let the underlying protocol module record * debug information. * .CS *     setsockopt (sock, SOL_SOCKET, SO_DEBUG, &optval, sizeof (optval)); * .CE * The value at for this option is an integer (type `int'), * either 1 (on) or 0 (off). * * OPTION FOR DATAGRAM SOCKETS * The following section discusses an option for datagram (UDP) sockets. * * .SS "SO_BROADCAST -- Sending to Multiple Destinations" * Specify the SO_BROADCAST option when an application needs to send * data to more than one destination: * .CS *     setsockopt (sock, SOL_SOCKET, SO_BROADCAST, &optval, sizeof (optval)); * .CE * The value at is an integer (type ), either 1 (on) or 0 * (off). * * OPTIONS FOR DATAGRAM AND RAW SOCKETS * The following section discusses options for multicasting on UDP and RAW * sockets. * * .SS "IP_ADD_MEMBERSHIP -- Join a Multicast Group" * Specify the IP_ADD_MEMBERSHIP option when a process needs to join * multicast group: * .CS *     setsockopt (sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&ipMreq, *                 sizeof (ipMreq)); * .CE * The value of is an 'ip_mreq' structure. * `ipMreq.imr_multiaddr.s_addr' is the internet multicast address * `ipMreq.imr_interface.s_addr' is the internet unicast address of the * interface through which the multicast packet needs to pass. * * .SS "IP_DROP_MEMBERSHIP -- Leave a Multicast Group" * Specify the IP_DROP_MEMBERSHIP option when a process needs to leave * a previously joined multicast group: * .CS *     setsockopt (sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&ipMreq, *                 sizeof (ipMreq)); * .CE * The value of is an 'ip_mreq' structure.   * `ipMreq.imr_multiaddr.s_addr' is the internet multicast address. * `ipMreq.imr_interface.s_addr' is the internet unicast address of the * interface to which the multicast address was bound. * * .SS "IP_MULTICAST_IF -- Select a Default Interface for Outgoing Multicasts" * Specify the IP_MULTICAST_IF option when an application needs to specify * an outgoing network interface through which all multicast packets * are sent: * .CS *     setsockopt (sock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&ifAddr, *                 sizeof (mCastAddr)); * .CE * The value of is an 'in_addr' structure.   * `ifAddr.s_addr' is the internet network interface address.  详情 回复 发表于 2009-11-14 22:34
点赞 关注

回复
举报

71

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
你是要setsockopt的源代码


还是要弄通他是什么实现的啊


 
 

回复

71

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
我是要setsocketopt的源代码参考一下,然后写一个能实现类似功能的函数。
谢谢。
 
 
 

回复

65

帖子

0

TA的资源

一粒金砂(初级)

4
 
直接去google下一份VxWorks源码吧.光发一个函数给你,你也看不懂,牵扯太多了.
 
 
 

回复

71

帖子

0

TA的资源

一粒金砂(初级)

5
 

/*******************************************************************************
*
* setsockopt - set socket options
*
* This routine sets the options associated with a socket.
* To manipulate options at the "socket" level, should be SOL_SOCKET.
* Any other levels should use the appropriate protocol number.
*
* OPTIONS FOR STREAM SOCKETS
* The following sections discuss the socket options available for
* stream (TCP) sockets.
*
* .SS "SO_KEEPALIVE -- Detecting a Dead Connection"
* Specify the SO_KEEPALIVE option to make the transport protocol (TCP)
* initiate a timer to detect a dead connection:
* .CS
*     setsockopt (sock, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof (optval));
* .CE
* This prevents an application from  hanging on an invalid connection.
* The value at for this option is an integer (type `int'),
* either 1 (on) or 0 (off).
*
* The integrity of a connection is verified by transmitting
* zero-length TCP segments triggered by a timer, to force a response
* from a peer node.  If the peer does not respond after repeated
* transmissions of the KEEPALIVE segments, the connection is dropped,
* all protocol data structures are reclaimed, and processes sleeping
* on the connection are awakened with an ETIMEDOUT error.
*
* The ETIMEDOUT timeout can happen in two ways.  If the connection is
* not yet established, the KEEPALIVE timer expires after idling
* for TCPTV_KEEP_INIT.  If the connection is established, the
* KEEPALIVE timer starts up when there is no traffic for
* TCPTV_KEEP_IDLE.  If no response is received from the peer after
* sending the KEEPALIVE segment TCPTV_KEEPCNT times with interval
* TCPTV_KEEPINTVL, TCP assumes that the connection is invalid.
* The TCPTV_KEEP_INIT, TCPTV_KEEP_IDLE, TCPTV_KEEPCNT, and TCPTV_KEEPINTVL
* parameters are defined in the file target/h/netinet/tcp_timer.h.
*
* .SS "SO_LINGER -- Closing a Connection"
* Specify the SO_LINGER option to determine whether TCP should perform a
* "graceful" close:
* .CS
*     setsockopt (sock, SOL_SOCKET, SO_LINGER, &optval, sizeof (optval));
* .CE
* To achieve a "graceful" close in response to the shutdown of a connection,
* TCP puts itself through an elaborate set of state transitions.  The goal is
* to assure that all the unacknowledged data in the transmission channel are
* acknowledged, and that the peer is shut down properly.

 
 
 

回复

67

帖子

0

TA的资源

一粒金砂(初级)

6
 
*
* The value at indicates the amount of time to linger if
* there is unacknowledged data, using `struct linger' in
* target/h/sys/socket.h.  The `linger' structure has two members:
* `l_onoff' and `l_linger'.  `l_onoff' can be set to 1 to turn on the
* SO_LINGER option, or set to 0 to turn off the SO_LINGER option.
* `l_linger' indicates the amount of time to linger.  If `l_onoff' is
* turned on and `l_linger' is set to 0, a default value TCP_LINGERTIME
* (specified in netinet/tcp_timer.h) is used for incoming
* connections accepted on the socket.
*
* When SO_LINGER is turned on and the `l_linger' field is set to 0,
* TCP simply drops the connection by sending out an RST (if a
* connection is already established).  This frees up the space for the TCP
* protocol control block, and wakes up all tasks sleeping on the
* socket.
*
* For the client side socket, the value of `l_linger' is not changed
* if it is set to 0.  To make sure that the value of `l_linger' is 0
* on a newly accepted socket connection, issue another setsockopt()
* after the accept() call.
*
* Currently the exact value of `l_linger' time is actually ignored
* (other than checking for 0); that is, TCP performs the state
* transitions if `l_linger' is not 0, but does not explicitly use its
* value.
*
* .SS "TCP_NODELAY -- Delivering Messages Immediately"
* Specify the TCP_NODELAY option for real-time protocols, such as the X
* Window System Protocol, that require immediate delivery of many small
* messages:
* .CS
* setsockopt (sock, IPPROTO_TCP, TCP_NODELAY, &optval, sizeof (optval));
* .CE
* The value at is an integer (type `int') set to either 1
* (on) or 0 (off).
*
* By default, the VxWorks TCP implementation employs an algorithm that
* attempts to avoid the congestion that can be produced by a large number
* of small TCP segments. This typically arises with virtual terminal
* applications (such as telnet or rlogin) across networks that have
* low bandwidth and long delays.  The algorithm attempts to have no
* more than one outstanding unacknowledged segment in the transmission
* channel while queueing up the rest of the smaller segments for later
* transmission.  Another segment is sent only if enough new data is
* available to make up a maximum sized segment, or if the outstanding
* data is acknowledged.
*
* This congestion-avoidance algorithm works well for virtual terminal
* protocols and bulk data transfer protocols such as FTP without any
* noticeable side effects.  However, real-time protocols that require
* immediate delivery of many small messages, such as the X Window
* System Protocol, need to defeat this facility to guarantee proper
* responsiveness in their operation.
 
 
 

回复

83

帖子

0

TA的资源

一粒金砂(初级)

7
 
*
* TCP_NODELAY is a mechanism to turn off the use of this algorithm.
* If this option is turned on and there is data to be sent out, TCP
* bypasses the congestion-avoidance algorithm: any available data
* segments are sent out if there is enough space in the send window.
*
* .SS "TCP_MAXSEG -- Changing TCP MSS for the connection"
* Specify the TCP_MAXSEG option to decrease the maximum allowable size of an
* outgoing TCP segment. This option cannot be used to increase the MSS.
* .CS
* setsockopt (sock, IPPROTO_TCP, TCP_MAXSEG, &optval, sizeof (optval));
* .CE
* The value at is an integer set to the desired MSS (eg. 1024).
*
* When a TCP socket is created, the MSS is initialized to the default MSS
* value which is determined by the configuration parameter `TCP_MSS_DFLT' (512
* by default). When a connection request is received from the other end with
* an MSS option, the MSS is modified depending on the value of the received
* MSS and on the results of Path MTU Discovery (which is enabled by default).
* The MSS may be set as high as the outgoing interface MTU (1460 for an
* Ethernet). Therefore, after a call to `socket' but before a connection is
* established, an application can only decrease the MSS from its default of 512.
* After a connection is established, the application can decrease the MSS from
* whatever value was selected.
*
* .SS "SO_DEBUG -- Debugging the  underlying protocol"
* Specify the SO_DEBUG option to let the underlying protocol module record
* debug information.
* .CS
*     setsockopt (sock, SOL_SOCKET, SO_DEBUG, &optval, sizeof (optval));
* .CE
* The value at for this option is an integer (type `int'),
* either 1 (on) or 0 (off).
*
* OPTION FOR DATAGRAM SOCKETS
* The following section discusses an option for datagram (UDP) sockets.
*
* .SS "SO_BROADCAST -- Sending to Multiple Destinations"
* Specify the SO_BROADCAST option when an application needs to send
* data to more than one destination:
* .CS
*     setsockopt (sock, SOL_SOCKET, SO_BROADCAST, &optval, sizeof (optval));
* .CE
* The value at is an integer (type ), either 1 (on) or 0
* (off).
*
* OPTIONS FOR DATAGRAM AND RAW SOCKETS
* The following section discusses options for multicasting on UDP and RAW
* sockets.
*
* .SS "IP_ADD_MEMBERSHIP -- Join a Multicast Group"
* Specify the IP_ADD_MEMBERSHIP option when a process needs to join
* multicast group:
* .CS
*     setsockopt (sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&ipMreq,
*                 sizeof (ipMreq));
* .CE
* The value of is an 'ip_mreq' structure.
* `ipMreq.imr_multiaddr.s_addr' is the internet multicast address
* `ipMreq.imr_interface.s_addr' is the internet unicast address of the
* interface through which the multicast packet needs to pass.
*
* .SS "IP_DROP_MEMBERSHIP -- Leave a Multicast Group"
* Specify the IP_DROP_MEMBERSHIP option when a process needs to leave
* a previously joined multicast group:
* .CS
*     setsockopt (sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&ipMreq,
*                 sizeof (ipMreq));
* .CE
* The value of is an 'ip_mreq' structure.  
* `ipMreq.imr_multiaddr.s_addr' is the internet multicast address.
* `ipMreq.imr_interface.s_addr' is the internet unicast address of the
* interface to which the multicast address was bound.
*
* .SS "IP_MULTICAST_IF -- Select a Default Interface for Outgoing Multicasts"
* Specify the IP_MULTICAST_IF option when an application needs to specify
* an outgoing network interface through which all multicast packets
* are sent:
* .CS
*     setsockopt (sock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&ifAddr,
*                 sizeof (mCastAddr));
* .CE
* The value of is an 'in_addr' structure.  
* `ifAddr.s_addr' is the internet network interface address.
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表