简体   繁体   English

处于阻塞模式的管道上的select()返回EAGAIN

[英]select() on a pipe in blocking mode returns EAGAIN

The man pages for select() do not list EAGAIN as possible error code for the select() function. select()手册页没有列出EAGAIN作为select()函数的可能错误代码。

Can anyone explain in which cases the select() can produce EAGAIN error? 谁能解释在哪种情况下select()会产生EAGAIN错误?

If I understand select_tut man page , EAGAIN can be produced by sending a signal to the process which is blocked waiting on blocked select(). 如果我了解select_tut手册页 ,则可以通过向被阻塞的进程发送信号,等待阻塞的select()来产生EAGAIN。 Is this correct? 这个对吗?

Since I am using select() in blocking mode with timeout, like this: 由于我在具有超时的阻止模式下使用select(),如下所示:

bool selectRepeat = true;
int res = 0;
timeval  selectTimeout( timeout );
while ( true == selectRepeat )
{
  res = ::select( fd.Get() + 1,
                  NULL,
                  &writeFdSet,
                  NULL,
                  &selectTimeout );
  selectRepeat = ( ( -1 == res ) && ( EINTR == errno ) );
}

should I just repeat the loop when the error number is EAGAIN? 错误号为EAGAIN时,我应该重复循环吗?

select() will not return EAGAIN under any circumstance. 在任何情况下, select()都不会返回EAGAIN It may, however, return EINTR if interrupted by a signal (This applies to most system calls). 但是,如果被信号中断,它可能会返回EINTR (这适用于大多数系统调用)。

EAGAIN (or EWOULDBLOCK ) may be returned from read , write , recv , send , etc. EAGAIN (或EWOULDBLOCK )可以从readwriterecvsend等返回。

EAGAIN is technically not an error, but an indication that the operation terminated without completing, and you should...er...try it again. 从技术上讲,EAGAIN并不是错误,而是表示操作未完成而终止,您应该...再尝试一次。 You will probably want to write logic to retry, but not infinitely. 您可能需要编写逻辑来重试,但不是无限的。 If that was safe, they would have done it themselves in the API. 如果那是安全的,他们将自己在API中完成。

If you are thinking that returing a silly non-error error code like that is kinda bad client interface design, you aren't the first. 如果您认为像这样愚蠢的非错误错误代码是很糟糕的客户端界面设计,那么您不是第一个。 It turns out EAGAIN as an error code has a long interesting history in Unix. 事实证明,EAGAIN是一个错误代码,在Unix中历史悠久。 Among other things, it spawned the widely circulated essay on software design The Rise of Worse-is-Better . 除其他事项外,它催生了关于软件设计《 The Worse-is-Better的崛起》的广泛散文。 There's a couple of paragraphs in the middle that explain why Unix needs to return this sometimes. 中间有几个段落解释了为什么Unix有时需要返回此内容。 Yes, it does indeed have something to do with receiving interrupts during an I/O. 是的,的确与I / O期间接收中断有关。 They call it PC loser-ing. 他们称其为PC失败者。

Many credit this essay as one of the inspirations for Agile programming. 许多人认为这篇文章是敏捷编程的灵感之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM