void ServerConnectionAdapter::badMessage(BadMessageException& e) { fprintf(stdout, "[NT] Bad message: %s\n", e.what()); fflush(stdout); gotoState(new ServerConnectionState_Error(e)); adapterListener.close(*this, true); m_IsAdapterListenerClosed=true; if (readThread) { readThread->stop(); } }
void ServerConnectionAdapter::clientHello(ProtocolVersion protocolRevision) { if(connectionState!=&ServerConnectionState::GOT_CONNECTION_FROM_CLIENT) throw BadMessageException("A server should not receive a client hello after it has already connected/entered an error state"); if(protocolRevision!=NetworkTableConnection::PROTOCOL_REVISION){ connection.sendProtocolVersionUnsupported(); throw BadMessageException("Client Connected with bad protocol revision"); } else{ entryStore.sendServerHello(connection); gotoState(&ServerConnectionState::CONNECTED_TO_CLIENT); } }
void ClientConnectionAdapter::serverHelloComplete() { if (connectionState==&ClientConnectionState::CONNECTED_TO_SERVER) { try { gotoState(&ClientConnectionState::IN_SYNC_WITH_SERVER); entryStore.sendUnknownEntries(*connection); } catch (IOException& e) { ioException(e); } } else throw BadMessageException("A client should only receive a server hello complete once and only after it has connected to the server"); }
/** * Close the connection to the server and enter the given state * @param newState */ void ClientConnectionAdapter::close(ClientConnectionState* newState) { { Synchronized sync(LOCK); gotoState(newState); if(readThread!=NULL){ readThread->stop(); readThread = NULL; } if(connection!=NULL){ connection->close(); connection = NULL; } entryStore.clearIds(); } }
/** * Reconnect the client to the server (even if the client is not currently connected) */ void ClientConnectionAdapter::reconnect() { { Synchronized sync(LOCK); close();//close the existing stream and monitor thread if needed try{ IOStream* stream = streamFactory.createStream(); if(stream==NULL) return; connection = new NetworkTableConnection(stream, typeManager); readThread = threadManager.newBlockingPeriodicThread(new ConnectionMonitorThread(*this, *connection), "Client Connection Reader Thread"); connection->sendClientHello(); gotoState(&ClientConnectionState::CONNECTED_TO_SERVER); } catch(IOException& e){ close();//make sure to clean everything up if we fail to connect } } }
bool Parser::reduce(ParserActionReduce* const r) { if (r == 0) return false; const int productionID = r->getProductionID(); ProductionStub* prod = findProduction(productionID); if (prod == 0) { log_ << "fatal error: there is no production with ID = " << productionID << "!\n"; return false; } bool result = true; const std::list<int>& body = prod->getBodyIDs(); std::vector<ParserSymbol*> removedSymbols; for (std::list<int>::const_reverse_iterator it = body.rbegin(); it != body.rend(); ++it) { if (! states_.empty()) states_.pop(); else { log_ << "fatal error: stack is empty!\n"; result = false; } if (! symbols_.empty()) { if ((*(symbols_.top()) != *it) && (! isProxySymbol(*it, symbols_.top()->getSymbolID())) ) { log_ << "fatal error: top symbol ('" << symbolID2String(symbols_.top()->getSymbolID()); log_ << "') does not match the symbol in the production's body ('"; log_ << symbolID2String(*it) << "')\n"; log_ << "ProdcutionID = " << productionID << "\n"; result = false; } // Attention: this reverses the order of the symbols from the stack! // removedSymbols.push_back(symbols_.top()); symbols_.pop(); } } symbols_.push(new ParserSymbol(prod->getHeadID())); const int nextState = gotoState(states_.top(), prod->getHeadID()); if (nextState >= 0) states_.push(nextState); else { log_ << "fatal: no following state found for state "; log_ << states_.top() << " and symbol " << symbolID2String(prod->getHeadID()) << "\n"; result = false; } delete prod; if (result == true) expandParseTree(productionID, removedSymbols); for (size_t i = 0; i < removedSymbols.size(); ++i) delete removedSymbols[i]; return result; }
void ClientConnectionAdapter::protocolVersionUnsupported(ProtocolVersion protocolRevision) { close(); gotoState(new ClientConnectionState_ProtocolUnsuppotedByServer(protocolRevision)); }