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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:24:46+00:00 2026-06-02T03:24:46+00:00

I have a TcpDevice class which encapsulates a TCP connection, which has an onRemoteDisconnect

  • 0

I have a TcpDevice class which encapsulates a TCP connection, which has an onRemoteDisconnect method which gets called whenever the remote end hangs up. Then, there’s a SessionManager object which creates TcpSession objects which take a TcpDevice as a communication channel and inserts them in an internal pointer container for the application to use. In case any of the managed TcpSessions should end, I would like the SessionManager instance to be notified about it and then remove the corresponding session from the container, freeing up the resources associated with it.

I found my problem to be very similar to this question:

Object delete itself from container

but since he has a thread for checking the connections state, it gets a little different from mine and the way I intended to solve it using boost::signals, so I decided to go for a new question geared towards it – I apologize if it’s the wrong way to do it… I’m still getting the feel on how to properly use S.O. 🙂

Since I’m kind of familiar with QT signals/slots, I found boost::signals offers a similar mechanism (I’m already using boost::asio and have no QT in this project), so I decided to implement a remoteDeviceDisconnected signal to be emitted by TcpDevice’s onRemoteDisconnect, and for which I would have a slot in SessionManager, which would then delete the disconnected session and device from the container.

To initially try it out I declared the signal as a public member of TcpDevice in tcpdevice.hpp:

class TcpDevice
{
             (...)
  public:
    boost::signal <void ()> remoteDeviceDisconnected;
             (...)
}

Then I emitted it from TcpDevice’s onRemoteDisconnect method like this:

remoteDeviceDisconnected();

Now, is there any way to connect this signal to my SessionManager slot from inside session manager? I tried this:

unsigned int SessionManager::createSession(TcpDevice* device)
{
  unsigned int session_id = session_counter++;
  boost::mutex::scoped_lock lock(sessions_mutex);
  sessions.push_back(new TcpSession(device, session_id));
  device->remoteDeviceDisconnected.connect(boost::bind(&SessionManager::removeDeadSessionSlot, this));
  return session_id;
}

It compiles fine but at link time it complains of multiple definitions of remoteDeviceDisconnected in several object code files:

tcpsession.cpp.o:(.bss+0x0): multiple definition of `remoteDeviceDisconnected'
tcpdevice.cpp.o: (.bss+0x0): first defined here
sessionmanager.cpp.o:(.bss+0x0): multiple definition of `remoteDeviceDisconnected'
tcpdevice.cpp.o: (.bss+0x0): first defined here

I found this strange, since I didn’t redefine the signal anywhere, but just used it at the createSession method above.

Any tips would be greatly appreciated! Thank you!

  • 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-02T03:24:49+00:00Added an answer on June 2, 2026 at 3:24 am

    My bad! Like we all should expect, the linker was right… there was indeed a second definition, I just couldn’t spot it right away because it wasn’t defined by any of my classes, but just “floating” around one of my .cpp files, like those found on boost::signals examples.

    Just for the record, the initial idea worked like a charm: when a given TcpDevice gets disconnected from the remote end, it emits the remoteDeviceDisconnected signal, which is then caught by the SessionManager object which holds the TcpSession instance that points to that TcpDevice. Once notified, SessionManager’s method removeDeadSessionSlot gets executed, iterating through the sessions ptr_list container and removing the one which was disconnected:

    void SessionManager::removeDeadSessionSlot()
    {
      boost::mutex::scoped_lock lock(sessions_mutex);
      TcpSession_ptr_list_it it = sessions.begin();
      while (it != sessions.end()) {
        if (!(*it).device->isConnected())
          it = sessions.erase(it);
        else
          ++it;
      }
    }
    

    Hope that may serve as a reference to somebody!

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

Sidebar

Related Questions

I have a class TDevice. Some devices will have a cellular module. So I
Have a singleton class for BNRItemStore, but when I tried to call it, I
Have a really weird one here. The app has two targets, just to be
Have a group of related projects running in SQL Server 2005 for which I
Have anyone used Redmine Documentor which lets you convert PHP to HTML to Redmine
Have the following scenario. I have a few form, which essentially have a few
Have a bunch of classes which I need to do serialize and deserialize from/to
Have you ever tried working with a XAML file which contains thousand tons of
Have just started using Visual Studio Professional's built-in unit testing features, which as I
have next code: class GameTexture { private: LPDIRECT3DTEXTURE9 texture; unsigned char *alphaLayer; UINT width,

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.