We are porting existing windows code to Linux. We are using ACE as abstraction layer. We are using windows named pipes for communicating with multiple clients and to perform overlapped operations .
What is the equivalent to this in linux. I have checked linux named pipes(FIFO), but they seem to support only one client and server and do not support overlapped IO.
Can you guide me regarding this.
Unix sockets. Essentially,
socket(PF_UNIX, SOCK_STREAM, 0)
. This returns a file descriptor or -1 on error.struct sockaddr_un addr; bzero(addr); addr.sun_len = sizeof(addr); addr.sun_family = PF_UNIX; strncpy(addr.sun_path, "/path/to/file", sizeof(addr.sun_path)-1);
to create the socket address.bind(fd, &addr, sizeof(addr))
.listen(fd,backlog)
to listen for connections. backlog
is the number of un-accept()ed connections that can exist.I'm not sure if SOCK_DGRAM is supported for Unix sockets (if so, it's probably UDP-like).
See the man pages for socket(2), bind(2), listen(2), accept(2), connect(2), unix(4), setsockopt(2).
For "overlapped I/O", see select(2). You can additionally enable non-blocking IO with fcntl(fd,F_SETFL,(int)(fcntl(fd,F_GETFL)|O_NONBLOCK))
(see fcntl(2)), this means read() and write() never block (which means write() can return short, so you need to look at the return value).
I'm not quite sure how Windows named pipes represent multiple connections from multiple clients, but in UNIX, you get one file descriptor per connection (plus one for the "listening" socket).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With