Detecting EOF in Named Pipes

This is a discussion on Detecting EOF in Named Pipes within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I've got a problem with Named Pipe under Windows. I've created a (waiting and duplex) Named Pipe with CreateNamedPipe() ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    8

    Detecting EOF in Named Pipes

    Hi,

    I've got a problem with Named Pipe under Windows. I've created a (waiting and duplex) Named Pipe with CreateNamedPipe() and ConnectNamedPipe(). On the client side I've connected to this with CreateFile() and write an amount of data to this pipe. How can the client tell the server, that the end of data is reached. When I try SetEndOfFile() I got the error code ERROR_INVALID_PARAMETER. And closing the handle is inacceptable because after the client wrote its data, it want to read the answer, so I need the handle.

    Junktyz.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, SetEndOfFile only works on "real" files (that is those on a disk/memory card/tape and such). To indicate end of file on a pipe, you have two choices:
    1. Close the pipe.
    2. Introduce a protocol where you send the size of the file at the beginning [to make it robust, you probably need some way to ensure that the data you receive is ACTUALLY the size of the file, and not something else!]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    8
    I've been afraid of an answer like that . But thanks. Because the length of the data must not be known at the beginning, I implement a Brickwall Stream. The brickwall is a byte array. When closing the output stream this data is send and when reading this brickwall in the input stream, EOF is recognized.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 2
    Last Post: 04-22-2008, 12:07 PM
  3. Replies: 2
    Last Post: 04-19-2008, 12:06 AM
  4. Deletion of open named pipes
    By sparkymat in forum Linux Programming
    Replies: 4
    Last Post: 11-07-2007, 09:46 AM
  5. Named Pipes with .NET?
    By michl in forum C# Programming
    Replies: 2
    Last Post: 04-28-2003, 12:54 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21