PIPE_BUF_SIZE - How to reuse NamedPipe buffer

Posted on 2009-12-23
Last Modified: 2013-11-17
Hi Experts,
    I am using NamedPipe in my MFC application.  When the application is started, I create a NamedPipe.  This NamedPipe is not closed until the application is closed.  I set the PIPE_BUF_SIZE to 1024.  I can only send/receive 11 messages, then the buffer is full, and the request can not be read any more.  I increase the bufer to 65535 to allow more messages to be sent.  I am wondering if there is a way to clear this buffer and reuse it without setting a limit. And, is there a way to find out if the buffer is about to be full. The NamedPipe is created as followed:

               m_hInPipe = CreateNamedPipe(

Thanks for your help.
Question by:ChiliPequin
    LVL 17

    Assisted Solution

    Have you tried re-calling CreateNamedPipe with lpszPipeName ?

    Author Comment

    Hi C Security,

    Thanks for your advice.  However, I do not wish to close and recreate the pipe.  The pattern of my application is:  Users login, pipe (server) is created in a thread which loops to listen for requests until there is a request to close the pipe.  Pipe client can only connects to pipe server after the pipe server is launched. Each transaction between pipe client and pipe server includes 2 requests and replies.  The first request sends the number of bytes of the message, the second request sends the main message.  The first reply from the pipe server sends the number of bytes in the reply, the second reply sends the content of the reply.  I am not sure if I understand correctly that the readFile will remove data from the buffer; therefore, the buffer space can be reused.  Temporarily, I increase the buffer size to 65530 in order to handle more messages per session.  Please advise if this temporarily solution would cause any major problem.  Please also advise if there is a way to reuse the buffer space,

    Thank in advance for your help.
    LVL 3

    Assisted Solution

    I believe that if you declare the sizes as zerom Windows will take care of allocating the memory for you.

    Author Comment

    Hi Greg,
       Thanks for the advice.  I have tried to use the default of 0.  The number of transactions that can go through are even smaller than 11.

    Accepted Solution

    Thanks CSecurity and Greg Arnold for providing me with suggestions.  I still do not know the cause of the limitation problem.  As a temporary solution, I increase the pipe buffer size to get around it.  I would like to close this question and divide the points to CSecurity and Greg Arnold.  Thanks again.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
    This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
    The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now