예제 #1
0
파일: utils.c 프로젝트: Earlz/microforth
int strlcmpt(const char* str1, const char* str2, bool (*terminating)(char c))
{
  int i=0;
  while(!terminating(str1[i]) && !terminating(str2[i]))
  {
    if(str1[i] != str2[i])
    {
      return 1;
    }
    i++;
  }
  return 0;
}
예제 #2
0
void GenericThread::terminate() {
    if (_isThreaded) {
        _stopThread = true;
        
        terminating();

        if (_thread) {
            _thread->wait();
            _thread->deleteLater();
            _thread = NULL;
        }
    }
}
예제 #3
0
    void SocketConnector::run (void)
    {
        started();

        while (!terminationRequested()) {
            TCPSocket * const pSocket = dynamic_cast<TCPSocket * const> (_pServerSocket->accept());
            if (!pSocket) {
                if (!terminationRequested()) {
                    checkAndLogMsg ("SocketConnector::run", Logger::L_MildError,
                                    "accept() on ServerSocket failed with error %d\n",
                                    _pServerSocket->error());
                    setTerminatingResultCode (-1);
                }
                break;
            }
            pSocket->bufferingMode (0);

            ConnectorAdapter * const pConnectorAdapter = ConnectorAdapter::ConnectorAdapterFactory (pSocket);
            Connection * const pConnection = new Connection (pConnectorAdapter, this);

            _mConnectionsTable.lock();
            pConnection->lock();
            Connection * const pOldConnection = _connectionsTable.put (generateUInt64Key (InetAddr (pSocket->getRemoteHostAddr(), pSocket->getRemotePort())), pConnection);
            _mConnectionsTable.unlock();
            if (pOldConnection) {
                // There was already a connection from this node to the remote node - close that one
                checkAndLogMsg ("SocketConnector::run", Logger::L_Info,
                                "replaced an old SocketConnection to <%s:%hu> in status %hu with a new one\n",
                                pConnection->getRemoteProxyInetAddr()->getIPAsString(), pConnection->getRemoteProxyInetAddr()->getPort(),
                                pOldConnection->getStatus());
                delete pOldConnection;
            }
            else {
                checkAndLogMsg ("SocketConnector::run", Logger::L_Info,
                                "accepted a new SocketConnection from <%s:%hu>\n",
                                pConnection->getRemoteProxyInetAddr()->getIPAsString(),
                                pConnection->getRemoteProxyInetAddr()->getPort());
            }

            pConnection->startMessageHandler();
            pConnection->unlock();
        }
        checkAndLogMsg ("SocketConnector::run", Logger::L_Info,
                        "SocketConnector terminated; termination code is %d\n", getTerminatingResultCode());

        Connector::_pConnectionManager->deregisterConnector (_connectorType);

        terminating();
        delete this;
    }