This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Using FIFO's in Cygwin.


Hi Corinna,

Just a question ... (and certainly NOT a request for a snapshot at the end of the day).

Or a confirmation, if you like ...

A server-client example (using FIFO's) from LPI (Linux Programming Interface, M. Kerrisk), chapter 44.8,
fails on Cygwin.

Below the example as an STC, which shows that the server blocks in the 2nd open() call on Cygwin, while
it does not on Linux.

I have exercised (modified) the example from LPI a lot, but was UNable to state exactly in what respect
Cygwin's FIFO is different from Linux's FIFO.

Q: is the model of the FIFO in Cygwin different from the one used in Linux? Note: the question is about
the model for FIFO's in blocking mode ...

Non-blocking complicates things even more ...

Henri

----- Cygwin
@@ uname -a
CYGWIN_NT-6.1-WOW Seven 1.7.35(0.286/5/3) 2015-02-27 17:16 i686 Cygwin

@@ ./server-stc -- window S
server fifo created. <==== output unitil './client-stc 4' is executed
server fifo opened for reading. serverFd = 3
^C                                                              <==== server does not terminate
@@

@@ ./client-stc 4 -- window C
server fifo opened for writing. serverFd = 3
client stopped.
@@

Note: server blocks in open() call - the 2nd one (O_WRONLY)

----- Linux
@@ uname -a
Linux xxxxx.localdomain 3.14.27-100.fc19.i686.PAE #1 SMP Wed Dec 17 19:56:19 UTC 2014 i686 i686 i386 GNU/Linux

@@ ./server-stc -- window S
server fifo created. <==== output until './client-stc 4' is executed
server fifo opened for reading. serverFd = 3
server fifo opened for writing. dummyFd = 4
server stopped.
@@

@ ./client-stc 4 -- window C
server fifo opened for writing. serverFd = 3
client stopped.
@@

Note: server terminates (on Linux) ...

----- // gcc -o server-stc server-stc.c
/*************************************************************************\
*                  Copyright (C) Michael Kerrisk, 2014.                   *
\*************************************************************************/

/* Listing 44-7 */

#define fatal(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0)

#ifdef __linux__
#include <sys/stat.h>
#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

#define SERVER_FIFO "/tmp/myfifo"

// NOT Kerrisk's server -- just an STC

int
main(int argc, char *argv[])
{
    int serverFd, dummyFd;

    umask(0);
    if (mkfifo(SERVER_FIFO, S_IRUSR | S_IWUSR | S_IWGRP) == -1 && errno != EEXIST)
        fatal("mkfifo %s");
printf("server fifo created.\n");

    // start service
    serverFd = open(SERVER_FIFO, O_RDONLY); // will block until fifo opened for write by the 1st client
    if (serverFd == -1) fatal("open %s");
printf("server fifo opened for reading. serverFd = %d\n", serverFd);

    // dummy: prevent that server would receive eof on read() of server fifo in case
    // the fifo has been closed by all clients
    dummyFd = open(SERVER_FIFO, O_WRONLY); // SHOULD NOT BLOCK -- it does not on Linux
    if (dummyFd == -1) fatal("open %s");
printf("server fifo opened for writing. dummyFd = %d\n", dummyFd);

printf("server stopped.\n");
    exit(EXIT_SUCCESS);
}

----- // gcc -o client-stc client-stc.c
/*************************************************************************\
*                  Copyright (C) Michael Kerrisk, 2014.                   *
\*************************************************************************/

/* Listing 44-8 */

#define fatal(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0)

#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>

#define SERVER_FIFO "/tmp/myfifo"

// NOT Kerrisk's client -- just an STC

int
main(int argc, char *argv[])
{
    int serverFd;

    // service request
    serverFd = open(SERVER_FIFO, O_WRONLY); // will unblock the open() call by the server if this is the 1st client
    if (serverFd == -1) fatal("open %s");
printf("server fifo opened for writing. serverFd = %d\n", serverFd);

printf("client stopped.\n");
    exit(EXIT_SUCCESS);
}

=====


--
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]