Exemplo n.º 1
0
void  processInputBuffer(ugClient *c) {
    while(sdslen(c->querybuf)) {
        if (c->flags & UG_CLOSE_AFTER_REPLY) return;

        /* Determine request type when unknown. */
        if (!c->reqtype) {
            if (c->querybuf[0] == '*') {
                c->reqtype = UG_REQ_MULTIBULK;
            } else {
                c->reqtype = UG_REQ_INLINE;
            }
        }

        if (c->reqtype == UG_REQ_INLINE) {
            if (processLineBuffer(c) != UGOK) break;
        } else if (c->reqtype == UG_REQ_MULTIBULK) {
            if (processMultbuff(c) != UGOK) break;
        } else {
            ugPanic("Unknown request type");
        }

        if (c->argc == 0) {
            resetClient(c);
        } else {
            if (processCommand(c) == UGOK) {
                resetClient(c);
            }
        }

    }
}
Exemplo n.º 2
0
void sendReplyToClient(aeEventLoop *el, int fd, httpClient *c) {
    int nwritten = 0;

    CCACHE_NOTUSED(el);    
    if(c->rep) {
        sds obuf = replyToBuffer(c->rep);
        int towrite = sdslen(obuf) - c->bufpos;
        nwritten = write(fd, obuf+c->bufpos,towrite);
        /* Content */
        if (nwritten == -1) {
            if (errno == EAGAIN) {
                nwritten = 0;
            } else {
                ulog(CCACHE_VERBOSE,
                     "Error writing to client: %s", strerror(errno));
                freeClient(c);
                return;
            }
        }
        c->lastinteraction = time(NULL);
        listMoveNodeToTail(el->clients,c->elNode);
        if(nwritten<towrite) {
            c->bufpos += nwritten;
        }
        else {
#ifdef AE_MAX_CLIENT_IDLE_TIME
            resetClient(c);
#else
            freeClient(c);
#endif
            aeModifyFileEvent(el,c->fd,AE_READABLE,c);
            printf("Send Reply: %.2lf\n", (double)(clock()));
        }
    }
}
Exemplo n.º 3
0
static void
processInputBuffer (client_t * c)
{
  while (sdslen (c->querybuf))
    {
      if (!c->reqtype)
	{
	  if (c->querybuf[0] == '*')
	    {
	      c->reqtype = REDIS_REQ_MULTIBULK;
	    }
	  else
	    {
	      c->reqtype = REDIS_REQ_INLINE;
	    }
	}

      if (c->reqtype == REDIS_REQ_MULTIBULK)
	{
	  if (processMultiBulk (c) == -1)
	    return;
	}
      else
	{
	  if (processInline (c) == -1)
	    return;
	}
      resetClient (c);
    }
}
Exemplo n.º 4
0
void MainController::signOut() {
	if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
		purgeCachedCredentials();
	}
	eventController_->clear();
	logout();
	loginWindow_->loggedOut();
	resetClient();
}
Exemplo n.º 5
0
void MainController::handleQuitRequest() {
	if (client_ && client_->isActive()) {
		quitRequested_ = true;
		client_->disconnect();
	}
	else {
		resetClient();
		loginWindow_->quit();
	}
}
Exemplo n.º 6
0
static void
freeClient (client_t * c)
{
  sdsfree (c->querybuf);
  sdsfree (c->replybuf);
  arc_free_request (c->rqst);
  resetClient (c);
  close (c->fd);
  free (c);
  pthread_exit (0);
}
Exemplo n.º 7
0
void processInputBuffer(client *c) {
    server.current_client = c;
    /* Keep processing while there is something in the input buffer */
    while(sdslen(c->querybuf)) {
        /* CLIENT_CLOSE_AFTER_REPLY closes the connection once the reply is
         * written to the client. Make sure to not let the reply grow after
         * this flag has been set (i.e. don't process more commands). */
        if (c->flags & CLIENT_CLOSE_AFTER_REPLY) break;

        /* Determine request type when unknown. */
        if (!c->reqtype) {
            if (c->querybuf[0] == '*') {
                c->reqtype = PROTO_REQ_MULTIBULK;
            } else {
                c->reqtype = PROTO_REQ_INLINE;
            }
        }

        if (c->reqtype == PROTO_REQ_INLINE) {
            if (processInlineBuffer(c) != C_OK) break;
        } else if (c->reqtype == PROTO_REQ_MULTIBULK) {
            if (processMultibulkBuffer(c) != C_OK) break;
        } else {
            serverPanic("Unknown request type");
        }

        /* Multibulk processing could see a <= 0 length. */
        if (c->argc == 0) {
            resetClient(c);
        } else {
            /* Only reset the client when the command was executed. */
            if (processCommand(c) == C_OK)
                resetClient(c);
        }
    }
    server.current_client = NULL;
}
Exemplo n.º 8
0
static void clientDone(client c) {
    if (config.requests_finished == config.requests) {
        freeClient(c);
        aeStop(config.el);
        return;
    }
    if (config.keepalive) {
        resetClient(c);
    } else {
        config.liveclients--;
        createMissingClients(c);
        config.liveclients++;
        freeClient(c);
    }
}
Exemplo n.º 9
0
int init() {
	clientCount = 0;
	int i = 0;
	for (; i < CLIENT_SIZE; i++)
		resetClient(&clients[i]);
	int listen_sd, on = 1;
	struct sockaddr_in addr;
	listen_sd = socket(AF_INET, SOCK_STREAM, 0);
	if (listen_sd < 0) {
		writeErr("socket() failed");
		return -1;
	}

	int rc = setsockopt(listen_sd, SOL_SOCKET, SO_REUSEADDR, (char*) &on,
			sizeof(on));
	if (rc < 0) {
		writeErr("setsockopt() failed");
		close(listen_sd);
		return -1;
	}

	rc = ioctl(listen_sd, FIONBIO, (char *) &on);
	if (rc < 0) {
		writeErr("ioctl() failed");
		close(listen_sd);
		return -1;
	}

	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = htonl(INADDR_ANY );
	addr.sin_port = htons(SERVER_PORT);
	rc = bind(listen_sd, (struct sockaddr *) &addr, sizeof(addr));
	if (rc < 0) {
		println("bind() failed");
		close(listen_sd);
		return -1;
	}

	rc = listen(listen_sd, 5);
	if (rc < 0) {
		writeErr("listen() failed");
		close(listen_sd);
		return -1;
	}
	return listen_sd;
}
Exemplo n.º 10
0
MainController::~MainController() {
	idleDetector_->onIdleChanged.disconnect(boost::bind(&MainController::handleInputIdleChanged, this, _1));

	purgeCachedCredentials();
	//setManagersOffline();
	eventController_->disconnectAll();

	resetClient();
	delete highlightEditorController_;
	delete highlightManager_;
	delete fileTransferListController_;
	delete xmlConsoleController_;
	delete xmppURIController_;
	delete soundEventController_;
	delete systemTrayController_;
	delete eventController_;
	delete notifier_;
	delete uiEventStream_;
}
Exemplo n.º 11
0
static void listDeleteClientObjects(void *cl) {
    ugClient *c = (ugClient *) cl;
    resetClient(c);
    if (c->querybuf) sdsfree(c->querybuf);

    if (c->reply) {
        LOG_TRACE("reply size :%d", listLength(c->reply));
        listRelease(c->reply);
    }

    pubsubUnsubscribeAllChannels(c, 0);
    if (c->pubsub_channels) dictRelease(c->pubsub_channels);
    if (c->pubsub_patterns) listRelease(c->pubsub_patterns);

    aeDeleteFileEvent(server.el, c->fd, AE_READABLE);
    aeDeleteFileEvent(server.el, c->fd, AE_WRITABLE);
#ifdef _WIN32
    aeWinCloseSocket(c->fd);
#else
    close(c->fd);
#endif
    zfree(c);
    c = NULL;
}
Exemplo n.º 12
0
int _tmain(int argc, _TCHAR* argv[])
{
  splash(argv[0]);

  if((argc < 4) || ((argc > 5) && (strcmp("log", argv[5])))){
    printf("Usage: %s <ServerIP> <ClientIP> <OSCIP> <OSCPort> [\"log\"]", argv[0]);
  }else{


    int retCode;
    char* OSCIP = argv[3];
    int OSCPort = atoi(argv[4]);

    //EU
    printf("\n\nBanana hammock!!\n\n");

    // Set callback handlers
    theClient.SetMessageCallback(MessageHandler);
    theClient.SetVerbosityLevel(Verbosity_Debug);
    theClient.SetDataCallback( DataHandler, &theClient );	// this function will receive data from the server

    // Connect to NatNet server
    strcpy(szServerIPAddress, argv[1]);	// specified on command line
    strcpy(szMyIPAddress, argv[2]);	// specified on command line
    printf("Connecting to server at %s from %s...\n", szServerIPAddress, szMyIPAddress);

    // Connect to NatNet server


    retCode = theClient.Initialize(szMyIPAddress, szServerIPAddress);
    if (retCode != ErrorCode_OK)
      {
	printf("Unable to connect to server.  Error code: %d. Exiting", retCode);
	return 1;
      }
    else
      {

	// print server info
	sServerDescription ServerDescription;
	memset(&ServerDescription, 0, sizeof(ServerDescription));
	theClient.GetServerDescription(&ServerDescription);
	if(!ServerDescription.HostPresent)
	  {
	    printf("Unable to connect to server. Host not present. Exiting.");
	    return 1;
	  }
	printf("[OSCNatNetClient] Server application info:\n");
	printf("Application: %s (ver. %d.%d.%d.%d)\n",
	       ServerDescription.szHostApp,
	       ServerDescription.HostAppVersion[0],
	       ServerDescription.HostAppVersion[1],
	       ServerDescription.HostAppVersion[2],
	       ServerDescription.HostAppVersion[3]);
	printf("NatNet Version: %d.%d.%d.%d\n",
	       ServerDescription.NatNetVersion[0],
	       ServerDescription.NatNetVersion[1],
	       ServerDescription.NatNetVersion[2],
	       ServerDescription.NatNetVersion[3]);
	printf("Server IP:%s\n", szServerIPAddress);
	printf("Server Name:%s\n\n", ServerDescription.szHostComputerName);

	//EU - init UDP socket
	transmitSocket = new UdpTransmitSocket(IpEndpointName(OSCIP, OSCPort));
	printf("OSC IP:%s\n", OSCIP);
	printf("OSC Port:%d\n", OSCPort);
      }

    // send/receive test request
    printf("[OSCNatNetClient] Sending Test Request\n");
    void* response;
    int nBytes;
    retCode = theClient.SendMessageAndWait("TestRequest", &response, &nBytes);
    if (retCode == ErrorCode_OK)
      {
	printf("[OSCNatNetClient] Received: %s", (char*)response);
      }




    //Writing Session data to file

    char szFile[MAX_PATH];
    char szFolder[MAX_PATH];
#ifdef __linux__
    sprintf(szFolder, "./");
#else
    GetCurrentDirectory(MAX_PATH, szFolder);
#endif
    char timeLabel[50];
    time_t rawtime;
    struct tm* timeinfo;
    time(&rawtime);
    timeinfo = localtime(&rawtime);

    //create time label for files
    strftime (timeLabel,80,"%d.%m.%y %H.%M.%S",timeinfo);

    // Retrieve MarkerSets from server
    printf("\n\n[OSCNatNetClient] Requesting all data definitions for current session...");
    sDataDescriptions* pDataDefs = NULL;
    theClient.GetDataDescriptions(&pDataDefs);
    if(!pDataDefs){

      printf("[OSCNatNetClient] Unable to retrieve current session.");
      //return 1;

    }else{
      sprintf(szFile, "%s\\SessionData %s.txt", szFolder, timeLabel);
      fps = fopen(szFile, "w");
      if(!fps)
	{
	  printf("error opening output file %s.  Exiting.", szFile);
	  exit(1);
	}
      _WriteHeader(fps, pDataDefs);
      fclose(fps);
    }


    // Prepare data file for frame info

    if(argc > 5){

      sprintf(szFile, "%s\\FrameData %s.txt", szFolder, timeLabel);
      fpf = fopen(szFile, "w");
      if(!fpf){
	printf("error opening output file %s.  Exiting.", szFile);
	exit(1);
      }
    }



    // Ready to receive marker stream!
    printf("\nOSCNatNetClient is connected to server and listening for data... press 'q' for quitting\n");
    int c;
    bool bExit = false;
    while(c =_getch()){
      switch(c){
      case 'q':
	bExit = true;
	printf("\nQuitting...\n\n");
	break;
      case 'r':
	printf("\nReseting Client...\n\n");
	resetClient();
	break;
      default:
	printf("not an option\n\n");
	break;
      }
      if(bExit)
	break;
    }

    printf("clean up\n\n");
    // Done - clean up.
    theClient.Uninitialize();
    if(fpf != NULL) fclose(fpf);

    return ErrorCode_OK;
  }
}
Exemplo n.º 13
0
void ThriftTransportBase::closeNow() {
  resetClient();
}
Exemplo n.º 14
0
int _tmain(int argc, _TCHAR* argv[])
{
    int iResult;
    int iConnectionType = ConnectionType_Multicast;
    //int iConnectionType = ConnectionType_Unicast;
    
    // parse command line args
    if(argc>1)
    {
        strcpy(szServerIPAddress, argv[1]);	// specified on command line
        printf("Connecting to server at %s...\n", szServerIPAddress);
    }
    else
    {
        strcpy(szServerIPAddress, "");		// not specified - assume server is local machine
        printf("Connecting to server at LocalMachine\n");
    }
    if(argc>2)
    {
        strcpy(szMyIPAddress, argv[2]);	    // specified on command line
        printf("Connecting from %s...\n", szMyIPAddress);
    }
    else
    {
        strcpy(szMyIPAddress, "");          // not specified - assume server is local machine
        printf("Connecting from LocalMachine...\n");
    }
    if(argc>3)
    {
        strcpy(szUnityIPAddress, argv[3]);	    // specified on command line
        printf("Connecting to Unity3D at %s...\n", szUnityIPAddress);
    }
    else
    {
        strcpy(szUnityIPAddress, "127.0.0.1");          // not specified - assume server is local machine
        printf("Connecting to Unity3D on LocalMachine...\n");
    }
	if(argc>4)
	{
		iConnectionType = strcmp(argv[4], "unicast") != 0 ? ConnectionType_Multicast : ConnectionType_Unicast;
	}

    gSlipStream = new cSlipStream(szUnityIPAddress,16000);

    // Create NatNet Client
    iResult = CreateClient(iConnectionType);
    if(iResult != ErrorCode_OK)
    {
        printf("Error initializing client.  See log for details.  Exiting");
        return 1;
    }
    else
    {
        printf("Client initialized and ready.\n");
    }


	// send/receive test request
	printf("[SampleClient] Sending Test Request\n");
	void* response;
	int nBytes;
	iResult = theClient->SendMessageAndWait("TestRequest", &response, &nBytes);
	if (iResult == ErrorCode_OK)
	{
		printf("[SampleClient] Received: %s", (char*)response);
	}

	// Retrieve Data Descriptions from server
	printf("\n\n[SampleClient] Requesting Data Descriptions...");
	sDataDescriptions* pDataDefs = NULL;
	int nBodies = theClient->GetDataDescriptions(&pDataDefs);
	if(!pDataDefs)
	{
		printf("[SampleClient] Unable to retrieve Data Descriptions.");
	}
	else
	{
        printf("[SampleClient] Received %d Data Descriptions:\n", pDataDefs->nDataDescriptions );
        for(int i=0; i < pDataDefs->nDataDescriptions; i++)
        {
            printf("Data Description # %d (type=%d)\n", i, pDataDefs->arrDataDescriptions[i].type);
            if(pDataDefs->arrDataDescriptions[i].type == Descriptor_MarkerSet)
            {
                // MarkerSet
                sMarkerSetDescription* pMS = pDataDefs->arrDataDescriptions[i].Data.MarkerSetDescription;
                printf("MarkerSet Name : %s\n", pMS->szName);
                for(int i=0; i < pMS->nMarkers; i++)
                    printf("%s\n", pMS->szMarkerNames[i]);

            }
            else if(pDataDefs->arrDataDescriptions[i].type == Descriptor_RigidBody)
            {
                // RigidBody
                sRigidBodyDescription* pRB = pDataDefs->arrDataDescriptions[i].Data.RigidBodyDescription;
                printf("RigidBody Name : %s\n", pRB->szName);
                printf("RigidBody ID : %d\n", pRB->ID);
                printf("RigidBody Parent ID : %d\n", pRB->parentID);
                printf("Parent Offset : %3.2f,%3.2f,%3.2f\n", pRB->offsetx, pRB->offsety, pRB->offsetz);

				// populate rb name dictionary for use in xml ==--
				gRBNames[pRB->ID] = pRB->szName;
            }
            else if(pDataDefs->arrDataDescriptions[i].type == Descriptor_Skeleton)
            {
                // Skeleton
                sSkeletonDescription* pSK = pDataDefs->arrDataDescriptions[i].Data.SkeletonDescription;
                printf("Skeleton Name : %s\n", pSK->szName);
                printf("Skeleton ID : %d\n", pSK->skeletonID);
                printf("RigidBody (Bone) Count : %d\n", pSK->nRigidBodies);
                for(int j=0; j < pSK->nRigidBodies; j++)
                {
                    sRigidBodyDescription* pRB = &pSK->RigidBodies[j];
                    printf("  RigidBody Name : %s\n", pRB->szName);
                    printf("  RigidBody ID : %d\n", pRB->ID);
                    printf("  RigidBody Parent ID : %d\n", pRB->parentID);
                    printf("  Parent Offset : %3.2f,%3.2f,%3.2f\n", pRB->offsetx, pRB->offsety, pRB->offsetz);

                    // populate bone name dictionary for use in xml ==--
                    gBoneNames[pRB->ID] = pRB->szName;
                }
            }
            else
            {
                printf("Unknown data type.");
                // Unknown
            }
        }      
	}

	// Ready to receive marker stream!
	printf("\nClient is connected to server and listening for data...\n");
	int c;
	bool bExit = false;
	while(c =_getch())
	{
		switch(c)
		{
			case 'q':
				bExit = true;		
				break;	
			case 'r':
				resetClient();
				break;	
            case 'p':
                sServerDescription ServerDescription;
                memset(&ServerDescription, 0, sizeof(ServerDescription));
                theClient->GetServerDescription(&ServerDescription);
                if(!ServerDescription.HostPresent)
                {
                    printf("Unable to connect to server. Host not present. Exiting.");
                    return 1;
                }
                break;	
            case 'f':
                {
                    sFrameOfMocapData* pData = theClient->GetLastFrameOfData();
                    printf("Most Recent Frame: %d", pData->iFrame);
                }
                break;	
            case 'm':	                        // change to multicast
                iResult = CreateClient(ConnectionType_Multicast);
                if(iResult == ErrorCode_OK)
                    printf("Client connection type changed to Multicast.\n\n");
                else
                    printf("Error changing client connection type to Multicast.\n\n");
                break;
            case 'u':	                        // change to unicast
                iResult = CreateClient(ConnectionType_Unicast);
                if(iResult == ErrorCode_OK)
                    printf("Client connection type changed to Unicast.\n\n");
                else
                    printf("Error changing client connection type to Unicast.\n\n");
                break;


			default:
				break;
		}
		if(bExit)
			break;
	}

	// Done - clean up.
	theClient->Uninitialize();

	return ErrorCode_OK;
}
Exemplo n.º 15
0
int _tmain(int argc, _TCHAR* argv[])
{
	int iResult;
	int iConnectionType = ConnectionType_Multicast;

	// parse command line args
	if (argc != 2)
	{ 
		printf("Error! Please run with the following arguments:\n");
		printf("%s pose-server_ip:port\n", argv[0]);
		return 1;
	}

	//Parsing args
	std::string tcp_remote_ip;
	int tcp_remote_port;
	{
		std::vector<std::string> tokens;
		boost::split(tokens, argv[1], boost::is_any_of(":"));

		if (tokens.size() != 2)
		{
			printf("Error! Please provide the remote address in the format: x.x.x.x:p\n"); 
			return 1;
		}

		tcp_remote_ip = tokens[0];
		tcp_remote_port = std::stoi(tokens[1], nullptr);
	}


	tcpClient = AR::IO::TCPClient::Create();
	tcpClient->connect(tcp_remote_ip, tcp_remote_port, false);


	// Create NatNet Client
	iResult = CreateClient(iConnectionType);
	if (iResult != ErrorCode_OK)
	{
		printf("Error initializing client.  See log for details.  Exiting");
		return 1;
	}
	else
	{
		printf("Client initialized and ready.\n");
	}


	// send/receive test request
	printf("[SampleClient] Sending Test Request\n");
	void* response;
	int nBytes;
	iResult = theClient->SendMessageAndWait("TestRequest", &response, &nBytes);
	if (iResult == ErrorCode_OK)
	{
		printf("[SampleClient] Received: %s", (char*)response);
	}


	// Retrieve Data Descriptions from server
	printf("\n\n[SampleClient] Requesting Data Descriptions...");
	sDataDescriptions* pDataDefs = NULL;
	int nBodies = theClient->GetDataDescriptions(&pDataDefs);
	if (!pDataDefs)
	{
		printf("[SampleClient] Unable to retrieve Data Descriptions."); 
		return 1;
	}
	else
	{
		printf("[SampleClient] Received %d Data Descriptions:\n", pDataDefs->nDataDescriptions);
		for (int i = 0; i < pDataDefs->nDataDescriptions; i++)
		{
			printf("Data Description # %d (type=%d)\n", i, pDataDefs->arrDataDescriptions[i].type);
			if (pDataDefs->arrDataDescriptions[i].type == Descriptor_RigidBody)
			{
				// RigidBody
				sRigidBodyDescription* pRB = pDataDefs->arrDataDescriptions[i].Data.RigidBodyDescription;
				printf("RigidBody Name : %s\n", pRB->szName);
				printf("RigidBody ID : %d\n", pRB->ID);
				printf("RigidBody Parent ID : %d\n", pRB->parentID);
				printf("Parent Offset : %3.2f,%3.2f,%3.2f\n", pRB->offsetx, pRB->offsety, pRB->offsetz);
			}
			else
			{
				printf("Unknown data type.");
				// Unknown
			}
		}
	}

	// Ready to receive marker stream!
	printf("\nClient is connected to server and listening for data...\n");
	int c;
	bool bExit = false;
	while (c = _getch())
	{
		switch (c)
		{
		case 'q':
			bExit = true;
			break;
		case 'r':
			resetClient();
			break;
		case 'p':
			sServerDescription ServerDescription;
			memset(&ServerDescription, 0, sizeof(ServerDescription));
			theClient->GetServerDescription(&ServerDescription);
			if (!ServerDescription.HostPresent)
			{
				printf("Unable to connect to server. Host not present. Exiting.");
				return 1;
			}
			break;
		case 'f':
			{
				sFrameOfMocapData* pData = theClient->GetLastFrameOfData();
				printf("Most Recent Frame: %d", pData->iFrame);
			}
			break;


		default:
			break;
		}
		if (bExit)
			break;
	}

	// Done - clean up.
	theClient->Uninitialize();
	tcpClient->disconnect();

	return ErrorCode_OK;
}
Exemplo n.º 16
0
/* sid = |flags(4byte)|client fd(4byte)| */
static int
smrCbData (void *arg, long long seq, long long timestamp,
	   short nid, int sid, int hash, smrData * smr_data, int size)
{
  char *data = smr_data_get_data (smr_data);
  redisClient *c;
  short cmdflags;
  dlisth *node;

  /* Special commands */
  if (size == 1 && data[0] == REDIS_SMR_CMD_CATCHUP_CHECK)
    {
      if (nid == smr_get_nid (server.smr_conn)
	  && (server.smr_init_flags & SMR_INIT_CATCHUP_PHASE2))
	checkSmrCatchup ();
      goto release_seq;
    }
  else if (size == 1 && data[0] == REDIS_SMR_CMD_DELIVER_OOM)
    {
      server.smr_oom_until = timestamp + REDIS_OOM_DURATION_MS;
      goto release_seq;
    }

  /* Normal command */
  server.smr_mstime = timestamp;
  cmdflags = (0xFFFF0000 & sid) >> 16;

  /* Because we fixed the bug that causes timestamp be 0, 
   * this warning log is not necessary and just an assert statement is enough after all.
   * But currently, there are nbase-arc clusters which have the bug.
   * So, we don't assert for now. */
  if (timestamp == 0)
    {
      redisLog (REDIS_WARNING, "Timestamp of SMR callback is 0,"
		"seq:%lld, nid:%d, sid:%d, hash:%d, size:%d",
		seq, nid, sid, hash, size);
    }

  if ((server.smr_init_flags & SMR_INIT_DONE)
      && nid == smr_get_nid (server.smr_conn))
    {
      callbackInfo *cb;
      /* query from this server. get client from global callback list */
      assert (!dlisth_is_empty (&server.global_callbacks));	/* global callback list shouldn't be empty */
      node = server.global_callbacks.next;
      cb = (callbackInfo *) node;
      dlisth_delete (&cb->global_head);
      dlisth_delete (&cb->client_head);
      c = cb->client;
      assert (cb->hash == hash);
      assert (c->fd == -1 || c->fd == (0X0000FFFF & sid));

      /* We already parsed querybuf because the query is requested from this 
       * server before smr callback*/
      c->argc = cb->argc;
      c->argv = cb->argv;
      cb->argc = 0;
      cb->argv = NULL;
      zfree (cb);

      server.current_client = c;

      /* fake client doesn't need to execute non-write query(read-only or admin) */
      if (c->fd != -1 || cmdflags & REDIS_CMD_WRITE)
	{
	  assert (!(c->flags & REDIS_CLOSE_AFTER_REPLY));
	  processCommand (c);
	}
    }
  else
    {
      /* replicated query from other servers, or catchup query during initialize */
      c = server.smrlog_client;
      server.current_client = c;

      /* fake client doesn't need to execute non-write query(read-only or admin) */
      if (cmdflags & REDIS_CMD_WRITE)
	{
	  /* We need to parse querybuf because the query is from different server 
	   * or we are recovering without client */
	  sdsclear (c->querybuf);
	  c->querybuf = sdsMakeRoomFor (c->querybuf, size);
	  memcpy (c->querybuf, data, size);
	  sdsIncrLen (c->querybuf, size);
	  if (c->querybuf_peak < size)
	    c->querybuf_peak = size;
	  processInputBuffer (c);
	}
    }

  resetClient (c);
  zfree (c->argv);
  c->argv = NULL;
  server.current_client = NULL;

release_seq:
  if (smr_release_seq_upto (server.smr_conn, seq + size) == -1)
    {
      redisLog (REDIS_WARNING, "smr_release_seq_upto error");
      redisAssert (0);
      return REDIS_ERR;
    }
  server.smr_seqnum = seq + size;

  return REDIS_OK;
}
Exemplo n.º 17
0
int _tmain(int argc, _TCHAR* argv[])
{
	dest_cont.dests[0] = KITCHEN;
	dest_cont.dests[1] = TABLE_ONE;
	dest_cont.dests[2] = TABLE_TWO;
	dest_cont.dests[3] = KITCHEN;
	dest_cont.dests[4] = TABLE_THREE;
	dest_cont.dests[5] = -1;
	InitializeCriticalSection(&(dest_cont.lock));
	//memset(dest_cont.dests, -1, 11);
	dest_cont.step_num = 0;
	dest_cont.num_dests = 5;
	acommand.packet_counter = 1;
		for (int i = 0; i < 10; i++) {
		//dest_cont.dests[i] = -1;
		//cout << dest_cont.dests[i];
	}
	for(int j = 0; j < 5; j++) {
		dest_cont.active_orders[j] = 0;
		dest_cont.inactive_orders[j] = 0;
	}
	HANDLE thread = (HANDLE)::_beginthreadex(NULL, 0, update_orders,  NULL, 0, NULL);
    int iResult;
    int iConnectionType = ConnectionType_Multicast;
    //int iConnectionType = ConnectionType_Unicast;
    
    // parse command line args
    if(argc>1)
    {
        strcpy(szServerIPAddress, argv[1]);	// specified on command line
        printf("Connecting to server at %s...\n", szServerIPAddress);
    }
    else
    {
        strcpy(szServerIPAddress, "10.10.67.12");		// not specified - assume server is local machine
        printf("Connecting to server at LocalMachine\n");
    }
    if(argc>2)
    {
        strcpy(szMyIPAddress, argv[2]);	    // specified on command line
        printf("Connecting from %s...\n", szMyIPAddress);
    }
    else
    {
        strcpy(szMyIPAddress, "10.10.67.32");          // not specified - assume server is local machine
        printf("Connecting from LocalMachine...\n");
    }

    // Create NatNet Client
    iResult = CreateClient(iConnectionType);
    if(iResult != ErrorCode_OK)
    {
        printf("Error initializing client.  See log for details.  Exiting");
        return 1;
    }
    else
    {
        printf("Client initialized and ready.\n");
    }


	// send/receive test request
	printf("[SampleClient] Sending Test Request\n");
	void* response;
	int nBytes;
	iResult = theClient->SendMessageAndWait("TestRequest", &response, &nBytes);
	if (iResult == ErrorCode_OK)
	{
		printf("[SampleClient] Received: %s", (char*)response);
	}

	// Retrieve Data Descriptions from server
	printf("\n\n[SampleClient] Requesting Data Descriptions...");
	sDataDescriptions* pDataDefs = NULL;
	int nBodies = theClient->GetDataDescriptions(&pDataDefs);
	if(!pDataDefs)
	{
		printf("[SampleClient] Unable to retrieve Data Descriptions.");
	}
	else
	{
        printf("[SampleClient] Received %d Data Descriptions:\n", pDataDefs->nDataDescriptions );
        for(int i=0; i < pDataDefs->nDataDescriptions; i++)
        {
            printf("Data Description # %d (type=%d)\n", i, pDataDefs->arrDataDescriptions[i].type);
            if(pDataDefs->arrDataDescriptions[i].type == Descriptor_MarkerSet)
            {
                // MarkerSet
                sMarkerSetDescription* pMS = pDataDefs->arrDataDescriptions[i].Data.MarkerSetDescription;
                printf("MarkerSet Name : %s\n", pMS->szName);
                for(int i=0; i < pMS->nMarkers; i++)
                    printf("%s\n", pMS->szMarkerNames[i]);

            }
            else if(pDataDefs->arrDataDescriptions[i].type == Descriptor_RigidBody)
            {
                // RigidBody
                sRigidBodyDescription* pRB = pDataDefs->arrDataDescriptions[i].Data.RigidBodyDescription;
                printf("RigidBody Name : %s\n", pRB->szName);
                printf("RigidBody ID : %d\n", pRB->ID);
                printf("RigidBody Parent ID : %d\n", pRB->parentID);
                printf("Parent Offset : %3.2f,%3.2f,%3.2f\n", pRB->offsetx, pRB->offsety, pRB->offsetz);
            }
            else if(pDataDefs->arrDataDescriptions[i].type == Descriptor_Skeleton)
            {
                // Skeleton
                sSkeletonDescription* pSK = pDataDefs->arrDataDescriptions[i].Data.SkeletonDescription;
                printf("Skeleton Name : %s\n", pSK->szName);
                printf("Skeleton ID : %d\n", pSK->skeletonID);
                printf("RigidBody (Bone) Count : %d\n", pSK->nRigidBodies);
                for(int j=0; j < pSK->nRigidBodies; j++)
                {
                    sRigidBodyDescription* pRB = &pSK->RigidBodies[j];
                    printf("  RigidBody Name : %s\n", pRB->szName);
                    printf("  RigidBody ID : %d\n", pRB->ID);
                    printf("  RigidBody Parent ID : %d\n", pRB->parentID);
                    printf("  Parent Offset : %3.2f,%3.2f,%3.2f\n", pRB->offsetx, pRB->offsety, pRB->offsetz);
                }
            }
            else
            {
                printf("Unknown data type.");
                // Unknown
            }
        }
	}

	
	// Create data file for writing received stream into
	char szFile[MAX_PATH];
	char szFolder[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, szFolder);
	if(argc > 3)
		sprintf(szFile, "%s\\%s", szFolder, argv[3]);
	else
		sprintf(szFile, "%s\\Client-output.pts",szFolder);
	fp = fopen(szFile, "w");
	if(!fp)
	{
		printf("error opening output file %s.  Exiting.", szFile);
		exit(1);
	}
	if(pDataDefs)
		_WriteHeader(fp, pDataDefs);

	// Ready to receive marker stream!
	printf("\nClient is connected to server and listening for data...\n");
	int c;
	bool bExit = false;
	while(c =_getch())
	{
		switch(c)
		{
			case 'q':
				bExit = true;		
				break;	
			case 'r':
				resetClient();
				break;	
            case 'p':
                sServerDescription ServerDescription;
                memset(&ServerDescription, 0, sizeof(ServerDescription));
                theClient->GetServerDescription(&ServerDescription);
                if(!ServerDescription.HostPresent)
                {
                    printf("Unable to connect to server. Host not present. Exiting.");
                    return 1;
                }
                break;	
            case 'f':
                {
                    sFrameOfMocapData* pData = theClient->GetLastFrameOfData();
                    printf("Most Recent Frame: %d", pData->iFrame);
                }
                break;	
            case 'm':	                        // change to multicast
                iResult = CreateClient(ConnectionType_Multicast);
                if(iResult == ErrorCode_OK)
                    printf("Client connection type changed to Multicast.\n\n");
                else
                    printf("Error changing client connection type to Multicast.\n\n");
                break;
            case 'u':	                        // change to unicast
                iResult = CreateClient(ConnectionType_Unicast);
                if(iResult == ErrorCode_OK)
                    printf("Client connection type changed to Unicast.\n\n");
                else
                    printf("Error changing client connection type to Unicast.\n\n");
                break;


			default:
				break;
		}
		if(bExit)
			break;
	}

	// Done - clean up.
	theClient->Uninitialize();
	_WriteFooter(fp);
	fclose(fp);

	return ErrorCode_OK;
}
Exemplo n.º 18
0
void MainController::signOut() {
	eventController_->clear();
	logout();
	loginWindow_->loggedOut();
	resetClient();
}
Exemplo n.º 19
0
void MainController::handleDisconnected(const boost::optional<ClientError>& error) {
	if (quitRequested_) {
		resetClient();
		loginWindow_->quit();
	}
	else if (error) {
		std::string message;
		std::string certificateErrorMessage;
		switch(error->getType()) {
			case ClientError::UnknownError: message = QT_TRANSLATE_NOOP("", "Unknown Error"); break;
			case ClientError::DomainNameResolveError: message = QT_TRANSLATE_NOOP("", "Unable to find server"); break;
			case ClientError::ConnectionError: message = QT_TRANSLATE_NOOP("", "Error connecting to server"); break;
			case ClientError::ConnectionReadError: message = QT_TRANSLATE_NOOP("", "Error while receiving server data"); break;
			case ClientError::ConnectionWriteError: message = QT_TRANSLATE_NOOP("", "Error while sending data to the server"); break;
			case ClientError::XMLError: message = QT_TRANSLATE_NOOP("", "Error parsing server data"); break;
			case ClientError::AuthenticationFailedError: message = QT_TRANSLATE_NOOP("", "Login/password invalid"); break;
			case ClientError::CompressionFailedError: message = QT_TRANSLATE_NOOP("", "Error while compressing stream"); break;
			case ClientError::ServerVerificationFailedError: message = QT_TRANSLATE_NOOP("", "Server verification failed"); break;
			case ClientError::NoSupportedAuthMechanismsError: message = QT_TRANSLATE_NOOP("", "Authentication mechanisms not supported"); break;
			case ClientError::UnexpectedElementError: message = QT_TRANSLATE_NOOP("", "Unexpected response"); break;
			case ClientError::ResourceBindError: message = QT_TRANSLATE_NOOP("", "Error binding resource"); break;
			case ClientError::SessionStartError: message = QT_TRANSLATE_NOOP("", "Error starting session"); break;
			case ClientError::StreamError: message = QT_TRANSLATE_NOOP("", "Stream error"); break;
			case ClientError::TLSError: message = QT_TRANSLATE_NOOP("", "Encryption error"); break;
			case ClientError::ClientCertificateLoadError: message = QT_TRANSLATE_NOOP("", "Error loading certificate (Invalid password?)"); break;
			case ClientError::ClientCertificateError: message = QT_TRANSLATE_NOOP("", "Certificate not authorized"); break;

			case ClientError::UnknownCertificateError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Unknown certificate"); break;
			case ClientError::CertificateExpiredError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has expired"); break;
			case ClientError::CertificateNotYetValidError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is not yet valid"); break;
			case ClientError::CertificateSelfSignedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is self-signed"); break;
			case ClientError::CertificateRejectedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has been rejected"); break;
			case ClientError::CertificateUntrustedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is not trusted"); break;
			case ClientError::InvalidCertificatePurposeError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate cannot be used for encrypting your connection"); break;
			case ClientError::CertificatePathLengthExceededError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate path length constraint exceeded"); break;
			case ClientError::InvalidCertificateSignatureError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Invalid certificate signature"); break;
			case ClientError::InvalidCAError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Invalid Certificate Authority"); break;
			case ClientError::InvalidServerIdentityError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate does not match the host identity"); break;
		}
		bool forceReconnectAfterCertificateTrust = false;
		if (!certificateErrorMessage.empty()) {
			Certificate::ref certificate = certificateTrustChecker_->getLastCertificate();
			if (loginWindow_->askUserToTrustCertificatePermanently(certificateErrorMessage, certificate)) {
				certificateStorage_->addCertificate(certificate);
				forceReconnectAfterCertificateTrust = true;
			}
			else {
				message = QT_TRANSLATE_NOOP("", "Certificate error");
			}
		}

		if (forceReconnectAfterCertificateTrust) {
			performLoginFromCachedCredentials();
		}
		else if (!rosterController_) { //hasn't been logged in yet
			signOut();
			loginWindow_->setMessage(message);
		} else {
			logout();
			setReconnectTimer();
			if (lastDisconnectError_) {
				message = str(format(QT_TRANSLATE_NOOP("", "Reconnect to %1% failed: %2%. Will retry in %3% seconds.")) % jid_.getDomain() % message % boost::lexical_cast<std::string>(timeBeforeNextReconnect_));
				lastDisconnectError_->conclude();
			} else {
				message = str(format(QT_TRANSLATE_NOOP("", "Disconnected from %1%: %2%.")) % jid_.getDomain() % message);
			}
			lastDisconnectError_ = boost::shared_ptr<ErrorEvent>(new ErrorEvent(JID(jid_.getDomain()), message));
			eventController_->handleIncomingEvent(lastDisconnectError_);
		}
	}
}
Exemplo n.º 20
0
int main(int argc, char *argv[]) {

	if (argc != 3) {
		writeErr("Error: Use ./server directory PORT");
		return -1;
	}
	strcpy(MY_PATH, argv[1]);
	SERVER_PORT = atoi(argv[2]);
	int i, len, rc;
	int desc_ready, end_server = FALSE;
	int close_conn;
	char buffer[BUFFER_SIZE];
	fd_set master_set, working_set;
	int max_sd, new_sd;

	int listen_sd = init();
	if (listen_sd == -1)
		return -1;
	println("list");
	FD_ZERO(&master_set);
	FD_SET(STDIN, &master_set);
	println("listening");
	max_sd = listen_sd;
	FD_SET(listen_sd, &master_set);
	do {
		memcpy(&working_set, &master_set, sizeof(master_set));
//		println("waiting for listen...");
		rc = select(max_sd + 1, &working_set, NULL, NULL, NULL );
		if (isRCValid(rc) <= 0)
			break;
		desc_ready = rc;
		for (i = 0; i <= max_sd && desc_ready > 0; ++i) {
			if (FD_ISSET(i, &working_set)) {
				desc_ready--;
				if (i == listen_sd) {
					print("  Listening socket is readable\n");
					//DO_ACCEPT
					/**********************/
					new_sd = accept(listen_sd, NULL, NULL );
					if (new_sd < 0) {
						if (errno != EWOULDBLOCK) {
							writeErr("  accept() failed");
							end_server = TRUE;
						}
						break;
					}
					print("  New incoming connection: %d\n", new_sd);
					rc = recv(new_sd, buffer, sizeof(buffer), 0);
					int q = 0;
					int flag = 0;
					for (; q < clientCount; q++) {
						if (clients[q].fd == -1) {
							flag = 1;
							clients[q].fd = new_sd;
							strcpy(clients[q].name, buffer);
							clients[q].id = q;
							println("cli#%d:%s", q, buffer);
							break;
						}
					}
					if (flag == 0) {
						q = clientCount;
						clients[q].fd = new_sd;
						strcpy(clients[q].name, buffer);
						clients[q].id = q;
						println("cli#%d:%s", q, buffer);
						clientCount++;
					}
					len = convertIntToString(q, buffer);
					rc = send(new_sd, buffer, len + 1, 0);
					println("It has been sent");
					/**********************/
					//END DO_ACCEPT
					FD_SET(new_sd, &master_set);
					if (new_sd > max_sd)
						max_sd = new_sd;

				} else if (i == STDIN) {
					memset(buffer, 0, BUFFER_SIZE);
					readLine(buffer);

					int index = 0;
					char next[BUFFER_SIZE];
					memset(next, 0, BUFFER_SIZE);
					index = nextToken(buffer, next, index);
					if (strcmp("kick", next) == 0) {
						strcpy(buffer, buffer + 9);
						char tmpInt[BUFFER_SIZE] = "";
						index = nextToken(buffer, tmpInt, 0);
						int q = atoi(tmpInt);
						int i = clients[q].fd;
						int j = 0;
						for (; j < clients[q].fileCount; j++) {
							char fileName[BUFFER_SIZE] = "";
							strcpy(fileName, MY_PATH);
							strcat(fileName, clients[q].fileNames[j]);
							unlink(fileName);
						}
						resetClient(&clients[q]);
						close(i);
						FD_CLR(i, &master_set);
						if (i == max_sd) {
							while (FD_ISSET(max_sd, &master_set) == FALSE)
								max_sd -= 1;
						}
					}
				} else {
//					print("  Descriptor %d is readable\n", i);
					close_conn = FALSE;
					rc = recv(i, buffer, sizeof(buffer), 0);
					if (rc < 0)
						writeErr("  recv() failed");

					if (rc == 0) {
						print("  Connection closed\n");

						close_conn = TRUE;
					}

					len = rc;
					do_command(buffer, len, getNum(i));

					if (close_conn) {
						int q = 0;
						int flag = 0;
						for (; q < clientCount; q++) {
							if (clients[q].fd == i) {
								int j = 0;
								for (; j < clients[q].fileCount; j++) {
									char fileName[BUFFER_SIZE] = "";
									strcpy(fileName, MY_PATH);
									strcat(fileName, clients[q].fileNames[j]);
									unlink(fileName);
								}
								resetClient(&clients[q]);
								break;
							}
						}
						close(i);
						FD_CLR(i, &master_set);
						if (i == max_sd) {
							while (FD_ISSET(max_sd, &master_set) == FALSE)
								max_sd -= 1;
						}
					}
				}
			}
		}
	} while (end_server == FALSE);

	for (i = 0; i <= max_sd; ++i) {
		if (FD_ISSET(i, &master_set))
			close(i);
	}
}
Exemplo n.º 21
0
void ThriftTransportBase::channelClosed() {
  VLOG(3) << "[ThriftTransport] Channel closed.";
  resetClient();
}
Exemplo n.º 22
0
void MainController::handleDisconnected(const boost::optional<ClientError>& error) {
	if (rosterController_) {
		rosterController_->getWindow()->setStreamEncryptionStatus(false);
	}
	if (adHocManager_) {
		adHocManager_->setOnline(false);
	}
	if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
		purgeCachedCredentials();
	}
	if (quitRequested_) {
		resetClient();
		loginWindow_->quit();
	}
	else if (error) {
		std::string message;
		std::string certificateErrorMessage;
		bool forceSignout = false;
		switch(error->getType()) {
			case ClientError::UnknownError: message = QT_TRANSLATE_NOOP("", "Unknown Error"); break;
			case ClientError::DomainNameResolveError: message = QT_TRANSLATE_NOOP("", "Unable to find server"); break;
			case ClientError::ConnectionError: message = QT_TRANSLATE_NOOP("", "Error connecting to server"); break;
			case ClientError::ConnectionReadError: message = QT_TRANSLATE_NOOP("", "Error while receiving server data"); break;
			case ClientError::ConnectionWriteError: message = QT_TRANSLATE_NOOP("", "Error while sending data to the server"); break;
			case ClientError::XMLError: message = QT_TRANSLATE_NOOP("", "Error parsing server data"); break;
			case ClientError::AuthenticationFailedError: message = QT_TRANSLATE_NOOP("", "Login/password invalid"); break;
			case ClientError::CompressionFailedError: message = QT_TRANSLATE_NOOP("", "Error while compressing stream"); break;
			case ClientError::ServerVerificationFailedError: message = QT_TRANSLATE_NOOP("", "Server verification failed"); break;
			case ClientError::NoSupportedAuthMechanismsError: message = QT_TRANSLATE_NOOP("", "Authentication mechanisms not supported"); break;
			case ClientError::UnexpectedElementError: message = QT_TRANSLATE_NOOP("", "Unexpected response"); break;
			case ClientError::ResourceBindError: message = QT_TRANSLATE_NOOP("", "Error binding resource"); break;
			case ClientError::SessionStartError: message = QT_TRANSLATE_NOOP("", "Error starting session"); break;
			case ClientError::StreamError: message = QT_TRANSLATE_NOOP("", "Stream error"); break;
			case ClientError::TLSError: message = QT_TRANSLATE_NOOP("", "Encryption error"); break;
			case ClientError::ClientCertificateLoadError: message = QT_TRANSLATE_NOOP("", "Error loading certificate (Invalid file or password?)"); break;
			case ClientError::ClientCertificateError: message = QT_TRANSLATE_NOOP("", "Certificate not authorized"); break;
			case ClientError::CertificateCardRemoved: message = QT_TRANSLATE_NOOP("", "Certificate card removed"); forceSignout = true; break;

			case ClientError::UnknownCertificateError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Unknown certificate"); break;
			case ClientError::CertificateExpiredError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has expired"); break;
			case ClientError::CertificateNotYetValidError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is not yet valid"); break;
			case ClientError::CertificateSelfSignedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is self-signed"); break;
			case ClientError::CertificateRejectedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has been rejected"); break;
			case ClientError::CertificateUntrustedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is not trusted"); break;
			case ClientError::InvalidCertificatePurposeError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate cannot be used for encrypting your connection"); break;
			case ClientError::CertificatePathLengthExceededError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate path length constraint exceeded"); break;
			case ClientError::InvalidCertificateSignatureError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Invalid certificate signature"); break;
			case ClientError::InvalidCAError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Invalid Certificate Authority"); break;
			case ClientError::InvalidServerIdentityError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate does not match the host identity"); break;
			case ClientError::RevokedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has been revoked"); break;
			case ClientError::RevocationCheckFailedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Unable to determine certificate revocation state"); break;
		}
		bool forceReconnectAfterCertificateTrust = false;
		if (!certificateErrorMessage.empty()) {
			std::vector<Certificate::ref> certificates = certificateTrustChecker_->getLastCertificateChain();
			if (!certificates.empty() && loginWindow_->askUserToTrustCertificatePermanently(certificateErrorMessage, certificates)) {
				certificateStorage_->addCertificate(certificates[0]);
				forceReconnectAfterCertificateTrust = true;
			}
			else {
				message = QT_TRANSLATE_NOOP("", "Certificate error");
			}
		}

		if (!message.empty() && error->getErrorCode()) {
			message = str(format(QT_TRANSLATE_NOOP("", "%1% (%2%)")) % message % error->getErrorCode()->message());
		}

		if (forceReconnectAfterCertificateTrust && settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
			forceReconnectAfterCertificateTrust = false;
			forceSignout = true;
			message = QT_TRANSLATE_NOOP("", "Re-enter credentials and retry");
		}

		if (forceReconnectAfterCertificateTrust) {
			performLoginFromCachedCredentials();
		}
		else if (forceSignout || !rosterController_) { //hasn't been logged in yet or permanent error
			signOut();
			loginWindow_->setMessage(message);
			loginWindow_->setIsLoggingIn(false);
		} else {
			logout();
			if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
				message = str(format(QT_TRANSLATE_NOOP("", "Disconnected from %1%: %2%. To reconnect, Sign Out and provide your password again.")) % jid_.getDomain() % message);
			} else {
				if (!offlineRequested_) {
					setReconnectTimer();
				}
				if (lastDisconnectError_) {
					message = str(format(QT_TRANSLATE_NOOP("", "Reconnect to %1% failed: %2%. Will retry in %3% seconds.")) % jid_.getDomain() % message % boost::lexical_cast<std::string>(timeBeforeNextReconnect_));
					lastDisconnectError_->conclude();
				} else {
					message = str(format(QT_TRANSLATE_NOOP("", "Disconnected from %1%: %2%.")) % jid_.getDomain() % message);
				}
				lastDisconnectError_ = boost::make_shared<ErrorEvent>(JID(jid_.getDomain()), message);
				eventController_->handleIncomingEvent(lastDisconnectError_);
			}
		}
	}
	else if (!rosterController_) { //hasn't been logged in yet
		loginWindow_->setIsLoggingIn(false);
	}
}