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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:08:15+00:00 2026-05-14T20:08:15+00:00

I am currently writing a multi-threaded C++ server using Poco and am now at

  • 0

I am currently writing a multi-threaded C++ server using Poco and am now at the point where I need to be keeping information on which users are connected, how many connections each of them have, and given it is a proxy server, where each of those connections are proxying through to.

For this purpose I have created a ServerStats class which holds an STL list of ServerUser objects. The ServerStats class includes functions which can add and remove objects from the list as well as find a user in the list an return a pointer to them so I can access member functions within any given ServerUser object in the list.

The ServerUser class contains an STL list of ServerConnection objects and much like the ServerStats class it contains functions to add, remove and find elements within this list.

Now all of the above is working but I am now trying to make it threadsafe.

I have defined a Poco::FastMutex within the ServerStats class and can lock/unlock this in the appropriate places so that STL containers are not modified at the same time as being searched for example. I am however having an issue setting up mutexes within the ServerUser class and am getting the following compiler error:

/root/poco/Foundation/include/Poco/Mutex.h:
In copy constructor
âServerUser::ServerUser(const
ServerUser&)â:
src/SocksServer.cpp:185:
instantiated from âvoid
__gnu_cxx::new_allocator<_Tp>::construct(_Tp*,
const _Tp&) [with _Tp = ServerUser]â
/usr/include/c++/4.4/bits/stl_list.h:464:
instantiated from
âstd::_List_node<_Tp>* std::list<_Tp,
_Alloc>::_M_create_node(const _Tp&) [with _Tp = ServerUser, _Alloc =
std::allocator]â
/usr/include/c++/4.4/bits/stl_list.h:1407:
instantiated from âvoid std::list<_Tp,
_Alloc>::_M_insert(std::_List_iterator<_Tp>, const _Tp&) [with _Tp = ServerUser,
_Alloc = std::allocator]â /usr/include/c++/4.4/bits/stl_list.h:920:
instantiated from âvoid std::list<_Tp,
_Alloc>::push_back(const _Tp&) [with _Tp = ServerUser, _Alloc = std::allocator]â
src/SocksServer.cpp:301:
instantiated from here
/root/poco/Foundation/include/Poco/Mutex.h:164:
error:
âPoco::FastMutex::FastMutex(const
Poco::FastMutex&)â is private
src/SocksServer.cpp:185: error: within
this context In file included from
/usr/include/c++/4.4/x86_64-linux-gnu/bits/c++allocator.h:34,
from /usr/include/c++/4.4/bits/allocator.h:48,
from /usr/include/c++/4.4/string:43,
from /root/poco/Foundation/include/Poco/Bugcheck.h:44,
from /root/poco/Foundation/include/Poco/Foundation.h:147,
from /root/poco/Net/include/Poco/Net/Net.h:45,
from /root/poco/Net/include/Poco/Net/TCPServerParams.h:43,
from src/SocksServer.cpp:1:
/usr/include/c++/4.4/ext/new_allocator.h:
In member function âvoid
__gnu_cxx::new_allocator<_Tp>::construct(_Tp*,
const _Tp&) [with _Tp = ServerUser]â:
/usr/include/c++/4.4/ext/new_allocator.h:105:
note: synthesized method
âServerUser::ServerUser(const
ServerUser&)â first required here
src/SocksServer.cpp: At global scope:
src/SocksServer.cpp:118: warning:
âstd::string getWord(std::string)â
defined but not used make: ***
[/root/poco/SocksServer/obj/Linux/x86_64/debug_shared/SocksServer.o]
Error 1

The code for the ServerStats, ServerUser and ServerConnection classes is below:

class ServerConnection
{
public:
    bool continue_connection;
    int bytes_in;
    int bytes_out;
    string source_address;
    string destination_address;

    ServerConnection()
    {
        continue_connection = true;
    }

    ~ServerConnection()
    {
    }
};

