/*!  Poll target to check run status
 *
 */
void GdbServerWindow::pollTarget() {
   static GdbTargetStatus lastTargetStatus = T_UNKNOWN;

   // Get status without polling target
   targetStatus = getGdbTargetStatus();
   switch (targetStatus) {
      case T_RUNNING:
      case T_SLEEPING:
         // Actually poll the target
         targetStatus = gdbPollTarget();
         // Set up next polling time
         statusTimer->Start(pollIntervalFast, wxTIMER_ONE_SHOT);
         break;
      case T_NOCONNECTION:
         Logging::print("GdbServerWindow::pollTarget() - T_NOCONNECTION\n");
         dropConnection();
         break;
      case T_UNKNOWN:
      case T_HALT:
         // Don't poll while not running
         break;
   }
   if (targetStatus != lastTargetStatus) {
      if (targetStatus == T_NOCONNECTION) {
         Logging::print("GdbServerWindow::pollTarget(), status changed to T_NOCONNECTION\n");
      }
      UpdateStatusBar();
   }
   lastTargetStatus = targetStatus;
}
void CNetworkClient::run()
{
	while(1)
	{
		{
			QMutexLocker lock( &m_mutex );
			QHostAddress hostAddr( m_ip );

			if ( !m_socket->isOpen () || !(m_socket->state() == QAbstractSocket::ConnectedState) )
			{
				m_socket->connectToHost( hostAddr, m_port );
				if ( !m_socket->waitForConnected( m_timeout ) )
				{
					return;
				}
			}

			write();
			read();
		}
		MilliSleep( m_sleepTime );

		{
			// how to exit 100% safe, this  is not  the way to go for sure
			QMutexLocker lock( &m_mutex );
			if ( dropConnection() )
			{
				m_socket->disconnectFromHost();
				break;
			}
		}
	}
}
 */void GdbServerWindow::OnCloseWindow(wxCloseEvent& event) {
   if (!event.CanVeto() || confirmDropConnection())  {
      Logging::print("GdbServerWindow::OnCloseWindow()\n");
      dropConnection();
      this->Destroy();
   }
   else {
      event.Veto();
   }
}
void GdbServerWindow::closeServer() {
   Logging::print("GdbServerWindow::closeServer()\n");

   dropConnection();

   if (serverSocket != NULL) {
      statusTextControl->AppendText(_("Stopping Server\n"));
      serverSocket->Destroy();
      serverSocket = NULL;
   }
   serverState = idle;
   UpdateStatusBar();
}
Example #5
0
 void timeoutExpired() noexcept override {
   VLOG(4) << "SSL handshake timeout expired";
   sslError_ = SSLErrorEnum::TIMEOUT;
   dropConnection();
 }
/*!
 *  Handler for Socket events (after connection)
 *
 *  - Only expects:
 *    - wxSOCKET_INPUT - New data
 *    - wxSOCKET_LOST  - Connection dropped
 *
 *  @param event Event to handle
 */
void GdbServerWindow::OnSocketEvent(wxSocketEvent& event) {

   if (event.GetSocket() != clientSocket) {
      statusTextControl->AppendText(_("Event from unknown socket\n"));
      return;
   }
   // Now we process the event
   switch(event.GetSocketEvent()) {
      case wxSOCKET_INPUT: {
         if (clientSocket != NULL) {
            clientSocket->SetNotify(wxSOCKET_LOST_FLAG);
         }
         if (deferredOpen) {
            // Open on first access after socket creation
            deferredOpen = false;

            USBDM_ErrorCode rc = shared->initBdm();
            if (rc != BDM_RC_OK) {
               reportError("BDM Open failed, reason: ", M_FATAL, rc);
               statusTextControl->AppendText(_("BDM Open failed\n"));
               Logging::print("GdbServerWindow::OnSocketEvent() - BDM Open failed\n");
               dropConnection();
               return;
            }

            gdbInOut = new GdbInOutWx(clientSocket, statusTextControl);
            GdbCallback cb = GdbMessageWrapper::getCallBack(this);

            rc = gdbHandlerInit(gdbInOut, *shared->getCurrentDevice(), cb);
            if (rc != BDM_RC_OK) {
               reportError("GDB Handler initialisation failed, reason: ", M_FATAL, rc);
               Logging::print("GdbServerWindow::OnSocketEvent() - GDB Handler initialisation failed\n");
               dropConnection();
               return;
            }
            statusTextControl->AppendText(_("BDM Open OK\n"));
         }
         // Triggers read of socket
         const GdbPacket *packet;
         USBDM_ErrorCode rc = BDM_RC_OK;
         do {
            // Process packets from GDB until idle
            packet = gdbInOut->getGdbPacket();
            if (packet != NULL) {
               rc = doGdbCommand(packet);
               if (rc != BDM_RC_OK) {
                  statusTextControl->AppendText(wxString(USBDM_GetErrorString(rc),wxConvUTF8));
               }
            }
         } while ((packet != NULL) && (rc == BDM_RC_OK) && !deferredFail);

         if (deferredFail) {
            // A fatal error was reported - drop connection
            Logging::print("GdbServerWindow::OnSocketEvent() - deferredFail\n");
            dropConnection();
         }
         else {
            // Poll target immediately (also adjusts polling rate)
            pollTarget();
         }
         if (clientSocket != NULL) {
            clientSocket->SetNotify(wxSOCKET_LOST_FLAG | wxSOCKET_INPUT_FLAG);
         }
         break;
      }
      case wxSOCKET_LOST: {
         serverState = listening;
         Logging::print("GdbServerWindow::OnSocketEvent() - wxSOCKET_LOST\n");
         dropConnection();
         break;
      }
      default:
         statusTextControl->AppendText(_("Unexpected event on socket!\n"));
         break;
   }
   UpdateStatusBar();
}
/*!  Handler for Drop connection menu item
 *
 */
void GdbServerWindow::OnDropConnection(wxCommandEvent& WXUNUSED(event)) {
   if ((clientSocket != NULL) && confirmDropConnection()) {
      Logging::print("GdbServerWindow::OnDropConnection()\n");
      dropConnection();
   }
}