Пример #1
0
int tls_server_io_schannel_send(CONCRETE_IO_HANDLE tls_io, const void* buffer, size_t size, ON_SEND_COMPLETE on_send_complete, void* callback_context)
{
    int result;
    if (internal_send((TLS_IO_INSTANCE*)tls_io, buffer, size, on_send_complete, callback_context) != 0)
    {
        LogError("send failed");
        result = __FAILURE__;
    }
    else
    {
        result = 0;
    }

    return result;
}
Пример #2
0
int
main(int argc, char *argv[])
{
  int size, length, i;
  int *data;
  int *target;

  int fds[2];
  int shm_size = SHM_SIZE;
  char *areas[2];

  double bs, as, br, ar;

  if (argc > 1) {
    size = atoi(argv[1]);
    length = size / sizeof(int);
    size = sizeof(int) * length;
  } else
    exit(1);

  if (argc > 2) {
    shm_size = atoi(argv[2]);    
  }

  if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == -1) {
    perror("socketpair");
    exit(1);
  }

  areas[0] = mmap(0, shm_size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
  if (areas[0] == MAP_FAILED) {
    perror("mmap: ");
    abort();
  }
  areas[1] = mmap(0, shm_size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
  if (areas[1] == MAP_FAILED) {
    perror("mmap: ");
    abort();
  }

  log_perf("before init, size=%d", size);
  data = malloc(size);
  for(i=0; i<length; i++)
    data[i] = i;
  log_perf("after init");

  int idx;
  int count = 0;

  if (!fork()) {  /* child */
    free(data);
    target = malloc(size);
    idx = 0;
    count = 0;
    syncup(fds[1]);

    br = log_perf("start read");
    syncup(fds[1]);
    while (count < size) {
      int read_size = (size - count) > shm_size ? shm_size : (size - count);
      memcpy(((void *)target)+count, areas[idx], read_size);
      count += read_size;
      idx = (idx + 1) % 2;
      syncup(fds[1]);
    }
    ar = log_perf("done read");

    internal_send(fds[1], &br, sizeof(double));
    internal_send(fds[1], &ar, sizeof(double));

    for(i=0; i<length; i++)
      assert(target[i] == i);
    
  } else { /* parent */
    idx = 0;
    count = 0;
    syncup(fds[0]);

    bs = log_perf("start write");
    while (count < size) {
      int write_size = (size - count) > shm_size ? shm_size : (size - count);
      memcpy(areas[idx], ((void *)data)+count, write_size);
      count += write_size;
      idx = (idx + 1) % 2;
      syncup(fds[0]);
    }
    syncup(fds[0]);
    as = log_perf("done write");

    internal_recv(fds[0], &br, sizeof(double));
    internal_recv(fds[0], &ar, sizeof(double));
    printf("TIME: %f\n", max(as,ar) - min(bs,br) );

    /* wait for child to die */
    wait(NULL);
  }  
  return 0;
}
Пример #3
0
_export void * module_thread(void *arg) {

	pthread_mutex_lock(&mcp_char_logon_mutex);

	if (!char_logon_signaled) {
		pthread_cond_wait(&mcp_char_logon_cond_v, &mcp_char_logon_mutex);
	}

	pthread_mutex_unlock(&mcp_char_logon_mutex);

	while (char_logon) {
		if (module_setting("RotateCDKeys")->b_var && n_created && !(n_created % module_setting("RotateAfterRuns")->i_var) && !rotated) {
			switch_keys();

			plugin_print("mcp game", "requesting client restart\n");

			internal_send(INTERNAL_REQUEST, "%d", CLIENT_RESTART);

			pthread_exit(NULL);
		}

		rotated = FALSE;

		plugin_print("mcp game", "sleeping for %i seconds\n", module_setting("LobbyIdleTime")->i_var);

		struct timespec ts;
		clock_gettime(CLOCK_REALTIME, &ts);
		ts.tv_sec += module_setting("LobbyIdleTime")->i_var;

		pthread_mutex_lock(&mcp_cleanup_m);

		if (mcp_cleanup) {
			pthread_mutex_unlock(&mcp_cleanup_m);

			pthread_exit(NULL);
		}

		if (!pthread_cond_timedwait(&mcp_cleanup_cv, &mcp_cleanup_m, &ts)) {
			pthread_mutex_unlock(&mcp_cleanup_m);

			pthread_exit(NULL);
		}

		pthread_mutex_unlock(&mcp_cleanup_m);

		game_created = FALSE;
		game_joined = FALSE;

		if (module_setting("JoinPublicGames")->b_var) {
			request_game_list("");
		}

		if (module_setting("JoinPublicGames")->b_var) {
			pthread_mutex_lock(&pub_m);

			game_t *g = get_new_public_game();
			if (g) {
				strncpy(game_name, g->name, 15);
				strncpy(game_pass, "", 15);
				n_joined++;
			}

			pthread_mutex_unlock(&pub_m);
		} else {
		if (difftime(time(NULL), start_t) < 3600) {
			if (module_setting("GameLimitPerHour")->i_var > 0 && (n_gph > module_setting("GameLimitPerHour")->i_var)) {
				plugin_print("mcp game", "game limit per hour reached (%i)\n", module_setting("GameLimitPerHour")->i_var);
				continue;
			} else {
				n_gph++;
			}
		} else {
			start_t = time(NULL);
			n_gph = 0;
		}

		if (string_compare(module_setting("GameNamePass")->s_var, "random", FALSE) || !strlen(module_setting("GameNamePass")->s_var)) {
			string_random(15, 'a', 26, game_name);
			string_random(15, 'a', 26, game_pass);
		} else {
			if (game_count > 99) game_count = 0;
			game_count++;

			char *c_setting = strdup(module_setting("GameNamePass")->s_var);

			char *tok = strtok(c_setting, "/");	
			snprintf(game_name, 15, "%s-%s%i", tok ? tok : "", game_count < 10 ? "0" : "", game_count);

			tok = strtok(NULL, "/");
			strncpy(game_pass, tok ? tok : "", 15);

			free(c_setting);
		}

		while (!mcp_responsed) {
			pthread_mutex_lock(&game_created_mutex);
			pthread_cleanup_push((pthread_cleanup_handler_t) pthread_mutex_unlock, (void *) &game_created_mutex)

			mcp_send(0x03, "%w %d 01 ff 08 %s 00 %s 00 %s 00", request_id, game_diff, game_name, game_pass, "");

			struct timespec ts;
			clock_gettime(CLOCK_REALTIME, &ts);
			ts.tv_sec += 2;

			pthread_cond_timedwait(&game_created_cond_v, &game_created_mutex, &ts);

			pthread_cleanup_pop(1);
		}

		request_id++;
		//mcp_responsed = FALSE;
		n_created++;

		plugin_print("mcp game", "created game %s / %s (%s)\n", game_name, game_pass, module_setting("Difficulty")->s_var);
		}

		mcp_responsed = FALSE;

		pthread_mutex_lock(&d2gs_engine_shutdown_mutex);
		pthread_cleanup_push((pthread_cleanup_handler_t) pthread_mutex_unlock, (void *) &d2gs_engine_shutdown_mutex);

		while (!mcp_responsed) {
			pthread_mutex_lock(&game_joined_mutex);
			pthread_cleanup_push((pthread_cleanup_handler_t) pthread_mutex_unlock, (void *) &game_joined_mutex)

			mcp_send(0x04, "03 00 %s 00 %s 00", game_name, game_pass);

			clock_gettime(CLOCK_REALTIME, &ts);
			ts.tv_sec += 2;

			pthread_cond_timedwait(&game_joined_cond_v, &game_joined_mutex, &ts);

			pthread_cleanup_pop(1);
		}

		mcp_responsed = FALSE;

		if (!game_joined) {
			ftj++;
			goto retry;
		}

		plugin_print("mcp game", "joined game %s%s%s\n", game_name, strlen(game_pass) ? " / " : "", game_pass);

		pthread_cond_wait(&d2gs_engine_shutdown_cond_v, &d2gs_engine_shutdown_mutex);

		retry:
		pthread_cleanup_pop(1);
	}

	pthread_exit(NULL);
}