Пример #1
0
void StaticHandler::readFile(folly::EventBase* evb) {
  folly::IOBufQueue buf;
  while (file_ && !paused_) {
    // read 4k-ish chunks and foward each one to the client
    auto data = buf.preallocate(4000, 4000);
    auto rc = folly::readNoInt(file_->fd(), data.first, data.second);
    if (rc < 0) {
      // error
      VLOG(4) << "Read error=" << rc;
      file_.reset();
      evb->runInEventBaseThread([this] {
          LOG(ERROR) << "Error reading file";
          downstream_->sendAbort();
        });
      break;
    } else if (rc == 0) {
      // done
      file_.reset();
      VLOG(4) << "Read EOF";
      evb->runInEventBaseThread([this] {
          ResponseBuilder(downstream_)
            .sendWithEOM();
        });
      break;
    } else {
      buf.postallocate(rc);
      evb->runInEventBaseThread([this, body=buf.move()] () mutable {
          ResponseBuilder(downstream_)
            .body(std::move(body))
            .send();
        });
    }
  }

  // Notify the request thread that we terminated the readFile loop
  evb->runInEventBaseThread([this] {
      readFileScheduled_ = false;
      if (!checkForCompletion() && !paused_) {
        VLOG(4) << "Resuming deferred readFile";
        onEgressResumed();
      }
    });
}
Пример #2
0
void Tutorial::tick() {
    if (state == TS_END) return;

    tickCommonTutorial();
    switch(tutee->getGameRole()) {
        case PILOT:
            tickPilotTutorial();
            break;
        case ENGINEER:
            tickEngineerTutorial();
            break;
        case NAVIGATOR:
            tickNavigatorTutorial();
            break;
    }
    checkForCompletion();
    if (state == TS_INDIVIDUAL)
        door->open();
}
Пример #3
0
void sortFree()

