All of lore.kernel.org
 help / color / mirror / Atom feed
* Switch a fd between blocking and non-blocking mode?
@ 2019-11-11 23:21 Jeffrey Walton
  2019-11-13  9:58 ` Konstantin Andreev
  0 siblings, 1 reply; 3+ messages in thread
From: Jeffrey Walton @ 2019-11-11 23:21 UTC (permalink / raw)
  To: kernelnewbies

Hi Everyone,

I have one more question related to my problem of my program losing
data. I want to ensure I'm not using an anti-pattern that's causing
the problem.

I have a worker thread that blocks on read(2). When the read() occurs,
the fd is switch from blocking to non-blocking. Additional reads are
performed until EAGAIN or EWOULDBLOCK. Then the fd is switched back to
blocking mode.

Does switching a socket between blocking and non-blocking mode cause
the kernel to reset or delete queued data (that has not been read by
the application yet)?

Thanks in advance.

Jeff

----------

Here are the functions that switch between blocking and non-blocking
mode. There's not much to them.

void make_blocking_fd(int fd)
{
    const int old = fcntl(fd, F_GETFL, 0);
    fcntl(fd, F_SETFL, old & ~(int)O_NONBLOCK);
}

void make_nonblocking_fd(int fd)
{
    const int old = fcntl(fd, F_GETFL, 0);
    fcntl(fd, F_SETFL, old | (int)O_NONBLOCK);
}

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

end of thread, other threads:[~2019-11-14  2:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-11 23:21 Switch a fd between blocking and non-blocking mode? Jeffrey Walton
2019-11-13  9:58 ` Konstantin Andreev
2019-11-14  2:20   ` Jeffrey Walton

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.