两个文件描述符之间的桥接 [英] bridging between two file descriptors

查看:137
本文介绍了两个文件描述符之间的桥接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个插座我做选择()就可以了,等待其他进程写入。
一旦写,我读出的数据,并将其写入到另一个文件描述符。
我的问题是,如果有一种方法来弥合套接字的文件描述符,所以当有数据准备好了,它会自动写入到其他文件描述符?

I have a socket I'm doing select() on it, waiting for other process to write. Once it write, I read the data, and write it to another file descriptor. My question is, if there's a way to bridge the socket to the file descriptor, so when there's data ready, it will be automatically written to the other file descriptor ?

这样的话,我可以抛出一个办法,我用的缓冲区,在系统中省略一个线程。

This way, I could throw a way the buffer I'm using, and omit a thread in the system.

推荐答案

在Linux上,使用拼接()可能更合适,当方向是从插座到文件。使用拼接()是有点复杂,但你得到的两个方向。另外,我觉得发送文件使用拼接内部的这些日子。

On linux, using splice() might be more suitable, when the direction is from socket to file. Using splice() is a bit more complicated, but you get both directions. Also, I think sendfile uses splice internally these days.

有对SO已经在讨论()拼接()和发送文件之间的差异很多问题。在网上搜索也揭示什么(源和目的地)为拼接工程矛盾说法。要知道,如果它是适合你的情况,最好的方法就是测试它。

There are many questions on SO already discussing the differences between splice() and sendfile(). Searching the web also reveals conflicting statements on what (sources and destinations) splice works for. The best way to know if it is suitable for your case, is to test it.

SO有关兼容的文件系统:<一href=\"http://stackoverflow.com/questions/3638657/which-file-systems-support-splicing-via-linuxs-splice2\">Which文件系统支持通过拼接的Linux的剪接(2)?

SO about compatible filesystems: Which file systems support splicing via Linux's splice(2)?

SO岁左右的内核不支持对TCP套接字拼接:<一href=\"http://stackoverflow.com/questions/884934/does-linuxs-splice2-work-when-splicing-from-a-tcp-socket\">Does Linux的的剪接(2)工作时从TCP套接字拼接?

SO about old kernels not supporting splice for TCP sockets: Does Linux's splice(2) work when splicing from a TCP socket?

拼接解释说:
http://kerneltrap.org/node/6505

拼接来源:
<一href=\"http://lxr.linux.no/#linux+v3.8.2/fs/splice.c\">http://lxr.linux.no/#linux+v3.8.2/fs/splice.c

这篇关于两个文件描述符之间的桥接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