我所阅读和体验过的所有东西(基于Tornado的应用程序)都让我相信ePoll是基于Select和Poll的网络的自然替代品,特别是对于Twisted.这让我变得偏执,对于更好的技术或方法而言,这是非常罕见的.
阅读epoll和替代品之间的几十个比较表明,epoll显然是速度和可扩展性的支柱,特别是它以线性方式扩展,非常棒.那说,处理器和内存利用率如何,epoll仍然是冠军?
在我的应用程序中,有一个专用的io-thread
应用程序通过不同的线程处理数据.此外,要求规定未确认的窗口大小应为1,即任何时候应该只有一个未确认的未确认消息.这意味着如果io-thread已经通过套接字发送了一条消息,它将不再发送任何消息,直到它从接收方听到一个确认消息.应用程序的处理线程通过管道与io-thread通信.如果来自linux CLI的人键入ctrl + C,应用程序需要正常关闭.因此,鉴于这些要求,我有以下选择
我有以下问题
select()和poll()之间的决定.我的应用程序只处理少于50个文件描述符.可以假设我选择选择或民意调查没有区别吗?
select()和pselect()之间的决定.我阅读了linux文档,它说明了signal和select之间的竞争条件.我没有信号经验,所以有人可以更清楚地解释竞争条件和选择()吗?它是否与某人在CLI上按ctrl + C并且应用程序没有停止有关?
pselect和ppoll()之间的决定?对一个与另一个的任何想法
该select()和pselect()系统调用修改其参数(在" fd_set *"参数),所以输入值告诉系统文件描述符检查和返回值告诉程序员哪些文件描述符当前可用它.
如果要为同一组文件描述符重复调用它们,则需要确保每个调用都有一个描述符的新副本.显而易见的方法是使用结构副本:
fd_set ref_set_rd;
fd_set ref_set_wr;
fd_set ref_set_er;
...
...code to set the reference fd_set_xx values...
...
while (!done)
{
fd_set act_set_rd = ref_set_rd;
fd_set act_set_wr = ref_set_wr;
fd_set act_set_er = ref_set_er;
int bits_set = select(max_fd, &act_set_rd, &act_set_wr,
&act_set_er, &timeout);
if (bits_set > 0)
{
...process the output values of act_set_xx...
}
}
Run Code Online (Sandbox Code Playgroud)
(编辑删除不正确的struct fd_set引用 - 正如'R ..'所指出的那样.)
我的问题:
fd_set如图所示,对值进行结构复制是不安全的?我担心的是,有任何隐藏的内存分配或任何意外的事情.(有宏/函数FD_SET(),FD_CLR(),FD_ZERO()和FD_ISSET()来掩盖应用程序的内部.)
我可以看到MacOS X(达尔文)是安全的; 因此,其他基于BSD的系统可能是安全的.您可以通过记录您知道答案中安全的其他系统来提供帮助.
(我确实对fd_set使用超过8192个打开文件描述符的效果有一些小问题- …
我正在努力创建进程并将子进程的输出传递给父进程的字符串.我让它在Windows上工作(使用CreatePipe和CreateProcess和ReadFile),但似乎无法在Unix上获得完全模拟的工作.这是我的代码:
#include <spawn.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
int exit_code;
int cout_pipe[2];
int cerr_pipe[2];
posix_spawn_file_actions_t action;
if(pipe(cout_pipe) || pipe(cerr_pipe))
cout << "pipe returned an error.\n";
posix_spawn_file_actions_init(&action);
posix_spawn_file_actions_addclose(&action, cout_pipe[0]);
posix_spawn_file_actions_addclose(&action, cerr_pipe[0]);
posix_spawn_file_actions_adddup2(&action, cout_pipe[1], 1);
posix_spawn_file_actions_adddup2(&action, cerr_pipe[1], 2);
posix_spawn_file_actions_addclose(&action, cout_pipe[1]);
posix_spawn_file_actions_addclose(&action, cerr_pipe[1]);
vector<string> argmem = {"bla"};
vector<char*> args = {&argmem[0][0], nullptr}; // I don't want to call new.
pid_t pid;
if(posix_spawnp(&pid, "echo", &action, NULL, &args[0], …Run Code Online (Sandbox Code Playgroud)