Exemplo n.º 1
0
static void processLine(QString line)
{
   if (line.isEmpty())
      return;

   if (line[0] == '#')
   {
      if (line[1] == '#')
         qDebug("%s", line.toLatin1().constData());
      return;
   }

   QString command;
   popArg(command, line);
   if (command.isEmpty())
      return;

   if (command == "COOKIE")
      processCookie(line);
   else if (command == "CHECK")
      processCheck(line);
   else if (command == "CLEAR")
      processClear(line);
   else if (command == "CONFIG")
      processConfig(line);
   else if (command == "SAVE")
      saveCookies();
   else
      FAIL(QString("Unknown command '%1'").arg(command));
}
Exemplo n.º 2
0
void processClientMessage(char* command, char* out_buffer)
{
	/*
	 * If other commands have not implemented logic to overwrite the server's output buffer,
	 *    client calling any any valid command after calling "list" causes the server output
	 *    to still display the list output.
	 */
	printf("**processClientMessage: command=%s\n", command);
	if(strcmp(command, "test") == 0) {
		strcpy(out_buffer, command);
	}
	else if(strcmp(command, "list") == 0) {  //process client command: list
		printf("**processClientMessage/processList\n");
		processList(out_buffer);
	}
	else if(strncmp(command, "check", 5) == 0) {  // processes client command: check filename
		printf("**processClientMessage/processCheck\n");
		char filename[MAXDATASIZE];
		strcpy(filename, command+strlen("check"));
		printf("**processClientMessage/processCheck: filename=%s\n", filename);

		processCheck(out_buffer, filename);
	}
	else if(strncmp(command, "get", 3) == 0) {  // processes client command: get filename
		printf("**processClientMessage/processGet\n");
		char filename[MAXDATASIZE];
		strcpy(filename, command+strlen("get"));
		printf("**processClientMessage/processCheck: filename=%s\n", filename);

		processGet(out_buffer, filename);
	}
	else if(strcmp(command, "quit") == 0) {
		strcpy(out_buffer, "goodbye");
	}
	else {
		printf("**processClientMessage/default\n");
		strcpy(out_buffer, "**command not recognized");
	}

	printf("**exiting processClientMessage\n");
}
Exemplo n.º 3
0
int processHandler(int fd)
{
  logTest("processHandler", "Going to run a new process");

  for (;;)
  {
    for (int i = 0; i < DEFAULT_PROCESS_ENTRIES; i++)
    {
      if (processes[i] == NULL)
      {
        logTest("processHandler", "Starting process for descriptor %d", fd);

        processes[i] = new Process();

        processes[i] -> setFunction(requestHandler, NULL);

        processes[i] -> setStdin(fd);
        processes[i] -> setStdout(fd);
        processes[i] -> setStderr(fileno(stderr));

        processes[i] -> start();

        return 1;
      }
    }

    //
    // We were unable to find a slot.
    // Wait until a child exits.
    //

    logTest("processHandler", "No free slots found");

    processes[0] -> wait(getTimestamp(10));

    processCheck();
  }
}
Exemplo n.º 4
0
/**
* \fn int jumpDoability(SDL_Surface* pSurfaceMap, SDL_Surface* pSurfaceMotion, enum DIRECTION jumpDirection)
* \brief Determine the faisability of a jump.
*
* \param[in] pSurfaceMap, pointer to the surface of the map.
* \param[in] pSurfaceMotion, pointer to the surface in motion.
* \param[in] jumpDirection, direction of the jump (UP or UPLEFT or UPRIGHT).
* \returns 1 = jump doable, 0 = jump not doable
*/
int jumpDoability(SDL_Surface* pSurfaceMap, SDL_Surface* pSurfaceMotion, enum DIRECTION jumpDirection)
{
	int checkUpLeft = 1, checkUpRight = 1, checkUp = 1, checkRight = 1, checkLeft = 1;
	int doAble = 1;

	checkUp = checkDirection(pSurfaceMap, pSurfaceMotion, 0, -7, UP);
	if (jumpDirection == UPLEFT)
	{
		checkUpLeft = checkDirection(pSurfaceMap, pSurfaceMotion, -3, -7, UPLEFT);
		checkLeft = checkDirection(pSurfaceMap, pSurfaceMotion, -3, 0, LEFT);
	}
	if (jumpDirection == UPRIGHT)
	{
		checkUpRight = checkDirection(pSurfaceMap, pSurfaceMotion, 3, -7, UPRIGHT);
		checkRight = checkDirection(pSurfaceMap, pSurfaceMotion, 3, 0, RIGHT);
	}
	if (jumpDirection == UP)
	{
		checkUpRight = checkDirection(pSurfaceMap, pSurfaceMotion, 2, -7, UPRIGHT);
		checkUpLeft = checkDirection(pSurfaceMap, pSurfaceMotion, -2, -7, UPLEFT);
	}
	doAble = processCheck(checkLeft, checkRight, checkUp, checkUpLeft, checkUpRight, jumpDirection);
	return doAble;
}
Exemplo n.º 5
0
int connectionHandler()
{
  requests = 0;

  logTest("connectionHandler", "Going to create a new dispatcher");

  dispatcher = new Dispatcher();

  dispatcher -> start();

  logTest("connectionHandler", "Going to create a new listener");

  listener = new TcpListener();

  listener -> setPort(6001);
  listener -> setBacklog(32);

  //
  // Not needed for the early tests.
  //
  // listener -> setAccept("127.0.0.1");
  //

  listener -> start();

  logTest("connectionHandler", "Going to add the listener to the set");

  dispatcher -> addReadFd(listener -> getFd());

  logTest("connectionHandler", "Going to enter the main loop");

  T_timestamp start = getTimestamp();
  T_timestamp now   = getTimestamp();

  int result;
  int fd;

  T_timestamp timeout;

  while (diffTimestamp(start, now) < 1000000000)
  {
    logTest("connectionHandler", "Going to wait for new events");

    timeout = nullTimestamp();

    result = dispatcher -> waitEvent(timeout);

    logTest("connectionHandler", "Dispatcher returned %d", result);

    while ((fd = dispatcher -> nextReadEvent()) != -1)
    {
      if ((fd = listener -> accept()) != -1)
      {
        requests++;

        logTest("connectionHandler", "Going to handle request %d",
                    requests);

        processHandler(fd);
      }
    }

    processCheck();

    now = getTimestamp();
  }

  logTest("connectionHandler", "Exiting with %ld seconds elapsed since start",
              diffTimestamp(start, now) / 1000);

  dispatcher -> removeReadFd(listener -> getFd());

  dispatcher -> end();

  delete dispatcher;

  logTest("connectionHandler", "Deleted the dispatcher");

  listener -> end();

  delete listener;

  logTest("connectionHandler", "Deleted the listener");

  processWait();

  return requests;
}