logo

Navigation:First_Community->Software->Linux development Goto:New TopicSettingSearch
Linux网络编程--8. 套接字选项
Posted by: imac Date: March 29, 2008 02:05AM

MegaEntry - Social networking and discussion site!

有时候我们要控制套接字的行为(如修改缓冲区的大小),这个时候我们就要控制套接字的选项了.  8.1 getsockopt和setsockopt 

CopyRight owned by the original author.--(www.MegaEntry.com)

int getsockopt(int sockfd,int level,int optname,void *optval,socklen_t *optlen) int setsockopt(int sockfd,int level,int optname,const void *optval,socklen_t *optlen) level指定控制套接字的层次.可以取三种值: 1)SOL_SOCKET:通用套接字选项. 2)IPPROTO_IP:IP选项. 3)IPPROTO_TCP:TCP选项.  optname指定控制的方式(选项的名称),我们下面详细解释 

MegaEntry - Social networking and discussion site!

optval获得或者是设置套接字选项.根据选项名称的数据类型进行转换  选项名称                说明                                    数据类型 ========================================================================                         SOL_SOCKET

MegaEntry - Social networking and discussion site!

------------------------------------------------------------------------ SO_BROADCAST            允许发送广播数据                        int SO_DEBUG                允许调试                                int SO_DONTROUTE            不查找路由                              int SO_ERROR                获得套接字错误                          int SO_KEEPALIVE            保持连接                                int

CopyRight owned by the original author.--(www.MegaEntry.com)

SO_LINGER               延迟关闭连接                            struct linger SO_OOBINLINE            带外数据放入正常数据流                  int SO_RCVBUF               接收缓冲区大小                          int SO_SNDBUF               发送缓冲区大小                          int SO_RCVLOWAT             接收缓冲区下限                          int SO_SNDLOWAT             发送缓冲区下限                          int

MegaEntry - Social networking and discussion site!

SO_RCVTIMEO             接收超时                                struct timeval SO_SNDTIMEO             发送超时                                struct timeval SO_REUSERADDR           允许重用本地地址和端口                  int SO_TYPE                 获得套接字类型                          int SO_BSDCOMPAT            与BSD系统兼容                           int ==========================================================================

CopyRight owned by the original author.--(www.MegaEntry.com)

                        IPPROTO_IP -------------------------------------------------------------------------- IP_HDRINCL              在数据包中包含IP首部                    int IP_OPTINOS              IP首部选项                              int IP_TOS                  服务类型 IP_TTL                  生存时间                                int

CopyRight owned by the original author.--(www.MegaEntry.com)

==========================================================================                         IPPRO_TCP -------------------------------------------------------------------------- TCP_MAXSEG              TCP最大数据段的大小                     int TCP_NODELAY             不使用Nagle算法                         int =========================================================================

CopyRight owned by the original author.--(www.MegaEntry.com)

关于这些选项的详细情况请查看 Linux Programmer 's Manual  8.2 ioctl  ioctl可以控制所有的文件描述符的情况,这里介绍一下控制套接字的选项. 

MegaEntry - Social networking and discussion site!

 int ioctl(int fd,int req,...)   ==========================================================================                         ioctl的控制选项 -------------------------------------------------------------------------- SIOCATMARK              是否到达带外标记                        int

MegaEntry - Social networking and discussion site!

FIOASYNC                异步输入/输出标志                       int FIONREAD                缓冲区可读的字节数                      int ========================================================================== 详细的选项请用 man ioctl_list 查看. 

CopyRight owned by the original author.--(www.MegaEntry.com)



Reply To This Message
Subject: 

Copyright 2005-2006 megaentry,All Rights Reserved
IE 6.0 or above is perfect