void TgtTelnetIntf::tgtReadCallback(const boost::system::error_code& error, const size_t bytesTransferred) { if (!error) { boost::asio::mutable_buffer buffer; if (bytesTransferred > 0) { if (_currentIncomingBuffer != nullptr) { _currentIncomingBuffer->_buffer = boost::asio::buffer(_currentIncomingBuffer->_buffer, bytesTransferred); boost::intrusive_ptr<RefCntBuffer> readData; _bufferPool->dequeue(readData, 100); if (readData != nullptr) { int numBytes = tgtTelnetProcessData(readData); if (numBytes > 0) { readData->_buffer = boost::asio::buffer(readData->_buffer, numBytes); _incomingData.enqueue(readData); } } } _bufferPool->dequeue(_currentIncomingBuffer, 100); } if (_currentIncomingBuffer == nullptr) { // If there are no buffers available then just throw away the next // bit if incoming data... buffer = boost::asio::buffer(_throwAway, sizeof(_throwAway) - 1); } else { buffer = _currentIncomingBuffer->_buffer; } _socket->async_read_some(boost::asio::buffer(buffer, boost::asio::buffer_size(buffer) - 1), boost::bind(&TgtTelnetIntf::tgtReadCallback, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); } else { tgtAttemptReconnect(); } }
bool TgtSerialIntf::writerThread() { boost::intrusive_ptr<RefCntBuffer> b; boost::system::error_code ec; bool attemptReconnect = false; if (_outgoingData.dequeue(b, 100) == true) { boost::asio::write(*_port.get(), boost::asio::buffer(b->_buffer), ec); if (ec) { attemptReconnect = true; } } if (attemptReconnect == true) { tgtAttemptReconnect(); } return !attemptReconnect; }
bool TgtCppsshIntf::sshThread() { bool attemptReconnect = false; if ((isConnected() == false) || (sshSend() == false) || (sshRecv() == false)) { attemptReconnect = true; _sshData->_connected = false; } else if (_sshData->_windowResize == true) { tgtWindowResize(_sshData->_columns, _sshData->_rows); } if (attemptReconnect == true) { tgtAttemptReconnect(); _sshData->_windowResize = true; } return !attemptReconnect; }
void TgtSerialIntf::tgtReadCallback(const boost::system::error_code& error, const size_t bytesTransferred) { if (!error) { boost::asio::mutable_buffer buffer; if (bytesTransferred > 0) { if (_currentIncomingBuffer != nullptr) { _currentIncomingBuffer->_buffer = boost::asio::buffer(_currentIncomingBuffer->_buffer, bytesTransferred); _incomingData.enqueue(_currentIncomingBuffer); } _bufferPool->dequeue(_currentIncomingBuffer, 100); } if (_currentIncomingBuffer == nullptr) { // If there are no buffers available then just throw away the next // bit if incoming data... buffer = boost::asio::buffer(_throwAway, sizeof(_throwAway) - 1); } else { buffer = _currentIncomingBuffer->_buffer; } _port->async_read_some(boost::asio::buffer(buffer, boost::asio::buffer_size(buffer) - 1), boost::bind(&TgtSerialIntf::tgtReadCallback, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); } else { tgtAttemptReconnect(); } }