delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2013/01/21/22:39:06

X-Recipient: archive-cygwin AT delorie DOT 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 AT cygwin DOT com
From: Zach Saw <zach DOT saw AT gmail DOT 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
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019