POSIX `pipe` 双向
我想以某种方式使用 (POSIX) pipe
来使其双向连接。即我可以在两端读写。
这可能吗?
(我不想创建两个带有 4 个文件描述符的管道。我只想有 2 个文件描述符,我可以在两端读/写。)
基本上,它应该是 openpty
的回退万一失败了。
I want to use (POSIX) pipe
in a way to have it connected both ways. I.e. I can read and write at both ends.
Is that possible?
(I don't want to create two pipes with 4 file descriptors. I want to have only 2 file descriptors where I can read/write at both ends.)
Basically, it should be a fallback to openpty
in case that fails.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
管道是严格单向的。但在 POSIX 环境中,您可以访问“socketpair()”调用,当与“AF_UNIX”套接字域一起使用时,它将为您提供一对已连接并准备就绪的双向描述符。如果您将 fork 和如果您尝试连接两个单独的预先存在的进程,则需要手动创建套接字并使用套接字调用来连接它们。
Pipes are strictly unidirectional. But in a POSIX environment you may have access to the 'socketpair()' call which, when used with 'AF_UNIX" socket domain will give you a pair of bidirectional descriptors all connected and ready to go. This is handy if you will fork and the descriptors get inherited. If you are trying to connect two separate pre-existing processes, then you will need to create the sockets manually and use the sockets calls to connect them.
我现在基本上有这个代码:
有点工作但还不太正确......
I basically have this code now:
Works somewhat but not quite right yet...