{
	unsigned char adj = adjC(CT);
	unsigned char pFar = (indi[term[CT][0]] == adj | indi[term[CT][0]] == CT | indi[term[CT][0]] == 0);		//wont work for empty node
	unsigned char nxTerm = 0;
	if (visited[CT] == 0)
		termPick();
	counter();
	pickup(0);
	pickup(1);
	if (farCount == 2)
	{
		nxTerm = indi[arm[0]];
		//SchDropAtSort(nxTerm);
	}
	else if (adjCount == 1)
	{
		if (farCount == 1)
		{
			nxTerm = adj;
			//SchDropAtSort(nxTerm);
		}
		else	//1 empty block
		{
			nxTerm = adj;
		}
	}
	else if (farCount == 1)
	{
		if (adjCount == 1)
		{
			nxTerm = adj;
			//SchDropAtSort(nxTerm);
		}
		else	//1 empty block
		{
			if (visited[adj] == 0)
			{
				nxTerm = adj;
				//SchDropAtSort(nxTerm);
			}
			else
				nxTerm = indi[arm[pFar]];

		}
	}
	else if (adjCount == 2)
	{
		nxTerm = adj;
		//SchDropAtSort(nxTerm);
	}
	else	//empty term
	{
		if (visited[1] + visited[2] + visited[3] + visited[4] >= 3 && checkForCompletion() >= 6)
		{
			if (nxTerm == 0 && swap[0] == 0 && swap[1] == 0 && arm[0] == 0 && arm[1] == 0)	//panic or complete
				while (1);
		}
		else
		{
			if (visited[adj] == 0)
				nxTerm = adj;
			else
			{
				if (arm[0] > 0)
					nxTerm = indi[arm[0]];
				else if (arm[1] > 0)
					nxTerm = indi[arm[1]];
				else if (swap[CT % 2]>0)
					nxTerm = indi[swap[CT % 2]];
				else if (swap[(CT + 1) % 2] > 0)
					nxTerm = indi[swap[(CT + 1) % 2]];

				else
					nxTerm = unvisited();
			}

		}
		if (nxTerm == 0)
		{
			while (1);
		}
	}
	if (arm[0] == 0 && arm[1] == 0)
	{
		travel(nxTerm);
		sortFree();
	}
	else
	{
		travel(nxTerm);
		sortMan();
	}
}
Пример #4
0
void sortMan()
{
	unsigned char nxTerm = 0;
	unsigned char adj = adjC(CT);
	if (visited[CT] == 0)
		termPick();
	counter();
	unsigned char pSwap = ((CT == 2 || CT == 3) ? 1 : 0);
	unsigned char pFar = (indi[term[CT][0]] == adj | indi[term[CT][0]] == CT | indi[term[CT][0]] == 0);		//wont work for empty node
	if (indi[swap[CT % 2]] == CT)
	{
		if (farCount == 2)
		{
			if (term[CT][0] == term[CT][1])
			{
				nxTerm = indi[term[CT][0]]; //the common terminal
				pickup(0);
				drop(0);
				gotoSort();
				pickupS(1);
				dropS(0);
				goBack();
				pickup(1);
				drop(1);
			}
			else	//both diff of far
			{
				nxTerm = indi[term[CT][0]];
				pickup(0);
				drop(0);
				gotoSort();
				pickupS(0);
				dropS(1);
				goBack();
				pickup(1);
				drop(1);
				//SchPickupAtSort	//CT
				//SchDropAtSort		//far
			}
		}
		else if (farCount == 1)
		{
			if (adjCount == 1)
			{
				nxTerm = adj;
				pickup(pFar);
				drop(pFar);
				gotoSort();
				pickupS(pSwap);
				dropS(pSwap);
				goBack();
				pickup(!pFar);
				drop(!pFar);
				//nothing to schedule
			}
			else
			{	//empty node
				//:O :O
				if (visited[adj] == 0 || term[adj][0] != indi[adj] || term[adj][1] != indi[adj])
					nxTerm = adj;

				else	//seq also usable for both empty
				{
					nxTerm = indi[term[CT][pFar]];
					pickup(pFar);
					drop(pFar);
					gotoSort();
					pickupS(pSwap);
					goBack();
					drop(!pFar);
				}
			}
		}
		else if (adjCount == 1)
		{
			if (farCount == 1)
			{
				nxTerm = adj;
				pickup(pFar);
				drop(pFar);
				gotoSort();
				pickupS(pSwap);
				dropS(pSwap);
				goBack();
				pickup(!pFar);
				drop(!pFar);
				//nothing to schedule
			}
			else
			{
				//empty node
				drop(pFar);
				gotoSort();
				pickupS(pSwap);
				goBack();
				pickup(!pFar);
				drop(!pFar);
				nxTerm = adj;
			}
		}
		else if (adjCount == 2)
		{
			nxTerm = adj;
			pickup(0);
			drop(0);
			gotoSort();
			pickupS(pSwap);
			dropS(pSwap);
			goBack();
			pickup(1);
			drop(1);
		}
		if (arm[0] == 0 && arm[1] == 0)
		{
			travel(nxTerm);
			sortFree();
		}
		else
		{
			travel(nxTerm);
			sortMan();
		}

	}


	else if (indi[swap[CT % 2]] != CT)	//Sort can be empty
	{
		if (farCount == 2)
		{
			if (term[CT][0] == term[CT][1])	//and sort not empty why ?? :/
			{
				nxTerm = indi[term[CT][0]]; //the common terminal
				//SchPickupAtSort
				//SchDropAtSort
				pickup(0);
				drop(0);
				pickup(1);
				drop(1);
			}
			else if (swap[CT % 2] == term[CT][0])
			{
				pickup(0);
				drop(0);
				nxTerm = indi[arm[0]];
			}
			else if (swap[CT % 2] == term[CT][1])
			{
				pickup(1);
				drop(1);
				nxTerm = indi[arm[1]];
			}
			else
			{
				if (visited[indi[term[CT][0]]] == 1)
				{
					nxTerm = indi[term[CT][0]];
				}
				else
					nxTerm = indi[term[CT][1]];
				pickup(0);
				drop(0);
				pickup(1);
			}

		}
		else if (farCount == 1)
		{
			if (adjCount == 1)
			{
				if (swap[CT % 2] == 0)
				{
					pickup(!pFar); //adjwala
					drop(!pFar);
					pickup(pFar);
					nxTerm = adj;
					//SchDropAtSort
				}
				else
				{
					//Sort of far and CT has 1 far a adj
					pickup(!pFar);
					drop(!pFar);
					pickup(pFar);
					nxTerm = adj;
				}
			}
			else  //====
			{	//one node is empty
				if (visited[adj] == 1)
					nxTerm = indi[term[CT][pFar]];
				else nxTerm = adj;
				pickup(pFar);
				drop(pFar);
				//SchDropAtSort
			}
		}

		else if (adjCount == 1)
		{
			if (farCount == 1)
			{
				if (swap[CT % 2] == 0)
				{
					pickup(!pFar); //adjwala
					drop(!pFar);
					pickup(pFar);
					nxTerm = adj;
					//SchDropAtSort
				}
				else
				{
					//Sort of far and CT has 1 far a adj
					pickup(!pFar);
					drop(!pFar);
					nxTerm = adj;
				}
			}
			else	//1 empty 1 adj
			{
				pickup(!pFar);
				drop(!pFar);
				nxTerm = adj;
			}
		}
		else if (adjCount == 2)
		{
			if (swap[CT % 2] > 0) //smthin is at Sort
			{
				pickup(0);
				drop(0);
			}
			else
			{
				pickup(0);
				drop(0);
				pickup(1);
			}
			nxTerm = adj;
		}
		else	//empty term nore precisely we arent pickiing up anything so we have NO CLUE WHERE TO GO
		{
			drop(0);
			drop(1);
			if (visited[1] + visited[2] + visited[3] + visited[4] > 3 && checkForCompletion() >= 6)
			{
				if (nxTerm == 0 && swap[0] == 0 && swap[1] == 0 && arm[0] == 0 && arm[1] == 0)	//panic or complete
					while (1);
			}
			else
			{
				if (visited[adj] == 0)
					nxTerm = adj;
				else
				{
					if (arm[0] > 0)
						nxTerm = indi[arm[0]];
					else if (arm[1] > 0)
						nxTerm = indi[arm[1]];
					else if (swap[CT % 2]>0)
						nxTerm = indi[swap[CT % 2]];
					else if (swap[(CT + 1) % 2] > 0)
						nxTerm = indi[swap[(CT + 1) % 2]];

					else
						nxTerm = unvisited();
				}

			}
			if (nxTerm == 0)
			{
				while (1);
			}
		}
	}
	if (arm[0] == 0 && arm[1] == 0)
	{
		travel(nxTerm);
		sortFree();
	}
	else
	{
		travel(nxTerm);
		sortMan();
	}
}
Пример #5
0
void StaticHandler::onError(ProxygenError /*err*/) noexcept {
  finished_ = true;
  paused_ = true;
  checkForCompletion();
}
Пример #6
0
void StaticHandler::requestComplete() noexcept {
  finished_ = true;
  paused_ = true;
  checkForCompletion();
}
Пример #7
0
int test(char *URL)
{
  int res = 0;
  CURL *curl = NULL;
  FILE *hd_src = NULL;
  int hd ;
  int error;
  struct_stat file_info;
  CURLM *m = NULL;
  struct ReadWriteSockets sockets = {{NULL, 0, 0}, {NULL, 0, 0}};
  struct timeval timeout = {-1, 0};
  int success = 0;

  start_test_timing();

  if (!libtest_arg3) {
    fprintf(stderr, "Usage: lib582 [url] [filename] [username]\n");
    return TEST_ERR_USAGE;
  }

  hd_src = fopen(libtest_arg2, "rb");
  if(NULL == hd_src) {
    error = ERRNO;
    fprintf(stderr, "fopen() failed with error: %d (%s)\n",
            error, strerror(error));
    fprintf(stderr, "Error opening file: (%s)\n", libtest_arg2);
    return TEST_ERR_FOPEN;
  }

  /* get the file size of the local file */
  hd = fstat(fileno(hd_src), &file_info);
  if(hd == -1) {
    /* can't open file, bail out */
    error = ERRNO;
    fprintf(stderr, "fstat() failed with error: %d (%s)\n",
            error, strerror(error));
    fprintf(stderr, "ERROR: cannot open file (%s)\n", libtest_arg2);
    fclose(hd_src);
    return TEST_ERR_FSTAT;
  }
  fprintf(stderr, "Set to upload %d bytes\n", (int)file_info.st_size);

  res_global_init(CURL_GLOBAL_ALL);
  if(res) {
    fclose(hd_src);
    return res;
  }

  easy_init(curl);

  /* enable uploading */
  easy_setopt(curl, CURLOPT_UPLOAD, 1L);

  /* specify target */
  easy_setopt(curl,CURLOPT_URL, URL);

  /* go verbose */
  easy_setopt(curl, CURLOPT_VERBOSE, 1L);

  /* now specify which file to upload */
  easy_setopt(curl, CURLOPT_READDATA, hd_src);

  easy_setopt(curl, CURLOPT_USERPWD, libtest_arg3);
  easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, "curl_client_key.pub");
  easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, "curl_client_key");

  easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);

  multi_init(m);

  multi_setopt(m, CURLMOPT_SOCKETFUNCTION, curlSocketCallback);
  multi_setopt(m, CURLMOPT_SOCKETDATA, &sockets);

  multi_setopt(m, CURLMOPT_TIMERFUNCTION, curlTimerCallback);
  multi_setopt(m, CURLMOPT_TIMERDATA, &timeout);

  multi_add_handle(m, curl);

  while (!checkForCompletion(m, &success))
  {
    fd_set readSet, writeSet;
    curl_socket_t maxFd = 0;
    struct timeval tv = {10, 0};

    FD_ZERO(&readSet);
    FD_ZERO(&writeSet);
    updateFdSet(&sockets.read, &readSet, &maxFd);
    updateFdSet(&sockets.write, &writeSet, &maxFd);

    if (timeout.tv_sec != -1)
    {
      int usTimeout = getMicroSecondTimeout(&timeout);
      tv.tv_sec = usTimeout / 1000000;
      tv.tv_usec = usTimeout % 1000000;
    }
    else if (maxFd <= 0)
    {
      tv.tv_sec = 0;
      tv.tv_usec = 100000;
    }

    select_test(maxFd, &readSet, &writeSet, NULL, &tv);

    /* Check the sockets for reading / writing */
    checkFdSet(m, &sockets.read, &readSet, CURL_CSELECT_IN, "read");
    checkFdSet(m, &sockets.write, &writeSet, CURL_CSELECT_OUT, "write");

    if (timeout.tv_sec != -1 && getMicroSecondTimeout(&timeout) == 0)
    {
      /* Curl's timer has elapsed. */
      notifyCurl(m, CURL_SOCKET_TIMEOUT, 0, "timeout");
    }

    abort_on_test_timeout();
  }

  if (!success)
  {
    fprintf(stderr, "Error uploading file.\n");
    res = TEST_ERR_MAJOR_BAD;
  }

