Hi, I am making a simple tcp (Nagle's off) multi-client server.
I have player objects which contain the SOCKET that they connect to the client via.
In the server's main loop I am inputting the listen socket and all the player sockets into a fd_set and having select() output the fd_set of players which can recv() from their socket.
After doing that I need a way to relate the resultant fd_set back to the player object to perform actions with the associated object.
I think using a hash table via std::map is a good way, but am I missing a more obvious solution? Also, my players object pointers are stored in a std::list, do their pointers remain constant? And do vectors and other stl containers differ from lists in that way - lists don't store the array in contiguous memory as a way of offering constant pointers and speeding up internal deletion/insertion?
I am going to start implementing a std::map for now because I think it is the best strategy but I am not totally sure. IE. the map key template is SOCKET and the value template is a pointer to the player objects (as taken from the std::list of player objects). I don't want to end up with memory leaks or pointer inconsistency, and that is why I have asked here if I am doing it properly.
Thanks for the help, gamedev.net is down
I have player objects which contain the SOCKET that they connect to the client via.
In the server's main loop I am inputting the listen socket and all the player sockets into a fd_set and having select() output the fd_set of players which can recv() from their socket.
After doing that I need a way to relate the resultant fd_set back to the player object to perform actions with the associated object.
I think using a hash table via std::map is a good way, but am I missing a more obvious solution? Also, my players object pointers are stored in a std::list, do their pointers remain constant? And do vectors and other stl containers differ from lists in that way - lists don't store the array in contiguous memory as a way of offering constant pointers and speeding up internal deletion/insertion?
I am going to start implementing a std::map for now because I think it is the best strategy but I am not totally sure. IE. the map key template is SOCKET and the value template is a pointer to the player objects (as taken from the std::list of player objects). I don't want to end up with memory leaks or pointer inconsistency, and that is why I have asked here if I am doing it properly.
Thanks for the help, gamedev.net is down
