文件描述符:是否可以非阻塞“写入”任意长度的数据?
是否可以使用文件描述符作为句柄(也许使用自定义内核驱动程序)来读取和写入任意大小的数据?
或者通过文件描述符传输数据的缓冲区大小是否有操作系统规定的限制?
我知道
- 文件由于磁盘访问时间缓慢而阻塞
- 套接字(流和dgram)具有最大数据包大小
- 管道和fifos 似乎也有某种缓冲区限制
我想创建一个永远不会阻塞写入的 fd。
示例
用法将是这样的:
fd = open("/dev/new_buffer")
write(fd, data, huge_size, NON_BLOCK)
read(fd, data2, huge_size, NON_BLOCK)
后端实现将是这样的 (请原谅过度简化):
on_write(fd, data, size, opts)
{
void* buffers[fd] = malloc(size);
memcpy(buffers[fd], data, size);
}
on_read(fd, data, size, opts)
{
memcpy(data, buffers[fd], size);
}
Is it be possible to read and write arbitrary sizes of data using a file-descriptor as a handle (perhaps with a custom kernel driver)?
Or is there an OS-mandated limit to the buffer size used for transferring data through file descriptors?
I know that
- files block due to slow disk access time
- sockets (stream and dgram) have maximum packet sizes
- pipes and fifos also seem to have some sort of buffer limitation
I would like to create an fd that will never block on writes.
Example
Usage would be something like this:
fd = open("/dev/new_buffer")
write(fd, data, huge_size, NON_BLOCK)
read(fd, data2, huge_size, NON_BLOCK)
Backend implementation would be something like this
(excuse the over simplification):
on_write(fd, data, size, opts)
{
void* buffers[fd] = malloc(size);
memcpy(buffers[fd], data, size);
}
on_read(fd, data, size, opts)
{
memcpy(data, buffers[fd], size);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论