示例#1
0
文件: main.c 项目: oxnz/RTFSC
int main(int argc, char *argv[]) {
	struct server server;
	sigset_t sigset;
	siginfo_t siginfo;
	struct timespec tmo;

	{ // setup server
		server.server_socket.addr = INADDR_ANY;
		server.server_socket.port = 8000;
		server.nrequest_max = 1024;
		server.nworker_min = 16;
		server.nworker_max = 32;
		server.nevent = 10;
		server.event_tmo = 10;
		if (server_init(&server)) {
			perror("server_init");
			return -1;
		}
	}
	{ // blocking all signals
		sigfillset(&sigset);
		if (pthread_sigmask(SIG_BLOCK, &sigset, NULL) != 0) {
			perror("pthread_sigmask");
			return -1;
		}
	}
	server_startup(&server);
	{ // signal handling
		tmo.tv_sec = 0;
		tmo.tv_nsec = 100000000; // 100 ms
		sigemptyset(&sigset);
		sigaddset(&sigset, SIGINT);
		sigfillset(&sigset);
		do {
			int signo = sigtimedwait(&sigset, &siginfo, &tmo);
			//int signo = sigwaitinfo(&sigset, &siginfo);
			if (signo == -1) {
				if (errno == EAGAIN || errno == EINTR) {
					continue;
				}
				perror("sigwaitinfo");
				break;
			}
			//dispatch_signal(siginfo);
			printf("got signal %d\n", siginfo.si_signo);
			if (siginfo.si_signo == SIGINT) {
				printf("interrupted, quittingx\n");
				break;
			}
		} while (1);
	}

	printf("shuting down\n");
	server_shutdown(&server);

	return 0;
}
示例#2
0
int main(void)
{
  server_startup_st construct;

  memset(&construct, 0, sizeof(server_startup_st));

  construct.count= 4;

  server_startup(&construct);

  return 0;
}
示例#3
0
void *world_create(void)
{
  server_startup_st *construct;

  construct= (server_startup_st *)malloc(sizeof(server_startup_st));
  memset(construct, 0, sizeof(server_startup_st));
  construct->count= SERVERS_TO_CREATE;
  construct->udp= 1;
  server_startup(construct);

  return construct;
}
示例#4
0
void *world_create(void)
{
  unsigned int x;
  memcached_server_st *servers;
  server_startup_st *construct;

  construct= (server_startup_st *)malloc(sizeof(server_startup_st));
  memset(construct, 0, sizeof(server_startup_st));

  construct->count= SERVERS_TO_CREATE;
  server_startup(construct);

  return construct;
}
示例#5
0
文件: server.c 项目: zybreak/enter
gboolean server_start(conf_t *conf)
{
	struct sigaction sa;
	
	/* Handle signals.
	 * SIGUSR1 is sent when the X server is ready.  */
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = SA_RESTART;
	sa.sa_handler = server_callback;
	sigaction(SIGUSR1,&sa,NULL);

	/* TODO: fix cmd */

	char *cmd[] = {
		"Xnest",
		conf_get(conf,"display"),
		NULL, NULL, NULL
	};

	if (strcmp(conf_get(conf, "authentication"), "none") != 0) {
		cmd[2] = "-auth";
		cmd[3] = conf_get(conf,"auth_file");
	}

	GError *error = NULL;
	gboolean spawn_successful = g_spawn_async(
			NULL, cmd, NULL,
			G_SPAWN_SEARCH_PATH,
			child_setup, NULL,
			&server_pid, &error);

	if (!spawn_successful) {
		g_warning("Spawn X failed: %s\n", error->message);
		return FALSE;
	}
	
	if (!server_startup(SERVER_TIMEOUT)) {
		g_warning("Could not start X, server timed out.");
		return FALSE;
	}

	return TRUE;
}