test_cleanup:

  /* proper cleanup sequence - type PB */

  curl_multi_remove_handle(m, curl);
  curl_easy_cleanup(curl);
  curl_multi_cleanup(m);
  curl_global_cleanup();

  /* close the local file */
  fclose(hd_src);

  /* free local memory */
  free(sockets.read.sockets);
  free(sockets.write.sockets);

  return res;
}
Пример #8
0
int test(char *URL)
{
  int res = 0;
  CURL *curl;
  FILE *hd_src ;
  int hd ;
  int error;
  struct_stat file_info;
  CURLM *m = NULL;
  struct timeval ml_start;
  char ml_timedout = FALSE;
  struct ReadWriteSockets sockets = {{NULL, 0, 0}, {NULL, 0, 0}};
  struct timeval timeout = {-1, 0};
  int success = 0;

  if (!libtest_arg3) {
    fprintf(stderr, "Usage: lib582 [url] [filename] [username]\n");
    return -1;
  }

  hd_src = fopen(libtest_arg2, "rb");
  if(NULL == hd_src) {
    error = ERRNO;
    fprintf(stderr, "fopen() failed with error: %d %s\n",
            error, strerror(error));
    fprintf(stderr, "Error opening file: %s\n", libtest_arg2);
    return TEST_ERR_MAJOR_BAD;
  }

  /* get the file size of the local file */
  hd = fstat(fileno(hd_src), &file_info);
  if(hd == -1) {
    /* can't open file, bail out */
    error = ERRNO;
    fprintf(stderr, "fstat() failed with error: %d %s\n",
            error, strerror(error));
    fprintf(stderr, "ERROR: cannot open file %s\n", libtest_arg2);
    fclose(hd_src);
    return -1;
  }
  fprintf(stderr, "Set to upload %d bytes\n", (int)file_info.st_size);

  if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
    fprintf(stderr, "curl_global_init() failed\n");
    fclose(hd_src);
    return TEST_ERR_MAJOR_BAD;
  }

  if ((curl = curl_easy_init()) == NULL) {
    fprintf(stderr, "curl_easy_init() failed\n");
    fclose(hd_src);
    curl_global_cleanup();
    return TEST_ERR_MAJOR_BAD;
  }

  /* enable uploading */
  test_setopt(curl, CURLOPT_UPLOAD, 1L);

  /* specify target */
  test_setopt(curl,CURLOPT_URL, URL);

  /* go verbose */
  test_setopt(curl, CURLOPT_VERBOSE, 1L);

  /* now specify which file to upload */
  test_setopt(curl, CURLOPT_READDATA, hd_src);

  test_setopt(curl, CURLOPT_USERPWD, libtest_arg3);
  test_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, "curl_client_key.pub");
  test_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, "curl_client_key");

  test_setopt(curl, CURLOPT_INFILESIZE_LARGE,
                   (curl_off_t)file_info.st_size);

  if ((m = curl_multi_init()) == NULL) {
    fprintf(stderr, "curl_multi_init() failed\n");
    curl_easy_cleanup(curl);
    curl_global_cleanup();
    fclose(hd_src);
    return TEST_ERR_MAJOR_BAD;
  }
  test_multi_setopt(m, CURLMOPT_SOCKETFUNCTION, curlSocketCallback);
  test_multi_setopt(m, CURLMOPT_SOCKETDATA, &sockets);

  test_multi_setopt(m, CURLMOPT_TIMERFUNCTION, curlTimerCallback);
  test_multi_setopt(m, CURLMOPT_TIMERDATA, &timeout);

  if ((res = (int)curl_multi_add_handle(m, curl)) != CURLM_OK) {
    fprintf(stderr, "curl_multi_add_handle() failed, "
            "with code %d\n", res);
    curl_multi_cleanup(m);
    curl_easy_cleanup(curl);
    curl_global_cleanup();
    fclose(hd_src);
    return TEST_ERR_MAJOR_BAD;
  }

  ml_timedout = FALSE;
  ml_start = tutil_tvnow();

  while (!checkForCompletion(m, &success))
  {
    fd_set readSet, writeSet;
    curl_socket_t maxFd = 0;
    struct timeval tv = {10, 0};

    if (tutil_tvdiff(tutil_tvnow(), ml_start) >
        MAIN_LOOP_HANG_TIMEOUT) {
      ml_timedout = TRUE;
      break;
    }

    FD_ZERO(&readSet);
    FD_ZERO(&writeSet);
    updateFdSet(&sockets.read, &readSet, &maxFd);
    updateFdSet(&sockets.write, &writeSet, &maxFd);

    if (timeout.tv_sec != -1)
    {
      int usTimeout = getMicroSecondTimeout(&timeout);
      tv.tv_sec = usTimeout / 1000000;
      tv.tv_usec = usTimeout % 1000000;
    }
    else if (maxFd <= 0)
    {
      tv.tv_sec = 0;
      tv.tv_usec = 100000;
    }

    select_test(maxFd, &readSet, &writeSet, NULL, &tv);

    /* Check the sockets for reading / writing */
    checkFdSet(m, &sockets.read, &readSet, CURL_CSELECT_IN, "read");
    checkFdSet(m, &sockets.write, &writeSet, CURL_CSELECT_OUT, "write");

    if (timeout.tv_sec != -1 && getMicroSecondTimeout(&timeout) == 0)
    {
      /* Curl's timer has elapsed. */
      notifyCurl(m, CURL_SOCKET_TIMEOUT, 0, "timeout");
    }
  }

  if (!success)
  {
    fprintf(stderr, "Error uploading file.\n");
    res = TEST_ERR_MAJOR_BAD;
  }
  else if (ml_timedout) {
    fprintf(stderr, "ABORTING TEST, since it seems "
            "that it would have run forever.\n");
    res = TEST_ERR_RUNS_FOREVER;
  }

