We discuss only isockunix
here. osockunix
and
iosockunix
are similar.
isockunix
is used to handle interprocess communication in
unix domain. It is derived from isockstream
class and it
uses a sockunixbuf
as its stream buffer. See iosockstream, for
more details on isockstream
. See sockunixbuf Class, for
information on sockunixbuf
.
In what follows,
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
proto
denotes the protocol number and is of type int
sb
is a sockbuf
object and must be in unix domain
sinp
is a pointer to an object of sockunixbuf
isockunix is (ty, proto)
isockunix
object is
whose sockunixbuf
buffer is of the type ty
and has the protocol number
proto
. The default protocol number is 0.
isockunix is (sinp)
isockunix
object is
whose sockunixbuf
is sinp
.
sinp = is.rdbuf ()
sockunixbuf
of isockunix
object
is
.
isockunix::operator ->
sockunixbuf
of sockunix
so that the sockunix
object acts as a smart pointer to sockunixbuf
.
is->localhost (); // same as is.rdbuf ()->localhost ();
tsunread
listens for connections. When tsunwrite
requests
connection, tsunread
accepts it and waits for input.
tsunwrite
sends the string "Hello!!!" to tsunread
.
tsunread
reads the string sent by tsunwrite
and prints on
its stdout.
// tsunread.cpp #include <sockunix.h> #include <unistd.h> int main () { bsockunixbuf sunb (sockbuf::sock_stream); sunb.bind ("/tmp/socket+-"); sunb.listen (2); bisockunix is ( sunb.accept () ); char buf[32]; is >> buf; cout << buf << endl; unlink ("/tmp/socket+-"); return 0; }
// tsunwrite.cpp #include <sockunix.h> int main () { bosockunix os (sockbuf::sock_stream); os->connect ("/tmp/socket++"); os << "Hello!!!\n" << flush; return 0; }