int Drawboard::send(int fd,uint8_t *data, uint32_t datalen) { const int written = ::send(fd, (const char *)data, datalen,0); #ifdef DEBUG std::cout << "Written " << written << " bytes to client" << std::endl; #endif if (written == SOCKET_ERROR) { #ifdef WIN32 #define ERROR_NUMBER WSAGetLastError() if ((ERROR_NUMBER != WSATRY_AGAIN && ERROR_NUMBER != WSAEINTR && ERROR_NUMBER != WSAEWOULDBLOCK)) #else #define ERROR_NUMBER errno if ((errno != EAGAIN && errno != EINTR)) #endif { #ifdef DEBUG std::cout << "Error writing to client, tried to write " << std::endl; #endif remClient(fd); return -1; } } return 1; }
void ChatServer::run() { while (true) { vector<struct pollfd>* fds = _getPollFds(); int revents = poll(fds->data(), fds->size(), -1); int handled = 0; for (vector<struct pollfd>::iterator i = fds->begin(); i != fds->end() && handled < revents; ++i) { if (i->revents != 0) { ++handled; if (i->fd == _server->getFd()) { // cout << "add new client" << endl; addClient(accept(_server->getFd(), NULL, NULL)); } else { Client* c = _clients[i->fd]; if (c->readNext() == false) { remClient(c->getSocket()->getFd()); // cout << "removed old client" << endl; } else { Command* cmd = c->getCommand(); if (cmd != NULL) { // cout << "execute command" << endl; cmd->execute(this); } } } } } delete fds; } }
void CHostIce::removeClient( const std::string & id, const ::Ice::Current & c ) { IceUtil::Mutex::Lock lock( m_mut ); QLOG_TRACE() << "removeClient( " << QString::fromStdString( id ) << " )"; remClient( id ); sendClientList( c ); }