Exemplo n.º 1
0
int main(void) {
  EXPECTED_RECV_LEN = strlen(EXPECTED_HTTP_REQUEST);
  RESPONSE_LEN = strlen(RESPONSE);
  acceptLoop();
  startWorkers();
  socketCheck();
  return 0;
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) {
  if (argc != 4) {
    printf( "usage: %s #workers <port number> <fib-n>\n", argv[0] );
    return -1;
  }

  PORT_NUM=atoi(argv[2]);
  FIB_NUM=atoi(argv[3]);

  int numWorkers = atoi(argv[1]);
  if (numWorkers >= MAX_NUM_WORKERS) {
    printf("error: number of workers must be less than %d\n", MAX_NUM_WORKERS);
    return -1;
  }

  num_clients = -1;
  num_requests = 0;
  //atexit(server_shutdown);

  acceptLoop();
  return 0;
}
Exemplo n.º 3
0
int main(int argc, char *argv[]) {
  EXPECTED_RECV_LEN = strlen(EXPECTED_HTTP_REQUEST);
  RESPONSE_LEN = strlen(RESPONSE);

  printf("Length of requst: %d;  response: %d\n", EXPECTED_RECV_LEN, RESPONSE_LEN);
  
  if (argc != 2) {
    printf( "usage: %s #workers\n", argv[0] );
    return -1;
  }
  int numWorkers = atoi(argv[1]);
  if (numWorkers >= MAX_NUM_WORKERS) {
    printf("error: number of workers must be less than %d\n", MAX_NUM_WORKERS);
    return -1;
  }

  startWorkers(numWorkers);
#if !(defined SHOW_PEAK_PERFORMANCE)
  startWakeupThread();
  startSocketCheckThread();
#endif
  acceptLoop(numWorkers);
  return 0;
}
Exemplo n.º 4
0
int main(int argc, char *argv[]) {

	// check argument
	if (argc < 3) {
		// std::cout << "Usage: mc.exe [sync folder path] [refresh interval in ms] [server IP] [server port] [client listen port]" << std::endl;
		std::cout << "Usage: mc.exe [sync folder path] [config file path]" << std::endl;
		exit(EXIT_FAILURE);
	}

	// get argument
	std::string monitorPath(argv[1]);
	// int refreshInterval = atoi(argv[2]);
	// char *serverIP = "127.0.0.1";
	// int serverPort = 4180;
	// int listenPort = 4181;

	// open config file
	std::string line;
	std::ifstream configFile(argv[2]);
	std::getline(configFile, line);
	std::istringstream iss(line);
	iss >> line;
	int refreshInterval = stoi(line);
	iss >> line;
	char serverIP[16];
	strncpy(serverIP, line.c_str(), 16);
	iss >> line;
	int serverPort = stoi(line);
	iss >> line;
	int listenPort = stoi(line);
	configFile.close();

	// constants
	const Protocol protocol = TCP;
	#ifdef WIN32
		WSADATA wsa;
		initWinsock(&wsa);
	#endif

	/*|=======================================================|*/
	/*|            Connect to server and monitor              |*/
	/*|=======================================================|*/
	struct sockaddr_in serverAddress;
	int serverSocket = getConnectSocket(serverIP, serverPort, protocol, &serverAddress);
	// file monitoring thread
	std::thread monitorThread(monitorFile, serverSocket, std::cref(monitorPath), refreshInterval, listenPort);

	/*|=======================================================|*/
	/*|          Listen to GET request from server            |*/
	/*|=======================================================|*/
	struct sockaddr_in listenAddress;
	int listenSocket = getListenSocket(NULL, listenPort, protocol, &listenAddress);
	// accept loop
	acceptLoop(listenSocket, monitorPath, listenPort);
	
	#ifdef WIN32
		WSACleanup();
	#endif

	threadPrint("Client is KO ed...", "");
	return 0;
}