PREV UP NEXT C++ socket classes for OS/2

3.5: Getting and Setting Socket Options

Socket options are used to control a socket communication. New options can be set and old value of the options can be retrived at the protocol level or at the socket level by using setopt and getopt member functions. In addition, you can also use special member functions to get and set specific options.

In what follows,

s.getopt(op, &opval, sizeof(opval), oplevel)
gets the option value of the sockbuf::option op at the option level oplevel in opval. It returns the actual size of the buffer opval used. The default value of the oplevel is sockbuf::sol_socket.
s.setopt(op, &opval, sizeof(opval), oplevel)
sets the option value of the sockbuf::option op at the option level oplevel to opval. The default value of the oplevel is sockbuf::sol_socket.
s.gettype()
gets the socket type of s. The return type is sockbuf::type.
s.clearerror()
gets and clears the error status of the socket.
s.debug(opval)
if opval is not -1, set the sockbuf::so_debug option value to opval. In any case, return the old option value of sockbuf::so_debug option. The default value of opval is -1.
s.reuseaddr(opval)
if opval is not -1, set the sockbuf::so_reuseaddr option value to opval. In any case, return the old option value of sockbuf::so_reuseaddr option. The default value of opval is -1.
s.dontroute(opval)
if opval is not -1, set the sockbuf::so_dontroute option value to opval. In any case, return the old option value of sockbuf::so_dontroute option. The default value of opval is -1.
s.oobinline(opval)
if opval is not -1, set the sockbuf::so_oobinline option value to opval. In any case, return the old option value of sockbuf::so_oobinline option. The default value of opval is -1.
s.broadcast(opval)
if opval is not -1, set the sockbuf::so_broadcast option value to opval. In any case, return the old option value of sockbuf::so_broadcast option. The default value of opval is -1.
s.keepalive(opval)
if opval is not -1, set the sockbuf::so_keepalive option value to opval. In any case, return the old option value of sockbuf::so_keepalive option. The default value of opval is -1.
s.sendbufsz(opval)
if opval is not -1, set the new send buffer size to opval. In any case, return the old buffer size of the send buffer. The default value of opval is -1.
s.recvbufsz(opval)
if opval is not -1, set the new recv buffer size to opval. In any case, return the old buffer size of the recv buffer. The default value of opval is -1.
s.linger(tim)
if tim is positive, set the linger time to tim seconds. If tim is 0, set the linger off. In any case, return the old linger time if it was set earlier. Otherwise return -1. The default value of tim is -1.