class ServerUser
{
public:
    string username;
    int connection_count;
    string client_ip;

    ServerUser()
    {
    }

    ~ServerUser()
    {
    }

    ServerConnection* addConnection(string source_address, string destination_address)
    {
        //FastMutex::ScopedLock lock(_connection_mutex);

        ServerConnection connection;
        connection.source_address = source_address;
        connection.destination_address = destination_address;
        client_ip = getWord(source_address, ":");

        _connections.push_back(connection);
        connection_count++;

        return &_connections.back();
    }

    void removeConnection(string source_address)
    {
        //FastMutex::ScopedLock lock(_connection_mutex);

        for(list<ServerConnection>::iterator it = _connections.begin(); it != _connections.end(); it++)
        {
            if(it->source_address == source_address)
            {
                it = _connections.erase(it);
                connection_count--;
            }
        }
    }

    void disconnect()
    {    
        //FastMutex::ScopedLock lock(_connection_mutex);

        for(list<ServerConnection>::iterator it = _connections.begin(); it != _connections.end(); it++)
        {
            it->continue_connection = false;
        }
    }

    list<ServerConnection>* getConnections()
    {
        return &_connections;
    }

private:
    list<ServerConnection> _connections;

    //UNCOMMENTING THIS LINE BREAKS IT:
    //mutable FastMutex _connection_mutex;
};

class ServerStats
{
public:
    int current_users;

ServerStats()
{
    current_users = 0;
}

~ServerStats()
{
}

ServerUser* addUser(string username)
{
    FastMutex::ScopedLock lock(_user_mutex);

    for(list<ServerUser>::iterator it = _users.begin(); it != _users.end(); it++)
    {
        if(it->username == username)
        {
            return &(*it);
        }
    }

    ServerUser newUser;
    newUser.username = username;
    _users.push_back(newUser);
    current_users++;

    return &_users.back();
}

void removeUser(string username)
{
    FastMutex::ScopedLock lock(_user_mutex);

    for(list<ServerUser>::iterator it = _users.begin(); it != _users.end(); it++)
    {
        if(it->username == username)
        {
            _users.erase(it);
            current_users--;
            break;
        }
    }
}

ServerUser* getUser(string username)
{
    FastMutex::ScopedLock lock(_user_mutex);

    for(list<ServerUser>::iterator it = _users.begin(); it != _users.end(); it++)
    {
        if(it->username == username)
        {
            return &(*it);
        }
    }
    return NULL;
}

private:
    list<ServerUser> _users;
    mutable FastMutex _user_mutex;
};

Now I have never used C++ for a project of this size or mutexes for that matter so go easy please 🙂

Firstly, can anyone tell me why the above is causing a compiler error?

Secondly, can anyone suggest a better way of storing the information I require? Bear in mind that I need to update this info whenever connections come or go and it needs to be global to the whole server.

  • 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-14T20:08:15+00:00Added an answer on May 14, 2026 at 8:08 pm

    The problem is that FastMutex isn’t copyable, and consequently ServerUser isn’t copyable. When you insert objects into an STL container, they have to be copied. I think you will have to change the design of your classes.

    Also, you have to be really careful with returning pointers to objects which are stored in an STL container, because they can become invalid due to objects being reshuffled as you insert and remove things from the container.

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

Sidebar

Related Questions

I am currently writing a multi-user social iPhone app which interfaces with a server.
I'm currently writing a multi-process network game server (one gatekeeper process which tells players
I'm currently writing a large multi threaded C++ program (> 50K LOC). As such
In a multi-threaded program I'm writing a custom print function which accepts a variable
I am currently writing user interface in ember.js and need some help in server-side
I am currently writing a program using Weka that builds a model (using one
I'm currently writing a function what would create a zip file, which will be
I'm currently writing a billing application using EF 5 Code First, and I'm running
I'm currently writing several Python modules which perform some I/O. Thoses modules can be
I am currently writing a script which parses the ServiceTage, Computername and Username from

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.