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

3.4: Establishing connections

A name must be bound to a sockbuf if processes want to refer to it and use it for communication. Names must be unique. A unix name is a 3-tuple, <protocol, local path, peer path>. An inet name is a 5-tuple, <protocol, local addr, local port, peer addr, peer port>. sockbuf::bind is used to specify the local half of the name---<local path> for unix and <local addr, local port> for inet. sockbuf::connect and sockbuf::accept are used to specify the peer half of the name---<peer path> for unix and <peer addr, peer port> for inet.

In what follows,

s.bind(sa)
binds sockAddr sa as the local half of the name for s. It returns 0 on success and returns the errno on failure.
s.connect(sa)
sockbuf::connect uses sa to provide the peer half of the name for s and to establish the connection itself. sockbuf::connect also provides the local half of the name automatically and hence, the user should not use sockbuf::bind to bind any local half of the name. It returns 0 on success and returns the errno on failure.
s.listen(nc)
makes s ready to accept connections. nc specifies the maximum number of outstanding connections that may be queued and must be at least 1 and less than or equal to sockbuf::somaxconn which is usually 5 on most systems.
sockbuf so = s.accept(sa)
sockbuf so = s.accept()
accepts connections and returns the peer address in sa. s must be a listening sockbuf. See sockbuf::listen above.