据我所知。Linux是异步通知。当文件描述符变得可读/可写/可接受时,epoll_wait将返回这个fd。但是读写仍然是同步的,会阻塞线程。因此Redis6.0使用线程池来处理网络io。
Windows IOCP和Linux是预言家。当io_uring_enter返回时,读取的数据已经放置在缓冲区中,写缓冲区全部已经写入。
我的问题是:
负责复制这些缓冲区数据的?仍然会阻塞当前线程?如果是,如何加快线程池的使用?
我在Linux中实现了一个类似FTP的协议(家庭作业),我遇到了以下问题:在另一端设法做accept()之前,客户端可能能够连接()和write() (但在它做了listen()之后)。如果不依赖于在不同的通信通道中传递"accept succeeded,you can now write“这样的消息,我如何才能阻止写操作的工作?
如何在linux管道上设置写()的超时?
示例代码:
int fd_pipe = open("/run/some/pipe", O_RDWR);
// here i need to set timeout for 3 seconds somehow, if can't write, code will continue...
write(fd_pipe, something, strlen(something));
// continue executing..
谢谢