@@ -26,16 +26,22 @@ Manager::~Manager() {
2626
2727void *worker_runner (void *socket_fd);
2828
29- void Manager::handle_request (int socket_fd) {
29+ union dCont {
30+ int ival;
31+ const char * strval;
32+ };
33+
34+ void Manager::handle_request (string client, int socket_fd) {
3035 this ->logger ->debug (" Creating new thread for request at socket: " + std::to_string (socket_fd));
3136
3237 // get worker, if available
3338 int worker_ind = this ->get_free_worker_index ();
3439
3540 // handle the requst in a new thread
36- int * params = (int *) malloc (2 *sizeof (int ));
37- params[0 ] = worker_ind;
38- params[1 ] = socket_fd;
41+ dCont * params = (dCont *) malloc (2 *sizeof (int ) + 16 *sizeof (char ));
42+ params[0 ].ival = worker_ind;
43+ params[1 ].ival = socket_fd;
44+ params[2 ].strval = client.c_str ();
3945 if (pthread_create (&this ->pool [worker_ind], NULL , worker_runner, (void *)params) < 0 ) {
4046 char * err = std::strerror (errno);
4147 throw Manager::Exception (" Error creating thread: " + std::string (err ? err : " unknown error" ));
@@ -62,13 +68,15 @@ int Manager::get_free_worker_index() {
6268}
6369
6470void *worker_runner (void *arg) {
65- int *params = (int *) arg;
66- int worker_ind = params[0 ];
67- int socket_fd = params[1 ];
71+ dCont *params = (dCont *) arg;
72+ int worker_ind = params[0 ].ival ;
73+ int socket_fd = params[1 ].ival ;
74+ string client = string (params[2 ].strval );
75+ free (params);
6876
6977 // start handling the request
7078 try {
71- Worker worker (socket_fd);
79+ Worker worker (client, socket_fd);
7280 worker.handle_request ();
7381 }
7482 catch (Worker::Exception &e) {
0 commit comments