Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6797793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:39:09+00:00 2026-05-26T18:39:09+00:00

I am trying to write a named pipe server in C++. I have a

  • 0

I am trying to write a named pipe server in C++. I have a class called client_pool which contains a container of the pipe’s instances, and a single public member function write, which asynchronously sends data to all connected clients.

Problem is, clients have the tendency to disconnect unexpectedly. When this happens, the call to WriteFileEx fails with ERROR_NO_DATA. When that happens, i want to go to the client_pool class and tell it to close the client handle and remove it from the container. However, since WriteFileEx is so fricking hard to use, I created a helper class called write_context in an anonymous namespace.

So the end result is, that I want to call a private method in client_pool, which is declared in clients.h, from the class write_context, which is declared in clients.cpp. Something like that (details/error handling omitted):

clients.h

class client_pool {
    struct implementation;
    std::unique_ptr<implementation> pimpl;
public:
    void write(uint8_t *data, size_t size);
};

clients.cpp

struct client_pool::implementation {
    set<HANDLE> connected;
    // ...
    void disconnect(HANDLE victim)
    {
        CloseHandle(victim);
        connected.erase(victim);
    }
};

namespace { struct write_context {
    OVERLAPPED overlapped;
    client_pool *owner;
    HANDLE target;
    const uint8_t *buffer;
    size_t total_size;
    size_t written;
    // ...
    void next_chunk()
    {
        if(!WriteFileEx(/* ... */, write_context::completion_routine)) {
            if(GetLastError() == ERROR_NO_DATA) {
                // I want to do something like
                owner->pimpl->disconnect(target);
            }
        }
    }
    static void CALLBACK completion_routine(DWORD errcode, DWORD transferred, LPOVERLAPPED overlapped)
    {
        auto self = reinterpret_cast<write_context*>(overlapped);
        self->written += transferred;
        if(errcode == ERROR_MORE_DATA) {
            self->next_chunk();
        } else {
            delete self;
        }
    }
}; }

void client_pool::write(uint8_t *data, size_t size)
{
    for each handle in pimpl->connected {
        auto context = new write_context(this, handle, data, size);
        context->next_chunk();
    }
}

Obviously, the line owner->pimpl->disconnect(target); doesn’t compile because pimpl is private. What can I do / what are my alternatvies?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:39:10+00:00Added an answer on May 26, 2026 at 6:39 pm

    Directly accessing pimpl->connected and write_context directly in your client_pool::write method is kinda contrary to the point of the pimpl idiom. You could probably make a case otherwise, until you run into a problem just like this.

    I would just create an implementation::write method for which you can pass through the arguments and a pointer to client_pool.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a named scope that will order my 'Products' class based
I'm trying write a query to find records which don't have a matching record
Im trying to write a single byte at a certain location in a file.
Im trying to write something to get my images to show correctly. I have
I am trying to write a class that will calculate checksums using multiple processes,
I'm trying to write a method named isLowerThanFreezing that returns true if the Temperature
I'm trying to write dynamic method that calls Parallel.ForEach. I have checked a IL
I have a pair of shell programs that talk over a named pipe. The
I'm trying to write a regex with named captures in C# to parse cron
I'm trying to write a script that contains this screen -S demo -d -m

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.