sockbuf
constructors sets up an endpoint for communication. A
sockbuf
object so created can be read from and written to in
linebuffered mode. To change mode, refer to streambuf
class
in your IOStream library.
Note: If you are using AT&T IOStream library, then the linebuffered mode is permanently turned off. Thus, you need to explicitly flush a socket stream. You can flush a socket stream buffer in one of the following four ways:
// os is a socket ostream os << "this is a test" << endl; os << "this is a test\n" << flush; os << "this is a test\n"; os.flush (); os << "this is a test\n"; os->sync ();
sockbuf
objects are created as follows where
s
and so
are sockbuf
objects
sd
is an integer which is a socket descriptor
af
and proto
are integers which denote domain number and
protocol number respectively
ty
is a sockbuf::type
and must be one of
sockbuf::sock_stream
, sockbuf::sock_dgram
,
sockbuf::sock_raw
, sockbuf::sock_rdm
, and
sockbuf::sock_seqpacket
sockbuf s(sd);
sockbuf s;
s
to sd
(defaults to -1).
sockbuf
destructor will close sd
.
sockbuf s(af, ty, proto);
s
to ::socket(af, int(ty), proto);
s.open(ty, proto)
0
, the null pointer
to sockbuf
.
s.is_open()
s = so;
s
after assigning s
with so
.