Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	int i;
	char *ip = NULL;
	int port = 0;
	
	for (i = 1; i + 1 < argc; ) {
		if (!strcasecmp(argv[i], "-h")) {
			ip = argv[++i];
		} else if (!strcasecmp(argv[i], "-p")) {
			port = atoi(argv[++i]);
		} else {
			i++;
		}
	}

	if (!(ip && port)) {
		fprintf(stderr, "Usage %s -h <host> -p <port>\n", argv[0]);
		return -1;
	}

	esl_listen(ip, port, mycallback, 100000);
	
	return 0;
}
Ejemplo n.º 2
0
int main(void)
{
	signal(SIGINT, handle_sig);
	signal(SIGCHLD, SIG_IGN);

	esl_global_set_default_logger(7);
	esl_listen("localhost", 8040, mycallback, NULL, &server_sock);

	return 0;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	int i;
	char *ip = NULL;
	int port = 0, thread = 0;
	
	for (i = 1; i < argc; ) {
		int cont = 0;

		if (i + 1 < argc) {
			if (!strcasecmp(argv[i], "-h")) {
				ip = argv[++i]; cont++;
			} else if (!strcasecmp(argv[i], "-p")) {
				port = atoi(argv[++i]); cont++;
			}
		}

		if (cont) {
			i++;
			continue;
		}

		if (!strcasecmp(argv[i], "-t")) {
			thread++;
		}

		i++;
	}

	if (!(ip && port)) {
		fprintf(stderr, "Usage %s [-t] -h <host> -p <port>\n", argv[0]);
		return -1;
	}

	/*
	 * NOTE: fflush() stdout before entering esl_listen().
	 * Not doing so causes the fork()ed child to repeat the message for every incoming
	 * connection, if stdout has been redirected (into a logfile, for example).
	 */
	if (thread) {
		printf("Starting threaded listener.\n");
		fflush(stdout);
		esl_listen_threaded(ip, port, mycallback, NULL, 100000);
	} else {
		printf("Starting forking listener.\n");
		fflush(stdout);
		esl_listen(ip, port, my_forking_callback, NULL, NULL);
	}

	return 0;
}