test_cleanup:

  if(m)
    curl_multi_remove_handle(m, curl);
  curl_easy_cleanup(curl);
  if(m) {
    fprintf(stderr, "Now multi-cleanup!\n");
    curl_multi_cleanup(m);
  }

  fclose(hd_src); /* close the local file */
  if (sockets.read.sockets)
    free(sockets.read.sockets);
  if (sockets.write.sockets)
    free(sockets.write.sockets);

  curl_global_cleanup();
  return res;
}
/*
 *  ======== ACPY3_completeLinked ========
 * Non-blocking query to check completion of an individual
 * transfer in a Linked transfer.
 */
Bool ACPY3_completeLinked(IDMA3_Handle handle, unsigned short waitId)
{
#ifndef _ACPY3_CPUCOPY_
    Uns     tcc;
#endif
    Bool status;
   
    GT_2trace(CURTRACE, GT_ENTER,
            "ACPY3_completeLinked> Enter (handle=0x%x, waitId =%d)\n",
            handle, waitId); 

    GT_assert(CURTRACE, (handle != NULL) && (waitId < handle->numTccs));

    ACPY3_INSTR_CALLHOOKFXN(((ACPY3_MoreEnv *)handle->env)->extendedHooks, 
        handle, ACPY3_INSTR_COMPLETELINKED_ENTER);

    if (!handle->transferPending) {

        GT_0trace(CURTRACE, GT_2CLASS,
                "ACPY3_completeLinked> No transfers pending\n");

        /* No transfers pending - channel already waited on since last start */
        ACPY3_INSTR_CALLHOOKFXN(((ACPY3_MoreEnv *)handle->env)->extendedHooks,
                handle, ACPY3_INSTR_COMPLETELINKED_EXIT);

        GT_0trace(CURTRACE, GT_ENTER,
                "ACPY3_completeLinked> Exit (status=TRUE)\n");

        return (TRUE);
    }

    if (waitId == (handle->numTccs - 1)) {

        ACPY3_INSTR_CALLHOOKFXN(((ACPY3_MoreEnv *)handle->env)->extendedHooks,
                handle, ACPY3_INSTR_COMPLETELINKED_EXIT);

        GT_0trace(CURTRACE, GT_4CLASS, "ACPY3_completeLinked> "
                "Waiting for the last in a set of linked transfers\n");

        return (ACPY3_complete(handle));
    }

#ifndef _ACPY3_CPUCOPY_
    tcc = handle->tccTable[waitId + 1];

    /*
     * Wait for a channel only once. Set the 'pending' flag whenever new
     * transfer is submitted, then clear it when ACPY3_wait is issued.
     */
    ACPY3_INSTR_CALLHOOKFXN(((ACPY3_MoreEnv *)handle->env)->extendedHooks, 
            handle, ACPY3_INSTR_COMPLETELINKED_EXIT);

    GT_1trace(CURTRACE, GT_4CLASS,
            "  _ACPY3_completeLinked> Waiting for tcc %d\n", tcc);

    status = checkForCompletion(tcc);

    GT_1trace(CURTRACE, GT_ENTER, "ACPY3_completeLinked> Exit (status=%d)\n",
            status);

    return (status);

#else

    ACPY3_INSTR_CALLHOOKFXN(((ACPY3_MoreEnv *)handle->env)->extendedHooks, 
            handle, ACPY3_INSTR_COMPLETELINKED_EXIT);

    status = ACPY3_complete(handle);

    GT_1trace(CURTRACE, GT_ENTER, "ACPY3_completeLinked> Exit (status=%d)\n",
            status);

    return (status);
#endif
}