int clientReadData(Client * client_p){ int recv_len = -2; int toread_len = 0; if (client_p == NULL) { ntLogging(LOG_WARNING,"client is empty"); return 0; } if (client_p->recv_msg == NULL) { client_p->recv_msg = ntmalloc(RECV_MAX_LENGTH); if (client_p->recv_msg == NULL){ ntLogging(LOG_WARNING,"malloc recv msg max length failed" ); return 0; } recv_len = ntread(client_p->fd, client_p->recv_msg, RECV_MAX_LENGTH); if (recv_len == -1){ if (errno == EAGAIN){ return -EAGAIN; }else{ ntLogging(LOG_WARNING,"error occoured error:%s", strerror(errno)); return -errno; } } else if (recv_len == 0 ){ ntLogging(LOG_WARNING,"client close socket, so delete client"); delClient(client_p); return ERR_DEL_CLIENT ; } client_p->recv_msg_len = recv_len; } else { //saved old DATA toread_len = RECV_MAX_LENGTH - client_p->recv_msg_len; recv_len = ntread(client_p->fd, client_p->recv_msg+client_p->recv_msg_len , toread_len); if (recv_len == -1){ if (errno == EAGAIN){ return -EAGAIN; }else{ ntLogging(LOG_WARNING,"error occoured error:%s", strerror(errno)); return -errno; } } else if (recv_len ==0 ){ ntLogging(LOG_WARNING,"client close socket"); } client_p->recv_msg_len += recv_len; if (client_p->recv_msg_len >= RECV_MAX_LENGTH){ ntLogging(LOG_WARNING,"the recv_msg is full, so delete client"); delClient(client_p); return ERR_DEL_CLIENT ; } } return recv_len; }
//------------------------------------------------------------------------------------- void Bots::handleGameTick() { // time_t t = ::time(NULL); // DEBUG_MSG("EntityApp::handleGameTick[%"PRTime"]:%u\n", t, time_); ClientApp::handleGameTick(); pEventPoller_->processPendingEvents(0.0); { AUTO_SCOPED_PROFILE("updateBots"); CLIENTS::iterator iter = clients().begin(); for(;iter != clients().end();) { Network::Channel* pChannel = iter->first; ClientObject* pClientObject = iter->second; ++iter; if(pClientObject->isDestroyed()) { delClient(pChannel); continue; } pClientObject->gameTick(); } } }
void writeCallback(struct eventLoop * eventLoop_p, int fd, void * clientData, int mask){ ntLogging(LOG_DEBUG,"in write callback" ); Client * cp = (Client *)clientData; HOOK_MODULES_WRITING(cp); clientWriteData(cp); // ntwriteEasyByCount(fd,"OK", 2); mask |= IO_READABLE|IO_WRITABLE; delIoEvent(eventLoop_p, fd, mask); HOOK_MODULES_DONE(cp); delClient(cp); }
/*! * \brief Mouvement d'amelioration de la solution : deplacement d'un sommet * * \param ind1 : indice du client a inserer * \param tour1 : tournee du client a inserer * \param ind2 : indice du client avant ou apres lequel on insere * \param tour2 : tournee du client avant ou apres lequel on insere * \param instance : instance sur laquelle on travaille. * \param avant : indique si l'on doit inserer avant ou apres ind2 * * \return 0 si c'est ok -1 sinon */ int Solution::shift(unsigned ind1, unsigned tour1, unsigned ind2, unsigned tour2, Instance * instance, bool avant) { sommet_t ** vect = instance->getVect(); int res = 0; int tmp; if (_load[tour2] + vect[ind1]->_demande <= instance->getCapacityV()) { // on recupere l'indice de tour1 tmp = delClient(ind1, vect, tour1); // s'il a ete modifie et que la deuxieme tournee est apres la premiere, la deuxieme tournee aussi est en dessous if (tmp != (int)tour1 && tour2 > tour1) --tour2; if (avant) { if (_first[tour2] != ind2) { if (faisable(instance, ind2, std::max(_depart[_pred[ind2]], vect[ind1]->_debut), avant)) { insertClient(ind1, ind2, tour2, avant, vect); } else res = -1; } else if (faisable(instance, ind2, vect[ind1]->_debut, avant)) { insertClient(ind1, ind2, tour2, avant, vect); } else res = -1; } else { if (faisable(instance, ind2, std::max(_depart[ind2], vect[ind1]->_debut) + vect[ind1]->_duree, avant)) { insertClient(ind1, ind2, tour2, avant, vect); } else res = -1; } } else res = -1; return res; }
bool Epoll::handle(int fd){ Client* client = _clients[fd]; if (client->isNew()) { // 新连接,需要websocket握手协议 if(client->openHandshake()) { std::stringstream msg; return true; } } std::string msg = client->receive(); if(msg == "-2" || msg == "-1" || msg == "0"){ epoll_ctl(_epfd, EPOLL_CTL_DEL, client->getFileDescripto(), &_evt); delClient(client); }else{ checkMessage(client, msg); } return true; }
/*! * \brief Mouvement d'amelioration de la solution : echange de deux sommets * * \param ind1 : indice du premier client * \param tour1 : tournee du premier client * \param ind2 : indice du deuxieme client * \param tour2 : tournee du deuxieme client * \param instance : instance sur laquelle on travaille. * * \return 0 si c'est ok -1 sinon */ int Solution::swap(unsigned ind1, unsigned tour1, unsigned ind2, unsigned tour2, Instance * instance) { sommet_t ** vect = instance->getVect(); int res = 0; //On regarde si ça colle au niveau des charges if (_load[tour1] - vect[ind1]->_demande + vect[ind2]->_demande > instance->getCapacityV()) res = -1; if (!res && _load[tour2] - vect[ind2]->_demande + vect[ind1]->_demande > instance->getCapacityV()) res = -1; // On regarde si ça colle au niveau des fenetres de temps // si c'est le premier ça colle forcement au niveau du temps, sinon on regarde le pred if (!res && _pred[ind2] != 0 && _depart[_pred[ind2]] > vect[ind1]->_fin) res = -1; if (!res && _pred[ind1] != 0 && _depart[_pred[ind1]] > vect[ind2]->_fin) res = -1; // si c'est le dernier ça colle forcement aussi if (!res && _succ[ind1] != 0 && vect[ind2]->_debut > vect[_succ[ind1]]->_fin) res = -1; if (!res && _succ[ind2] != 0 && vect[ind1]->_debut > vect[_succ[ind2]]->_fin) res = -1; if (!res) { // sauvegarde des suivants et precedants unsigned savep1 = _pred[ind1]; unsigned saven1 = _succ[ind1]; unsigned savep2 = _pred[ind2]; unsigned saven2 = _succ[ind2]; // a supprimer bool toDel1 = false; bool toDel2 = false; if (_nbClt[tour1] != 1) delClient(ind1, vect, tour1); else toDel1 = true; if (_nbClt[tour2] != 1) delClient(ind2, vect, tour2); else toDel2 = true; bool avant = true; if (saven1 == 0) { saven1 = savep1; savep1 = _pred[savep1]; avant = false; } if (toDel1) { _pred[ind2] = 0; _succ[ind2] = 0; _first[tour1] = ind2; _last[tour1] = ind2; } else { if (faisable(instance, saven1, std::max(_depart[savep1], vect[ind2]->_debut), avant)) { if (saven1 != 0) insertClient(ind2, saven1, tour1, true, vect); else insertClient(ind2, _last[tour1], tour1, false, vect); } else res = -1; } avant = true; if (saven2 == 0) { saven2 = savep2; savep2 = _pred[savep2]; avant = false; } if (toDel2) { _pred[ind1] = 0; _succ[ind1] = 0; _first[tour2] = ind1; _last[tour2] = ind1; } else { if (faisable(instance, saven2, std::max(_depart[savep2], vect[ind1]->_debut), avant)) { if (saven2 != 0) insertClient(ind1, saven2, tour2, true, vect); else insertClient(ind1, _last[tour2], tour2, false, vect); } else res = -1; } } return res; }
void AnopeFini(void) { delClient(); }