コード例 #1
0
ファイル: main.c プロジェクト: simula67/spectranet
int
main(int argc,char *argv)
{

  while( 1 ) {
    if( check_internet_connection() ) {
      fprintf(stderr,"Connection exists. Sleeping\n");
      sleep( SLEEP_TIME );
      continue;
    }
    else {
      connect_to_internet(username,password);
    }
  }
  fprintf(stderr,"Something wrong\n");
  fprintf(stderr,"Exited out of infinite loop\n");
  return 1;
}
コード例 #2
0
ファイル: elev_slave.c プロジェクト: PederAaby/Heisprosjekt
void udp_send_elev_loc_and_dir(int udp_lastFloor, int direction){ //Status function
  //Uses the input arguments, and sends these over udp.
  char buf[BUF_SIZE];
  memset(&buf, 0, sizeof(buf));
  serialize(buf, 3, udp_lastFloor, direction, elevatorID);

  if (udp_send(sendSock, mlp, buf, "255.255.255.255") != 1){ // <---- This is serverport
    //Disconnected from master
    if (packetLoss > 10){
		  	printf("Disconnected from master\n");
		    if (backup == 1){
		    	if(!check_internet_connection()){
		    		backup = 0;
		 	   		connectStatus = 0;
		    	}
		    	else{

				printf("Spawning master\n");
		    	pthread_t masterThread;
		    	pthread_create(&masterThread, NULL, &spawn_master, NULL);
		    	backup = 0;
		 	    connectStatus = 0;	 	  
		 	    sleep(N_ELEVATORS*2);
		    	}
		    }


	     connectStatus = 0;

	  	 pthread_create(&connectMasterThread, NULL, &connect_to_master, NULL);
	   	 pthread_join(connectMasterThread, NULL);
	}
	packetLoss++;
	printf("Lost a packet\n");
  }
  else{
  	  packetLoss = 0;
  }
}