PIPE_BUF_SIZE - How to reuse NamedPipe buffer

Posted on 2009-12-23
Medium Priority
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
  • 3
LVL 17

Assisted Solution

CSecurity earned 1000 total points
ID: 26116941
Have you tried re-calling CreateNamedPipe with lpszPipeName ?

Author Comment

ID: 26127049
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.

Assisted Solution

Greg_Arnold earned 1000 total points
ID: 26138342
I believe that if you declare the sizes as zerom Windows will take care of allocating the memory for you.

Author Comment

ID: 26138721
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

ChiliPequin earned 0 total points
ID: 26506363
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.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them 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.
Suggested Courses

829 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