Question

For a pet project of mine I need a full duplex pipe.

Normally this could be accomplished with two calls to pipe() (one set of fds for each direction) but in my use case I need a solution where you can send in both directions over the same fd.

An other solution could be unix domain sockets but that solution, if I understand correctly, would require a file in the filesystem and connect()/accept() trickery.

The last solution I found is openpty(). This seems to work but I'm not entirely confident that it should: it creates a pseudo tty and there may be issues with using it as a pipe that googling did not tell me.

So my question now is: can I use a pseudotty as a full duplex fd/pipe? Or is there an other solution as well?

Thanks.

Was it helpful?

Solution


You will find your happiness using socketpair

So for Unix domain socket, the use of connect accept depends on wich mode you want use. You can use it without conect accept (not connected mode) by specifying SOCK_DGRAM in your socket call and recvfrom/sendto (without using connect to avoid connected datagram mode...).

It's so important to bind all communication members for getting the address for the "client" else you cannot send response to the client with sendto because the sockaddr_un's client received is empty !

You can see this best example for your need : client and server in the same site (replace cl by sv in the name link).

Regards,
/mohamed

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top