From owner-freebsd-hackers@FreeBSD.ORG Sun Jun 3 02:23:32 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E4BD116A46B for ; Sun, 3 Jun 2007 02:23:32 +0000 (UTC) (envelope-from artifact.one@googlemail.com) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.230]) by mx1.freebsd.org (Postfix) with ESMTP id 94BBA13C457 for ; Sun, 3 Jun 2007 02:23:32 +0000 (UTC) (envelope-from artifact.one@googlemail.com) Received: by wx-out-0506.google.com with SMTP id h28so785920wxd for ; Sat, 02 Jun 2007 19:23:32 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=googlemail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=CXp20s2tci6mnUOOmMP2a75lccumE/PwhrqOxZfZOAiKyufuA1Ug/6j0zQMUkdMDunYrUx7WQti5A+AK6N/XslWDOK7ZNAL8Ad4/PrsWk2OyYWhANAn2cdhqyXBVzjRRszDoosa4eGWFUNTIakCQKt9yU9RiOhbUk0KIasP63gA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=IYsMlVf1H+6JFG72UposFtDmdm4SlpviULx4c/Lt2s3eA7OZQjvU6Jc57WgYBrX0/Pm2dGcT1RExG1N397KxJiu8awm/AnrkIUhjFdBAL5AzsvdKIWT6pOgvA44achPz9GxjLwtQO5YwpTTvZWVA2HVUbqu6NTPJbK1KD+i+OjA= Received: by 10.90.28.13 with SMTP id b13mr2824098agb.1180837411917; Sat, 02 Jun 2007 19:23:31 -0700 (PDT) Received: by 10.90.51.1 with HTTP; Sat, 2 Jun 2007 19:23:31 -0700 (PDT) Message-ID: <8e96a0b90706021923i2ef1d95ey909e269f3061ca82@mail.gmail.com> Date: Sun, 3 Jun 2007 03:23:31 +0100 From: "mal content" To: freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: FIFO asymmetry X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Jun 2007 02:23:33 -0000 Hello. This is related to my earlier email, which I now believe to be unanswerable (so it's probably worth ignoring). Why do FIFOs work asymmetrically with regards to opening for reading or writing? int rfd; int wfd; if (mkfifo("fifo_r", 0600) == -1) die(); rfd = open("fifo_r", O_RDONLY | O_NONBLOCK); if (rfd == -1) die(); if (mkfifo("fifo_w", 0600) == -1) die(); wfd = open("fifo_w", O_WRONLY | O_NONBLOCK); if (wfd == -1) die(); The first open() call will (unless there's a catastrophic error), be successful and will not block, even if there's no writer on the other end of the fifo. The second open() call will fail if there's no reader (ENXIO). Why this irritating difference in functionality? Surely the second open() call should fail and any write() on the fd should return -1 (EWOULDBLOCK) or 0 like the first would in the case of a read()? In a hypothetical program, I would create a FIFO in the filesystem and select for readability (a writer has turned up and has data). I can't do the same in reverse (create a FIFO and select for writability - a reader has turned up and expects data). Is there some sort of rationale for this surprising behaviour (in POSIX or some ancient UNIX docs)? Before anybody tries to shoot me down in flames, I realise this isn't FreeBSD-specific. thanks, MC