LWS_VISIBLE int
lws_plat_init_fd_tables(struct libwebsocket_context *context)
{
	if (lws_libev_init_fd_table(context))
		/* libev handled it instead */
		return 0;

	if (pipe(context->dummy_pipe_fds)) {
		lwsl_err("Unable to create pipe\n");
		return 1;
	}

	/* use the read end of pipe as first item */
	context->fds[0].fd = context->dummy_pipe_fds[0];
	context->fds[0].events = LWS_POLLIN;
	context->fds[0].revents = 0;
	context->fds_count = 1;
	
	context->fd_random = open(SYSTEM_RANDOM_FILEPATH, O_RDONLY);
	if (context->fd_random < 0) {
		lwsl_err("Unable to open random device %s %d\n",
				    SYSTEM_RANDOM_FILEPATH, context->fd_random);
		return 1;
	}

	return 0;
}
예제 #2
0
LWS_VISIBLE int
lws_plat_init(struct lws_context *context,
	      struct lws_context_creation_info *info)
{
//	struct lws_context_per_thread *pt = &context->pt[0];
//	int n = context->count_threads, fd;

	/* master context has the global fd lookup array */
	context->connpool = lws_zalloc(sizeof(struct espconn *) *
					 context->max_fds * 2);
	if (context->connpool == NULL) {
		lwsl_err("OOM on lws_lookup array for %d connections\n",
			 context->max_fds);
		return 1;
	}

	lwsl_notice(" mem: platform fd map: %5u bytes\n",
		    sizeof(struct espconn *) * context->max_fds);
//	fd = open(SYSTEM_RANDOM_FILEPATH, O_RDONLY);

//	context->fd_random = fd;
//	if (context->fd_random < 0) {
//		lwsl_err("Unable to open random device %s %d\n",
//			 SYSTEM_RANDOM_FILEPATH, context->fd_random);
//		return 1;
//	}

        os_memset(&context->to_timer, 0, sizeof(os_timer_t));
        os_timer_disarm(&context->to_timer);
        os_timer_setfn(&context->to_timer, (os_timer_func_t *)cb_1Hz, context);
        os_timer_arm(&context->to_timer, 1000, 1);

	if (!lws_libev_init_fd_table(context) &&
	    !lws_libuv_init_fd_table(context)) {
		/* otherwise libev handled it instead */
#if 0
		while (n--) {
			if (pipe(pt->dummy_pipe_fds)) {
				lwsl_err("Unable to create pipe\n");
				return 1;
			}

			/* use the read end of pipe as first item */
			pt->fds[0].fd = pt->dummy_pipe_fds[0];
			pt->fds[0].events = LWS_POLLIN;
			pt->fds[0].revents = 0;
			pt->fds_count = 1;
			pt++;
		}
#endif
	}


#ifdef LWS_WITH_PLUGINS
	if (info->plugin_dirs)
		lws_plat_plugins_init(context, info->plugin_dirs);
#endif

	return 0;
}
예제 #3
0
LWS_VISIBLE int
lws_plat_init(struct lws_context *context,
	      struct lws_context_creation_info *info)
{
	struct lws_context_per_thread *pt = &context->pt[0];
	int n = context->count_threads, fd;

	/* master context has the global fd lookup array */
	context->lws_lookup = lws_zalloc(sizeof(struct lws *) *
					 context->max_fds);
	if (context->lws_lookup == NULL) {
		lwsl_err("OOM on lws_lookup array for %d connections\n",
			 context->max_fds);
		return 1;
	}

	lwsl_notice(" mem: platform fd map: %5u bytes\n",
		    sizeof(struct lws *) * context->max_fds);
	fd = open(SYSTEM_RANDOM_FILEPATH, O_RDONLY);

	context->fd_random = fd;
	if (context->fd_random < 0) {
		lwsl_err("Unable to open random device %s %d\n",
			 SYSTEM_RANDOM_FILEPATH, context->fd_random);
		return 1;
	}

	if (!lws_libev_init_fd_table(context) &&
	    !lws_libuv_init_fd_table(context)) {
		/* otherwise libev handled it instead */

		while (n--) {
			if (pipe(pt->dummy_pipe_fds)) {
				lwsl_err("Unable to create pipe\n");
				return 1;
			}

			/* use the read end of pipe as first item */
			pt->fds[0].fd = pt->dummy_pipe_fds[0];
			pt->fds[0].events = LWS_POLLIN;
			pt->fds[0].revents = 0;
			pt->fds_count = 1;
			pt++;
		}
	}

	context->fops.open	= _lws_plat_file_open;
	context->fops.close	= _lws_plat_file_close;
	context->fops.seek_cur	= _lws_plat_file_seek_cur;
	context->fops.read	= _lws_plat_file_read;
	context->fops.write	= _lws_plat_file_write;

#ifdef LWS_WITH_PLUGINS
	if (info->plugin_dirs)
		lws_plat_plugins_init(context, info->plugin_dirs);
#endif

	return 0;
}
예제 #4
0
LWS_VISIBLE int
lws_plat_init(struct lws_context *context,
              struct lws_context_creation_info *info)
{
    context->lws_lookup = lws_zalloc(sizeof(struct lws *) * context->max_fds);
    if (context->lws_lookup == NULL) {
        lwsl_err(
            "Unable to allocate lws_lookup array for %d connections\n",
            context->max_fds);
        return 1;
    }

    lwsl_notice(" mem: platform fd map: %5u bytes\n",
                sizeof(struct lws *) * context->max_fds);

    context->fd_random = open(SYSTEM_RANDOM_FILEPATH, O_RDONLY);
    if (context->fd_random < 0) {
        lwsl_err("Unable to open random device %s %d\n",
                 SYSTEM_RANDOM_FILEPATH, context->fd_random);
        return 1;
    }

    if (!lws_libev_init_fd_table(context)) {
        /* otherwise libev handled it instead */

        if (pipe(context->dummy_pipe_fds)) {
            lwsl_err("Unable to create pipe\n");
            return 1;
        }
    }

    /* use the read end of pipe as first item */
    context->fds[0].fd = context->dummy_pipe_fds[0];
    context->fds[0].events = LWS_POLLIN;
    context->fds[0].revents = 0;
    context->fds_count = 1;

    context->fops.open	= _lws_plat_file_open;
    context->fops.close	= _lws_plat_file_close;
    context->fops.seek_cur	= _lws_plat_file_seek_cur;
    context->fops.read	= _lws_plat_file_read;
    context->fops.write	= _lws_plat_file_write;

    return 0;
}