以下内容摘自于<msdn>

The setsockopt function sets a socket option.

int setsockopt(
  SOCKET s,
  int level,
  int optname,
  const char* optval,
  int optlen
);

 

Remarks

The setsockopt function sets the current value for a socket option associated with a socket of any type, in any state. Although options can exist at multiple protocol levels, they are always present at the uppermost socket level. Options affect socket operations, such as whether expedited data (OOB data for example) is received in the normal data stream, and whether broadcast messages can be sent on the socket.

Note  If the setsockopt function is called before the bind function, TCP/IP options will not be checked with TCP/IP until the bind occurs. In this case, the setsockopt function call will always succeed, but the bind function call may fail because of an early setsockopt failing.

Note  If a socket is opened, a setsockopt call is made, and then a sendto call is made, Windows Sockets performs an implicit bind function call.

 

level = SOL_SOCKET

ValueTypeMeaning
SO_BROADCASTBOOLEnables transmission and receipt of broadcast messages on the socket.
SO_CONDITIONAL_ACCEPTBOOLEnables sockets to delay the acknowledgment of a connection until after the WSAAccept condition function is called.
SO_DEBUGBOOLRecords debugging information.
SO_DONTLINGERBOOLDoes not block close waiting for unsent data to be sent. Setting this option is equivalent to setting SO_LINGER with l_onoff set to zero.
SO_DONTROUTEBOOLDoes not route: sends directly to interface. Succeeds but is ignored on AF_INET sockets; fails on AF_INET6 sockets with WSAENOPROTOOPT. Not supported on ATM sockets (results in an error).
SO_GROUP_PRIORITYintReserved.
SO_KEEPALIVEBOOLSends keep-alives. Not supported on ATM sockets (results in an error).
SO_LINGERLINGERLingers on close if unsent data is present.
SO_OOBINLINEBOOLReceives OOB data in the normal data stream. (See section Protocol Independent Out-Of-band Data for a discussion of this topic.)
SO_RCVBUFintSpecifies the total per-socket buffer space reserved for receives. This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window.
SO_REUSEADDRBOOLAllows the socket to be bound to an address that is already in use. (See bind.) Not applicable on ATM sockets.
SO_EXCLUSIVEADDRUSEBOOLEnables a socket to be bound for exclusive access. Does not require administrative privilege.
SO_SNDBUFintSpecifies the total per-socket buffer space reserved for sends. This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window.
PVD_CONFIGService Provider DependentThis object stores the configuration information for the service provider associated with socket s. The exact format of this data structure is service provider specific.


level = IPPROTO_TCP1

ValueTypeMeaning
TCP_NODELAYBOOLDisables the Nagle algorithm for send coalescing.
1     included for backward compatibility with Windows Sockets 1.1


level = NSPROTO_IPX

Note  Windows NT supports all IPX options. Windows Me/98/95 support only the following options:

Note  IPX_PTYPE
IPX_FILTERPTYPE
IPX_DSTYPE
IPX_RECVHDR
IPX_MAXSIZE (used with the getsockopt function)
IPX_ADDRESS (used with the getsockopt function)

ValueTypeMeaning
IPX_PTYPEintSets the IPX packet type.
IPX_FILTERPTYPEintSets the receive filter packet type
IPX_STOPFILTERPTYPEintStops filtering the filter type set with IPX_FILTERTYPE
IPX_DSTYPEintSets the value of the data stream field in the SPX header on every packet sent.
IPX_EXTENDED_ADDRESSBOOLSets whether extended addressing is enabled.
IPX_RECVHDRBOOLSets whether the protocol header is sent up on all receive headers.
IPX_RECEIVE_BROADCASTBOOLIndicates broadcast packets are likely on the socket. Set to TRUE by default. Applications that do not use broadcasts should set this to FALSE for better system performance.
IPX_IMMEDIATESPXACKBOOLDirects SPX connections not to delay before sending an ACK. Applications without back-and-forth traffic should set this to TRUE to increase performance.


BSD options not supported for setsockopt are shown in the following table.

ValueTypeMeaning
SO_ACCEPTCONNBOOLSocket is listening.
SO_RCVLOWATintReceives low watermark.
SO_RCVTIMEOintReceives time-out in milliseconds (available in the Microsoft implementation of Windows Sockets 2).
SO_SNDLOWATintSends low watermark.
SO_SNDTIMEOintSends time-out in milliseconds (available in the Microsoft implementation of Windows Sockets 2).
SO_TYPEintType of the socket.


posted on 2007-11-01 17:12  zdleek  阅读(4)  评论(0)    收藏  举报  来源