void Server::addClient(Client *c) { unsigned int num = UINT_MAX; worklist *wtmp = NULL; Worker *work; pthread_mutex_lock(&mutex); unsigned int size = workers.size(); for(int i=0; i < size;i++) { wtmp = &workers.front(); if(wtmp->w->getNum() < num) { work = wtmp->w; num = wtmp->w->getNum(); } workers.pop_front(); workers.push_back(*wtmp); } printf("WORKER ID:%d\n", work->getID()); pthread_mutex_unlock(&mutex); work->addClient(c); }
void worker_cb(evutil_socket_t evs, short events, void *ptr) { /* Last parameter is a worker object */ Worker *wrk = (Worker *)ptr; /* Receive client descriptor */ int client_fd = wrk->receiveDescriptor(evs); if (client_fd != -1) { /* Add client to worker process */ wrk->addClient(client_fd); } }