![]() Chapter Contents  | 
![]() Previous  | 
![]() Next  | 
| setsockopt | 
| Portability: | UNIX compatible | 
| SYNOPSIS | |
| DESCRIPTION | |
| RETURN VALUE | |
| PORTABILITY | |
| RELATED FUNCTIONS | 
| SYNOPSIS | 
#include <sys/types.h> #include <sys/socket.h> int setsockopt(int s, int level, int optname, const void *optval, int optlen);
| DESCRIPTION | 
setsockopt
 sets the value of the options associated with socket descriptor 
s
.  
level
 is the level of the option. 
optname
 is the name of the option.   
optval
is a pointer to a buffer that receives the value of the requested
option. As an input parameter, the integer 
optlen
 should be set to the size of the 
optval
 buffer.
Most options are at the socket level. 
Pass 
SOL_SOCKET
 as the 
level
 parameter for these options: 
SO_LINGER
linger
 option. The 
linger
 option controls the behavior of the 
close
 call when there are some data that have not been sent.  
optval
 should point to a 
struct linger
.  If the value
of the 
l_onoff
 field is 
0
, 
close
 returns immediately.  In this case, TCP/IP continues to attempt
to deliver the data, but the program is not informed if delivery fails.  If
the value of the 
l_onoff
field is nonzero, the behavior of the 
close
 call depends on the value of the 
l_linger
 field.  If this value is 
0
, unsent data are discarded at the time of the 
close
. If the value of 
l_linger
 is not 
0
, the 
close
 call
blocks the caller until there is a timeout or until all data are sent.  The 
l_linger
 field indicates the
length of the desired timeout period.  Some TCP/IP implementations may ignore
the value of the 
l_linger
field. 
s
 must be a stream
socket.
SO_OOBINLINE
MSG_OOB
flag in 
recv
 calls.  
optval
 should point to an integer. 
s
 must be a stream socket.  Refer
to "Out-of-Band Data" in Chapter 6, "Berkeley Sockets," in UNIX Network
Programming for information on out-of-band data.
SO_REUSEADDR
optval
 should point to an integer. 
s
 must be a stream socket.
The option
level 
IPPROTO_TCP
 is available for one option.  The 
TCP_NODELAY
 option indicates that TCP's normal
socket buffering should not be used on the socket.  The 
TCP_NODELAY
 option is not operative; it is supported
for source code compatibility.  The 
<netinet/in.h>
 and 
<netinet/tcp.h>
 headers files are required for this option.
| RETURN VALUE | 
If 
setsockopt
 succeeds, it returns a 
0
.   Otherwise, it returns a 
-1
, and sets 
errno
to indicate the type of error.
| PORTABILITY | 
setsockopt
 is portable to other environments, including most UNIX systems,
that implement BSD sockets.  The supported options may vary depending on the
system; additional options may be supported by a specific TCP/IP software
product, and the options described above may be supported differently.  Refer
to your software documentation for details.
| RELATED FUNCTIONS | 
bind
, 
close
, 
ioctl
, 
recv
, 
socket
![]() Chapter Contents  | 
![]() Previous  | 
![]() Next  | 
![]() Top of Page  | 
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.