From: Jeffrey Walton <noloader@gmail.com>
To: kernelnewbies <kernelnewbies@kernelnewbies.org>
Subject: Switch a fd between blocking and non-blocking mode?
Date: Mon, 11 Nov 2019 18:21:01 -0500 [thread overview]
Message-ID: <CAH8yC8k934m+eMTB-MPf4RPcVDMB1XZeiekMt1YqVD8BMoY7Rg@mail.gmail.com> (raw)
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
next reply other threads:[~2019-11-11 23:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-11 23:21 Jeffrey Walton [this message]
2019-11-13 9:58 ` Switch a fd between blocking and non-blocking mode? Konstantin Andreev
2019-11-14 2:20 ` Jeffrey Walton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAH8yC8k934m+eMTB-MPf4RPcVDMB1XZeiekMt1YqVD8BMoY7Rg@mail.gmail.com \
--to=noloader@gmail.com \
--cc=kernelnewbies@kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).