void TgtSerialIntf::tgtMakeConnection() { std::shared_ptr<const TgtConnectionConfig> connectionConfig = std::dynamic_pointer_cast<const TgtConnectionConfig>( _connectionConfig); //_service.reset(new boost::asio::io_service()); _port.reset(new boost::asio::serial_port(_service, connectionConfig->_portName)); _port->set_option(connectionConfig->_baudRate); _port->set_option(connectionConfig->_parity); _port->set_option(connectionConfig->_byteSize); _port->set_option(connectionConfig->_stopBits); _port->set_option(connectionConfig->_flowControl); _serialWriterThread = TgtThread::create(boost::protect(std::bind(&TgtSerialIntf::writerThread, this))); _serialServiceThread = TgtThread::create(boost::protect(std::bind(&TgtSerialIntf::serviceThread, this))); boost::system::error_code err; _bufferPool->dequeue(_currentIncomingBuffer); tgtReadCallback(err, 0); }
void TgtTelnetIntf::tgtMakeConnection() { std::shared_ptr<const TgtConnectionConfig> connectionConfig = std::dynamic_pointer_cast<const TgtConnectionConfig>( _connectionConfig); std::vector<boost::asio::ip::address> addresses; boost::asio::ip::tcp::resolver resolver(_socketService); boost::asio::ip::tcp::resolver::query query(connectionConfig->_hostName, "http"); boost::asio::ip::tcp::resolver::iterator endpointIterator = resolver.resolve(query); boost::asio::ip::tcp::resolver::iterator end; boost::asio::ip::tcp::endpoint endpoint; boost::system::error_code error; while (endpointIterator != end) { endpoint = *endpointIterator; addresses.push_back(endpoint.address()); #ifdef QT_DEBUG qDebug("addr: %s", endpoint.address().to_string().c_str()); #endif endpointIterator++; } _telnetServiceThread = TgtThread::create(boost::protect(std::bind(&TgtTelnetIntf::serviceThread, this))); for (std::vector<boost::asio::ip::address>::iterator it = addresses.begin(); ((it != addresses.end()) && (_abortConnection == false)); it++) { endpoint = boost::asio::ip::tcp::endpoint(*it, connectionConfig->_portNum); if (_socket != nullptr) { _socket->close(); } _socket.reset(new boost::asio::ip::tcp::socket(_socketService)); _socket->open(boost::asio::ip::tcp::v4()); clearConnectionQueue(); _socket->async_connect(endpoint, boost::bind( &TgtTelnetIntf::connectionHandler, this, boost::asio::placeholders::error)); bool done; do { done = _connectionQueue.dequeue(error, 1); if (_abortConnection == true) { break; } } while (done == false); if (!error) { break; } } if (error) { std::stringstream s; s << "Unable to connect to '" << connectionConfig->_hostName << ":" << connectionConfig->_portNum << "' (" << error << ")"; throw CB_EXCEPTION_STR(CBException::CbExcp, s.str().c_str()); } _socket->non_blocking(true); _telnetWriterThread = TgtThread::create(boost::protect(std::bind(&TgtTelnetIntf::writerThread, this))); boost::system::error_code err; _bufferPool->dequeue(_currentIncomingBuffer); tgtReadCallback(err, 0); }