delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/07/29/11:56:16

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/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
From: David Rothenberger <daveroth AT acm DOT org>
MIME-Version: 1.0
Message-ID: <16166.39182.824443.673410@phish.entomo.com>
Date: Tue, 29 Jul 2003 08:55:58 -0700
To: chris <caj AT cs DOT york DOT ac DOT uk>
Cc: cygwin AT cygwin DOT com
Subject: Re: Limit to size of pipe
In-Reply-To: <3F2691B2.10307@cs.york.ac.uk>
References: <3F2691B2 DOT 10307 AT cs DOT york DOT ac DOT uk>
Reply-To: daveroth AT acm DOT org

--guUe189JNu
Content-Type: text/plain; charset=us-ascii
Content-Description: message body text
Content-Transfer-Encoding: 7bit

chris writes:
 > Hello!
 > 
 > Further to an earlier message I sent, I now attach an example. This 
 > tries to send a message of a fixed sized down a pipe. Under windows I 
 > can't seem to send much more than 25k down in one go, although I can 
 > send more if I chop it up into sections. Under linux however I can send 
 > as large amounts as I like. While it is possible to work around it, I 
 > thought I would mention it in case it was easy to fix, just no-one had 
 > requested it :)
 > 
 > 
 > ------------
 > Example program follows: setting MSGSIZE>25000ish on my computer causes 
 > fail (ie pipeval=-1)
 > ------------
 > #include <unistd.h>
 > #include <stdio.h>
 > #define MSGSIZE 23000
 > char *msg1 = "message";

I modified the program to allocate the message buffer to send on the
heap and to initialize the entire thing.  The test seems to work for
any size at that point.

Dave


--guUe189JNu
Content-Type: text/plain
Content-Disposition: attachment;
	filename="pipe.c"
Content-Transfer-Encoding: 7bit

#include <unistd.h>
#include <stdio.h>
char *msg1;

void initmessage (int msgsize)
{
    msg1 = (char*) malloc(sizeof(char) * msgsize);

    int i;
    for (i=0; i<msgsize; ++i) {
        msg1[i] = i%255+1;
    }
}

int main (int argc, char** argv)
{
    char *inbuf;
    int p[2], j;
    int pid;
    int msgsize = atoi(argv[1]);

    inbuf = (char*) malloc(sizeof(char) * msgsize);
    initmessage(msgsize);

    if(pipe(p) == -1) exit(1);

    switch(pid = fork()){
        case -1:    exit(2);
        case 0:  /* if child then write down pipe */
            close(p[0]);  /* first close the read end of the pipe */
            write(p[1], msg1, msgsize);
            break;
        default:   /* parent reads pipe */
            close(p[1]);  /* first close the write end of the pipe */
            int pipeval=read(p[0], inbuf, msgsize);
            printf("pipeval:%d\n",pipeval);

            if (pipeval > 60) {
                inbuf[60] = '\0';
            }
            printf("Parent sent: %s\n", inbuf);
            wait(NULL);
    }
}


--guUe189JNu
Content-Type: text/plain; charset=us-ascii

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

- Raw text -


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