示例#1
0
static void proctl_monitor_loop(ACL_VSTREAM *sstream)
{
	const char *myname = "proctl_monitor_loop";
	ACL_VSTREAM *client;
	int   n;
	char  buf[1024];
	ACL_ARGV *cmd_argv;

	while (1) {
		client = acl_vstream_accept(sstream, NULL, 0);
		if (client == NULL)
			continue;

		n = acl_vstream_gets_nonl(client, buf, sizeof(buf));
		if (n == ACL_VSTREAM_EOF)
			continue;

		acl_debug(ACL_DEBUG_PROCTL, 2) ("%s(%d): get buf(%s)",
			myname, __LINE__, buf);
		cmd_argv = acl_argv_split(buf, "|");
		if (cmd_argv)
			proctl_monitor_main(client, cmd_argv->argc, cmd_argv->argv);
		else
			usage(client);
		acl_vstream_close(client);
	}
}
示例#2
0
文件: main.cpp 项目: 1514louluo/acl
static int vstream_server(void)
{
	const char *myname = "vstream_server";
	ACL_VSTREAM *sstream, *client;
	char  ebuf[256];

	sstream = acl_vstream_listen(addr, 128);
	if (sstream == NULL) {
		printf("%s(%d): listen on %s error(%s)\r\n",
			myname, __LINE__, addr,
			acl_last_strerror(ebuf, sizeof(ebuf)));
		return (-1);
	}

	acl_tcp_defer_accept(ACL_VSTREAM_SOCK(sstream), 0);
	printf("%s: listen %s ok\r\n", myname, addr);
	while (1) {
		client = acl_vstream_accept(sstream, NULL, 0);
		if (client == NULL) {
			printf("%s(%d): accept error(%s)\r\n",
				myname, __LINE__,
				acl_last_strerror(ebuf, sizeof(ebuf)));
			return (-1);
		}
		printf("accept one\r\n");
		if (1)
			reply_client2(client);
		else
			reply_client(client);
		acl_vstream_close(client);
	}
	
	return (0);
}
示例#3
0
文件: main.cpp 项目: 10jschen/acl
int main(int argc, char *argv[])
{
	ACL_VSTREAM *sstream, *client;
	const char *addr = "127.0.0.1:30082";

	acl_init();

	sstream = acl_vstream_listen(addr, 128);
	if (sstream == NULL) {
		printf("listen on %s error(%s)\r\n", addr, acl_last_serror());
		getchar();
		return (0);
	}

	printf("listening on %s ...\r\n", addr);

	while (1) {
		client = acl_vstream_accept(sstream, NULL, 0);
		if (client == NULL) {
			printf("accept error(%s)\r\n", acl_last_serror());
			break;
		}
		echo(client);
		acl_vstream_close(client);
	}

	printf("Over now\r\n");
	getchar();
	return (0);
}
示例#4
0
文件: main.c 项目: fatzero/acl
static void fiber_accept(void *ctx)
{
	ACL_VSTREAM *sstream = (ACL_VSTREAM *) ctx;

	for (;;) {
		ACL_VSTREAM *cstream = acl_vstream_accept(sstream, NULL, 0);
		if (cstream == NULL) {
			printf("acl_vstream_accept error %s\r\n",
				acl_last_serror());
			break;
		}

		printf("accept one\r\n");
		echo_client(cstream);
	}

	acl_vstream_close(sstream);
}
示例#5
0
void master_proc::listen_callback(int, ACL_EVENT*, ACL_VSTREAM *sstream, void*)
{
	ACL_VSTREAM* client = acl_vstream_accept(sstream, NULL, 0);
	if (client == NULL)
	{
		logger_error("accept error %s", last_serror());
		__stop = true;
	}
	else
	{
		service_main(client, NULL, NULL);
		acl_vstream_close(client); // 因为在 service_main 里不会关闭连接

		__count++;
		if (__count_limit > 0 && __count >= __count_limit)
			__stop = true;
	}
}
示例#6
0
文件: main.c 项目: jhomble/redis
static void run_server(const char *addr)
{
    ACL_VSTREAM *sstream = acl_vstream_listen(addr, 128);
    acl_pthread_pool_t *pool;
    CONN *conn;
    acl_pthread_t tid;
    acl_pthread_attr_t attr;
    ACL_VSTREAM *client;

    if (sstream == NULL) {
        acl_msg_error("listen %s error(%s)", addr, acl_last_serror());
        return;
    }

    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

    printf("listening on %s ...\n", addr);
    pool = acl_thread_pool_create(10, 10);
    while (1) {
        acl_mem_slice_delay_destroy();
        if (acl_read_wait(ACL_VSTREAM_SOCK(sstream), 5) == -1)
            continue;
        client = acl_vstream_accept(sstream, NULL, 0);
        if (client == NULL) {
            acl_msg_error("accept error(%s)", acl_last_serror());
            break;
        }
        acl_tcp_set_nodelay(ACL_VSTREAM_SOCK(client));
        conn = acl_mycalloc(1, sizeof(CONN));
        conn->stream = client;

        if (0)
            thread_run(conn);
        else if (1)
            acl_pthread_create(&tid, &attr, thread_main, conn);
        else
            acl_pthread_pool_add(pool, thread_run, conn);
    }

    acl_vstream_close(sstream);
}
示例#7
0
void master_threads::listen_callback(int, ACL_EVENT*, ACL_VSTREAM* sstream, void*)
{
	ACL_VSTREAM* client = acl_vstream_accept(sstream, NULL, 0);

	if (client == NULL)
	{
		logger_error("accept error(%s)", acl_last_serror());
		__stop = true;
	}
	else if (__thread_pool != NULL)
	{
		acl_pthread_pool_add(__thread_pool, thread_run, client);
		__count++;
	}
	else
	{
		// 单线程方式串行处理
		run_once(client);
		__count++;
	}
}
示例#8
0
文件: main.c 项目: iYefeng/acl
static void service_test(void)
{
	const char *addr = "127.0.0.1:8885";
	ACL_VSTREAM *sstream = acl_vstream_listen(addr, 32), *client;
	int   ret;

	assert(sstream != NULL);

	acl_xinetd_params_int_table(NULL, var_conf_int_tab);
	acl_xinetd_params_str_table(NULL, var_conf_str_tab);
	acl_xinetd_params_bool_table(NULL, var_conf_bool_tab);

	printf("listen %s ok\n", addr);

	service_init(NULL);

	while (1) {
		client = acl_vstream_accept(sstream, NULL, 0);
		if (client == NULL) {
			printf("accept error: %s\n", acl_last_serror());
			break;
		}

		while (1) {
			if (acl_readable(ACL_VSTREAM_SOCK(client)) == 0)
				continue;

			ret = service_main(client, NULL);
			if (ret < 0) {
				acl_vstream_close(client);
				break;
			}
			if (ret > 0)
				break;
		}
	}

	service_exit(NULL);
	acl_vstream_close(sstream);
}
示例#9
0
static void event_dog_open(EVENT_DOG *evdog)
{
	const char *myname = "event_dog_open";
	const char *addr = "127.0.0.1:0";
	char  ebuf[256];

	evdog->sstream = acl_vstream_listen(addr, 32);
	if (evdog->sstream == NULL)
		acl_msg_fatal("%s(%d): listen on addr(%s) error(%s)",
			myname, __LINE__, addr,
			acl_last_strerror(ebuf, sizeof(ebuf)));

	evdog->server = acl_vstream_connect(evdog->sstream->local_addr,
			ACL_BLOCKING, 0, 0, 1024);
	if (evdog->server == NULL)
		acl_msg_fatal("%s(%d): connect to addr(%s) error(%s)",
			myname, __LINE__, addr,
			acl_last_strerror(ebuf, sizeof(ebuf)));

	if (acl_vstream_writen(evdog->server, ebuf, 1) == ACL_VSTREAM_EOF)
		acl_msg_fatal("%s(%d): pre write error(%s)",
			myname, __LINE__,
			acl_last_strerror(ebuf, sizeof(ebuf)));

	evdog->client = acl_vstream_accept(evdog->sstream, ebuf, sizeof(ebuf));
	if (evdog->client == NULL)
		acl_msg_fatal("%s(%d): accept error(%s)",
			myname, __LINE__,
			acl_last_strerror(ebuf, sizeof(ebuf)));

	if (acl_vstream_readn(evdog->client, ebuf, 1) == ACL_VSTREAM_EOF)
		acl_msg_fatal("%s(%d): pre read error(%s)",
			myname, __LINE__,
			acl_last_strerror(ebuf, sizeof(ebuf)));

	acl_vstream_close(evdog->sstream);
	evdog->sstream = NULL;

	acl_event_enable_read(evdog->eventp, evdog->client, 0, read_fn, evdog);
}
示例#10
0
文件: main.c 项目: 10jschen/acl
int main(int argc, char *argv[])
{
	ACL_VSTREAM *sstream, *client;
	ACL_WORK_QUEUE* wq = acl_workq_create(100, 60, NULL, NULL);
	char  ch, *addr = "127.0.0.1:8889";
	char *regnum = "regnum";

	while ((ch = getopt(argc, argv, "hs:f:")) > 0) {
		switch (ch) {
		default:
		case 'h':
			usage(argv[0]);
			exit (0);
		case 's':
			addr = acl_mystrdup(optarg);
			break;
		case 'f':
			regnum = optarg;
			break;
		}
	}

	var_cfg_cache_file = acl_mystrdup(regnum);
	acl_socket_init();
	service_init(NULL);

	sstream = acl_vstream_listen(addr, 32);
	if (sstream == NULL)
		acl_msg_fatal("can't listen on addr(%s)", addr);

	printf("started, listen on %s ...\r\n", addr);
	while (1) {
		client = acl_vstream_accept(sstream, NULL, 0);
		acl_workq_add(wq, client_thread, 0, client);	
	}

	exit (0);
}