From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.4 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C245CC43331 for ; Mon, 11 Nov 2019 23:22:39 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7DC282184C for ; Mon, 11 Nov 2019 23:22:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sd/RNwCf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7DC282184C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.92.3) (envelope-from ) id 1iUJ0k-00087u-Ep; Mon, 11 Nov 2019 18:22:18 -0500 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by shelob.surriel.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.3) (envelope-from ) id 1iUJ0i-00087X-1B for kernelnewbies@kernelnewbies.org; Mon, 11 Nov 2019 18:22:16 -0500 Received: by mail-io1-xd35.google.com with SMTP id k13so8125240ioa.9 for ; Mon, 11 Nov 2019 15:22:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:reply-to:from:date:message-id:subject:to; bh=kMk7qCHVV82fy8x0Gd7TCV3GLQO1uNSqf7qSw4B4Ckw=; b=sd/RNwCfzTTXC3X7nigFHVuvd0blpE2Bi+1AoAYQ+w7huuYUHLA6c+86ltE2MZqym/ MEbreqDlm+22YJGlDl6yz3mrV9qfVLwjSPtjL8Mu0ItoGRbBJw4aqDWf6VIQ2KtzhmqH WKm1JDKroMAA7x5h4pOXdPkq0DrFhAEEtUH6Z7+dUna+j0C5GEqo4Prm9UA8S7zSBjwY COqvsKwvGeV1TB2PYZO8eQSvUvvJS4SPOpKGxxI1tMAUI6GNEJGOFWh1kCY8+ZZ7XanY dRanyBwDajUYpEORK/mLYgNGTnmoqNqcpUPFa6/N35xFVqIDYkwIKuYNfdzFCHEHnAZq lH5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:from:date:message-id :subject:to; bh=kMk7qCHVV82fy8x0Gd7TCV3GLQO1uNSqf7qSw4B4Ckw=; b=Bge+K7hRb58GvOFdbcuRGsemlNHszMqrEXTter2DZxJD+KSp4b5l9YnAh80sYo3IYT qZNQ1J6FcC4ldb4tLm5+W7ZP+xFOioSPYHamgjmWiVu3GxgV6Zs/cgDc+625pIqafUEi UcnCQqLbEq1A4AOyBThBcBMFpdRCTE+bpFg7D8igsSNv5hybajkQ7Pdzjynan/eNDQJM S5BXNwH1mEn5fn9REPIEcZKhmF8GxlkItwvK00U1oLw08pn5UItKT286aHxjH0rDIwVh LoNuGohjc2v5i6Um0kqj28yAG4+BBUyjuD/jbk4r1CSgmwuZqEdqUVMG5mNMwBQnzpGW D79w== X-Gm-Message-State: APjAAAVzOxwaCpyfpJVFX45eYl6cPJ1yaVzmg2zV28jk7KRhb34D2WXu l6pHv7QRG7mP3we+rbfj4YnW7qh4uAOp/U1woqrFsacO X-Google-Smtp-Source: APXvYqz2aYZPInWLgxHypT++B0N+8pThBvQWy6oC5W9OuCuryiqI9FIMNEZ7CaRwI2Bpyasv2fLgO3q1Qe6KEp/hx1A= X-Received: by 2002:a02:846:: with SMTP id 67mr3152441jac.54.1573514534288; Mon, 11 Nov 2019 15:22:14 -0800 (PST) MIME-Version: 1.0 From: Jeffrey Walton Date: Mon, 11 Nov 2019 18:21:01 -0500 Message-ID: Subject: Switch a fd between blocking and non-blocking mode? To: kernelnewbies X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: noloader@gmail.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org 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