LWS_VISIBLE int lws_plat_init(struct lws_context *context, struct lws_context_creation_info *info) { /* master context has the global fd lookup array */ context->lws_lookup = lws_zalloc(sizeof(struct lws *) * context->max_fds, "xrdio lws_lookup"); 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: %5lu bytes\n", (unsigned long)(sizeof(struct lws *) * context->max_fds)); #ifdef LWS_WITH_PLUGINS if (info->plugin_dirs) lws_plat_plugins_init(context, info->plugin_dirs); #endif #if defined(LWS_WITH_HTTP2) /* override settings */ context->set = lws_h2_defaults_xradio; #endif return 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; }
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; }
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 i, n = context->count_threads; for (i = 0; i < FD_HASHTABLE_MODULUS; i++) { context->fd_hashtable[i].wsi = lws_zalloc(sizeof(struct lws*) * context->max_fds); if (!context->fd_hashtable[i].wsi) return -1; } while (n--) { pt->events = lws_malloc(sizeof(WSAEVENT) * (context->fd_limit_per_thread + 1)); if (pt->events == NULL) { lwsl_err("Unable to allocate events array for %d connections\n", context->fd_limit_per_thread + 1); return 1; } pt->fds_count = 0; pt->events[0] = WSACreateEvent(); pt++; } context->fd_random = 0; 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; }
LWS_VISIBLE int lws_plat_init(struct lws_context *context, const struct lws_context_creation_info *info) { struct lws_context_per_thread *pt = &context->pt[0]; int i, n = context->count_threads; for (i = 0; i < FD_HASHTABLE_MODULUS; i++) { context->fd_hashtable[i].wsi = lws_zalloc(sizeof(struct lws*) * context->max_fds, "win hashtable"); if (!context->fd_hashtable[i].wsi) return -1; } while (n--) { pt->events = lws_malloc(sizeof(WSAEVENT) * (context->fd_limit_per_thread + 1), "event table"); if (pt->events == NULL) { lwsl_err("Unable to allocate events array for %d connections\n", context->fd_limit_per_thread + 1); return 1; } pt->fds_count = 0; pt->events[0] = WSACreateEvent(); /* the cancel event */ pt++; } context->fd_random = 0; #ifdef LWS_WITH_PLUGINS if (info->plugin_dirs) lws_plat_plugins_init(context, info->plugin_dirs); #endif return 0; }
LWS_VISIBLE LWS_EXTERN int _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi) { struct lws_context_per_thread *pt; int n = -1, m, c; //char buf; /* stay dead once we are dead */ if (!context || !context->vhost_list) return 1; pt = &context->pt[tsi]; if (timeout_ms < 0) goto faked_service; if (!context->service_tid_detected) { struct lws _lws; memset(&_lws, 0, sizeof(_lws)); _lws.context = context; context->service_tid_detected = context->vhost_list->protocols[0].callback( &_lws, LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0); context->service_tid = context->service_tid_detected; context->service_tid_detected = 1; } /* * is there anybody with pending stuff that needs service forcing? */ if (!lws_service_adjust_timeout(context, 1, tsi)) { lwsl_notice("%s: doing forced service\n", __func__); /* -1 timeout means just do forced service */ _lws_plat_service_tsi(context, -1, pt->tid); /* still somebody left who wants forced service? */ if (!lws_service_adjust_timeout(context, 1, pt->tid)) /* yes... come back again quickly */ timeout_ms = 0; } #if 1 n = poll(pt->fds, pt->fds_count, timeout_ms); #ifdef LWS_OPENSSL_SUPPORT if (!pt->rx_draining_ext_list && !lws_ssl_anybody_has_buffered_read_tsi(context, tsi) && !n) { #else if (!pt->rx_draining_ext_list && !n) /* poll timeout */ { #endif lws_service_fd_tsi(context, NULL, tsi); return 0; } #endif faked_service: m = lws_service_flag_pending(context, tsi); if (m) c = -1; /* unknown limit */ else if (n < 0) { if (LWS_ERRNO != LWS_EINTR) return -1; return 0; } else c = n; /* any socket with events to service? */ for (n = 0; n < pt->fds_count && c; n++) { if (!pt->fds[n].revents) continue; c--; #if 0 if (pt->fds[n].fd == pt->dummy_pipe_fds[0]) { if (read(pt->fds[n].fd, &buf, 1) != 1) lwsl_err("Cannot read from dummy pipe."); continue; } #endif m = lws_service_fd_tsi(context, &pt->fds[n], tsi); if (m < 0) return -1; /* if something closed, retry this slot */ if (m) n--; } return 0; } LWS_VISIBLE int lws_plat_check_connection_error(struct lws *wsi) { return 0; } LWS_VISIBLE int lws_plat_service(struct lws_context *context, int timeout_ms) { return _lws_plat_service_tsi(context, timeout_ms, 0); } LWS_VISIBLE int lws_plat_set_socket_options(struct lws_vhost *vhost, int fd) { return 0; } LWS_VISIBLE void lws_plat_drop_app_privileges(struct lws_context_creation_info *info) { } LWS_VISIBLE int lws_plat_context_early_init(void) { return 0; } LWS_VISIBLE void lws_plat_context_early_destroy(struct lws_context *context) { } LWS_VISIBLE void lws_plat_context_late_destroy(struct lws_context *context) { if (context->lws_lookup) lws_free(context->lws_lookup); } /* cast a struct sockaddr_in6 * into addr for ipv6 */ LWS_VISIBLE int lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr, size_t addrlen) { return -1; } LWS_VISIBLE void lws_plat_insert_socket_into_fds(struct lws_context *context, struct lws *wsi) { struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; pt->fds[pt->fds_count++].revents = 0; } LWS_VISIBLE void lws_plat_delete_socket_from_fds(struct lws_context *context, struct lws *wsi, int m) { struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; pt->fds_count--; } LWS_VISIBLE void lws_plat_service_periodic(struct lws_context *context) { } LWS_VISIBLE int lws_plat_change_pollfd(struct lws_context *context, struct lws *wsi, struct lws_pollfd *pfd) { return 0; } LWS_VISIBLE const char * lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt) { //return inet_ntop(af, src, dst, cnt); return "lws_plat_inet_ntop"; } LWS_VISIBLE int lws_plat_inet_pton(int af, const char *src, void *dst) { //return inet_pton(af, src, dst); return 1; } LWS_VISIBLE lws_fop_fd_t _lws_plat_file_open(lws_plat_file_open(struct lws_plat_file_ops *fops, const char *filename, lws_fop_flags_t *flags) { return NULL; } LWS_VISIBLE int _lws_plat_file_close(lws_fop_fd_t *fop_fd) { return 0; } LWS_VISIBLE lws_fileofs_t _lws_plat_file_seek_cur(lws_fop_fd_t fop_fd, lws_fileofs_t offset) { return 0; } LWS_VISIBLE int _lws_plat_file_read(lws_fop_fd_t fop_fd, lws_filepos_t *amount, uint8_t *buf, lws_filepos_t len) { return 0; } LWS_VISIBLE int _lws_plat_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount, uint8_t *buf, lws_filepos_t len) { return 0; } LWS_VISIBLE int lws_plat_init(struct lws_context *context, struct lws_context_creation_info *info) { /* master context has the global fd lookup array */ context->lws_lookup = lws_zalloc(sizeof(struct lws *) * context->max_fds, "lws_lookup"); 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: %5lu bytes\n", (long)sizeof(struct lws *) * context->max_fds); #ifdef LWS_WITH_PLUGINS if (info->plugin_dirs) lws_plat_plugins_init(context, info->plugin_dirs); #endif return 0; }