All of lore.kernel.org
 help / color / mirror / Atom feed
* How do I avoid recvmsg races with IP_RECVERR?
@ 2015-06-02 19:40 Andy Lutomirski
  2015-06-02 21:17 ` Hannes Frederic Sowa
  0 siblings, 1 reply; 10+ messages in thread
From: Andy Lutomirski @ 2015-06-02 19:40 UTC (permalink / raw)
  To: Network Development

As far as I can tell, enabling IP_RECVERR causes the presence of a
queued error to cause recvmsg, etc to return an error (once).  It's
worse, though: a new error can be queued asynchronously at any time,
this setting sk_err to a nonzero value.  How do I sensibly distinguish
recvmsg failures to to genuine errors receiving messages from recvmsg
failures because there's a queued error?

The only way I can see to get reliable error handling is to literally
call recvmsg in a loop:

while (true /* or while POLLIN is set */) {
  int ret = recvmsg(..., MSG_ERRQUEUE not set);
  if (ret < 0 && /* what goes here? */) {
    whoops!  this might be a harmless asynchronous error!
    take no action!
  }

  /* if POLLERR (or maybe unconditionally), recvmsg(..., MSG_ERRQUEUE);
}

The problem is that, if I'm screwing something up (thus causing EINVAL
or something similar), this will just spin forever.

Am I missing something here?  Would it make sense to add
MSG_IGNORE_ERROR to suppress the sock_error check or IP_RECVERR=2 to
stop setting sk_err?


Thanks,
Andy

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-04-09  0:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-02 19:40 How do I avoid recvmsg races with IP_RECVERR? Andy Lutomirski
2015-06-02 21:17 ` Hannes Frederic Sowa
2015-06-02 21:33   ` Andy Lutomirski
2015-06-02 21:42     ` Hannes Frederic Sowa
2015-06-02 21:49       ` Andy Lutomirski
2015-06-02 21:50       ` Hannes Frederic Sowa
2015-06-03  0:03         ` Andy Lutomirski
2015-06-03  0:33           ` Hannes Frederic Sowa
2015-06-03  0:56             ` Andy Lutomirski
2016-04-09  0:02             ` Andy Lutomirski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.