예제 #1
0
 THREAD_ROUTINE_RETURN SocketServer::HandleConnections(void* data)
 {
    SocketServer* server = (SocketServer*) data;
    std::vector<SocketServer::Connection*> clients;
    struct sockaddr_storage client_addr;
    socklen_t addr_size = sizeof(client_addr);
    MutexHandle lock;
    mutexCreate(&lock);
    int client_socket;

    while (!server->shutdown_) {
      if ((client_socket = accept(server->socket_, (struct sockaddr*)&client_addr, &addr_size)) > 0) {
        clients.push_back(new jsonrpc::SocketServer::Connection());
        clients.back()->socket = client_socket;
        clients.back()->pserver = server;
        clients.back()->plock_server = &lock;
        CloseFinishedConnections(clients);
        if (clients.size() > server->poolSize_) {
          CloseOldestConnection(clients);
        }
        threadCreate(&clients.back()->thread, (ThreadStartRoutine)ConnectionHandler, clients.back());
      }
    }
    CloseAllConnections(clients);
    mutexDestroy(&lock);
    return 0;
  }
예제 #2
0
void ShutdownCipStack(void) {
  /* First close all connections */
  CloseAllConnections();
  /* Than free the sockets of currently active encapsulation sessions */
  EncapsulationShutDown();
  /*clean the data needed for the assembly object's attribute 3*/
  ShutdownAssemblies();

  ShutdownTcpIpInterface();

  /*no clear all the instances and classes */
  DeleteAllClasses();
}
예제 #3
0
void CTCPStunThread::SweepDeadConnections()
{
    time_t timeCurrent = time(NULL);
    StunThreadConnectionMap* pSwap = NULL;
    
    // should we try to scale the timeout based on the active number of connections?
    
    if ((timeCurrent - _timeLastSweep) >= c_sweepTimeoutSeconds)
    {
        if  (_pOldConnList->Size())
        {
            Logging::LogMsg(LL_VERBOSE, "SweepDeadConnections closing %d connections", _pOldConnList->Size());
        }
        
        CloseAllConnections(_pOldConnList);
        
        _timeLastSweep = time(NULL);
        
        
        pSwap = _pOldConnList;
        _pOldConnList = _pNewConnList;
        _pNewConnList = pSwap;
    }
}
예제 #4
0
void CTCPStunThread::ThreadCleanup()
{
    CloseAllConnections(_pOldConnList);
    CloseAllConnections(_pNewConnList);
}
예제 #5
0
		//--------------------------------------------
		//--------------------------------------------
		Timer::~Timer()
		{
            CloseAllConnections();
		}
예제 #6
0
void
ProcSqlite::real_run()
{

    I_AM_READY;

    BOOL shutdown_flag = FALSE;
    while(shutdown_flag == FALSE)
    {

        ApiErrorCode res = API_SUCCESS;
        IwMessagePtr msg = _inbound->Wait( Seconds(60), res);

        switch (res)
        {
        case API_TIMEOUT:
        {
            LogInfo("Sqlite keep alive.");
            continue;
        }
        case API_SUCCESS:
        {
            break;
        }
        default:
        {
            LogCrit("Error wating for messages");
            shutdown_flag = TRUE;
            continue;;
        }
        }

        switch (msg->message_id)
        {
        case MSG_PROC_SHUTDOWN_REQ:
        {
            SendResponse(msg,new MsgShutdownAck());
            shutdown_flag = TRUE;
            continue;
        }
        case MSG_SQL_OPEN_CONNECTION_REQ:
        {
            UponSqlOpenConnectionReq(msg);
            break;
        }
        case MSG_SQL_CLOSE_CONNECTION_REQ:
        {
            UponSqlCloseConnectionReq(msg);
            break;
        }
        case MSG_SQL_FINALIZE_REQ:
        {
            UponSqlFinalizeReq(msg);
            break;
        }
        case MSG_SQL_EXEC_REQ:
        {
            UponSqlExecReq(msg);
            break;
        }
        case MSG_SQL_STEP_REQ:
        {
            UponSqlStepReq(msg);
            break;
        }
        default:
        {
            BOOL res = HandleOOBMessage(msg);
            if (res == FALSE)
            {
                LogCrit("Unknown msg:" << msg->message_id);
                shutdown_flag = TRUE;
                continue;;
            }
        }
        }
    } //while

    CloseAllConnections();
}
예제 #7
0
void CloseNetwork()
{
	if (IsNetworkRunning())
	{
		QString strNetCloseFile, strNetCloseArgs;
		bool bContinue = true;
		int iErrorCode;

		// stop clients, server
		CloseAllConnections();
		if (g_pMainWindow != NULL)
			g_pMainWindow->m_pNetworkManager->UpdateClientTable();
		if (!g_mapClients.empty())
			return;

		StopServer();
		if (g_pServer != NULL)
			return;

		g_pLogger->LogInfo("Closing Network Interface...");
		signal(SIGPIPE, g_pOldSigPipeHandler);

		/*if (g_strDeviceType.compare("denso") == 0)
			g_bNetworkEnabled = !CloseDensoUnit();
		*/
		strNetCloseFile = g_pSettings->m_sSettings[SETTINGS_NETWORK_CLOSEFILE_NUM].GetValue().strValue;
		if (!g_bNetworkEnabled && !strNetCloseFile.isEmpty())
		{
			strNetCloseArgs = g_pSettings->m_sSettings[SETTINGS_NETWORK_CLOSEARGS_NUM].GetValue().strValue;

			strNetCloseArgs.replace("%dn", g_strDeviceName);
			strNetCloseArgs.replace("%dt", g_strDeviceType);
			strNetCloseArgs.replace("%ip", IPAddressToString(g_ipAddress));
			strNetCloseArgs.replace("%sub", IPAddressToString(g_ipSubnet));
			strNetCloseArgs.replace("%txp", QString::number(g_iTXPower));
			strNetCloseArgs.replace("%txr", QString::number(g_iTXRate));

			if (!strNetCloseArgs.isEmpty())
				strNetCloseFile += " " + strNetCloseArgs;

			while (bContinue)
			{
				iErrorCode = system(strNetCloseFile);
				if (iErrorCode == 0) {
					g_bNetworkEnabled = false;
					bContinue = false;
				} else
					bContinue = g_pLogger->PromptLogError(PACKAGE_TITLE, QString("Could not close network interface (code %1)").arg(iErrorCode), false);
			}
		}
		else
			g_bNetworkEnabled = false;

		if (g_bNetworkEnabled) {
			g_pLogger->LogInfo("Failed\n");
			return;
		} else
			g_pLogger->LogInfo("Successful\n");

		if (g_pMainWindow != NULL)
		{
			g_pMainWindow->m_pNetInit->setMenuText("&Initialize");
			g_pMainWindow->m_pNetInit->setToolTip("Initialize network devices and connections");
			g_pMainWindow->m_pNetClose->setEnabled(false);
			g_pMainWindow->m_pNetMenu->setItemEnabled(g_pMainWindow->m_iNetServerMenuID, false);
			g_pMainWindow->m_pNetworkManager->SetNetworkInitialized(false);
		}
	}
}