X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=0.3 required=5.0	tests=AWL,BAYES_00,DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_NONE,RCVD_NUMERIC_HELO,RP_MATCHES_RCVD,SPF_HELO_PASS
X-Spam-Check-By: sourceware.org
To: cygwin@cygwin.com
From: Zach Saw <zach.saw@gmail.com>
Subject: BUG: FIFO (named pipe) is broken on Cygwin
Date: Tue, 22 Jan 2013 03:38:35 +0000 (UTC)
Lines: 68
Message-ID: <loom.20130122T043220-298@post.gmane.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

According to POSIX, FIFO allows multiple readers / writers. However, it appears 
that Cygwin's implementation only allows for multiple readers and single writer.

The following code fails on Cygwin but passes on Linux (tested on Ubuntu and 
Debian). Note that this code is to replicate an issue of a bigger project that 
relies on FIFO for interprocess synchronizations.

#include <unistd.h>
#include <fcntl.h>
#include <cerrno>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>

int main()
{
    std::string n = "/tmp/test";
    int err;
    err = mkfifo(n.c_str(), 0666);
    if (err == -1)
    {
        std::cout << "mkfifo error" << std::endl;
        return 0;
    }

    int pipefd[4];
    pipefd[0] = open(n.c_str(), O_RDONLY | O_NONBLOCK);
    if (pipefd[0] == -1)
    {
        std::cout << "open 1 error" << std::endl;
        return 0;
    }
    pipefd[1] = open(n.c_str(), O_WRONLY | O_NONBLOCK);
    if (pipefd[1] == -1)
    {
        std::cout << "open 2 error" << std::endl;
        return 0;
    }
    pipefd[2] = open(n.c_str(), O_RDONLY | O_NONBLOCK); // fails - ENXIO
    if (pipefd[2] == -1)
    {
        std::cout << "open 3 error" << std::endl;
        return 0;
    }
    pipefd[3] = open(n.c_str(), O_WRONLY | O_NONBLOCK); // fails - ENXIO
    if (pipefd[3] == -1)
    {
        std::cout << "open 4 error" << std::endl;
        return 0;
    }

    for (int i=0; i<4; i++)
        close(pipefd[i]);

    unlink(n.c_str());

    return 0;
}


Expected output (as tested on Ubuntu and Debian):
(nil)

Actual output:
open 3 error



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

