开发者

File Descriptors: is it possible to non-block `write` arbitrary lengths of data?

开发者 https://www.devze.com 2023-02-07 20:41 出处:网络
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)?

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], da开发者_StackOverflow中文版ta, size);
}

on_read(fd, data, size, opts)
{
  memcpy(data, buffers[fd], size);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消