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

3.1: Constructors

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

sockbuf s(sd);
sockbuf s;
Set socket descriptor of s to sd (defaults to -1). sockbuf destructor will close sd.
sockbuf s(af, ty, proto);
Set socket descriptor of s to ::socket(af, int(ty), proto);
s.open(ty, proto)
does nothing and returns simply 0, the null pointer to sockbuf.
s.is_open()
returns a non-zero number if the socket descriptor is open (that is, connected to a peer) else return 0.
s = so;
return a reference s after assigning s with so.