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 8280397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:39:43+00:00 2026-06-08T09:39:43+00:00

Suppose my application is using a library object Server which has a callback onConnected

  • 0

Suppose my application is using a library object Server which has a callback onConnected, which passes a reference to a Connection object when a new connection is established with a client; the Server retains ownership of the Connection. I would like to destroy the Connection when it is closed (whether locally or remotely), but I’m not sure how best to deal with notifying the application that is using the connection.

The obvious solution is to have some sort of onDisconnected callback and either delete it immediately, allowing the application to crash if it tries to continue using it, or pass it as shared_ptr and just let the object linger until the application cleans it up. Neither of these approaches feels particularly nice to me. The former just feels unsafe, and the latter muddies the concept of who owns the connection and makes leaks possible if the application ignores the callback.

Is there some idiomatic solution to this that I’m missing, or just a better way of doing it?

  • 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-06-08T09:39:44+00:00Added an answer on June 8, 2026 at 9:39 am

    It’s unclear whether you’re writing the library component or the application (or both), but if you don’t own the object then it’s not up to you to decide when to destroy it.

    But look at how connection handles usually work in OS networking libraries; the application’s connection handles don’t suddenly become invalid when the connection closes. The application is the owner of its handle on the connection and is responsible for correctly closing it. But ultimately the actual data structures for dealing with the connection are owned by the kernel, and can be discarded when the connection is no longer actually open. Then the application will get well defined errors when trying to use the shut down connection.

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

Sidebar

Related Questions

I am new to using QT so I suppose this has an easy answer
Suppose you're writing a simple database web application using Ruby and MySQL. Access to
Suppose the following application landscape: +-----------------+ | App server | +-----------------+ | | +-------+
Suppose I have a web application, which uses jQuery for Ajax and UI. Now
Suppose I want to make a Web application which uses a fixed width and
I'm using the Excel.Application COM object from a Python program to open a CSV
I'm building a database library for my application using sqlite3 as the base. I
I have a source code of a library which has a lot of strange
I've got an application that's using a static library I made. One .cpp file
I use a C++ library in my application which connects to the network (I

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.