if (!strcmp(&file[n - 4], ".ttf"))
return "application/x-font-ttf";
+ if (!strcmp(&file[n - 4], ".otf"))
+ return "application/font-woff";
+
if (!strcmp(&file[n - 5], ".woff"))
return "application/font-woff";
const struct lws_plat_file_ops *fops;
const char *vpath;
lws_fop_flags_t fflags = LWS_O_RDONLY;
+#if defined(WIN32) && defined(LWS_HAVE__STAT32I64)
+ struct _stat32i64 st;
+#else
struct stat st;
+#endif
int spin = 0;
#endif
char path[256], sym[512];
goto bail;
}
#else
+#if defined(LWS_HAVE__STAT32I64)
+ if (_stat32i64(path, &st)) {
+ lwsl_info("unable to stat %s\n", path);
+ goto bail;
+ }
+#else
if (stat(path, &st)) {
lwsl_info("unable to stat %s\n", path);
goto bail;
}
#endif
+#endif
wsi->u.http.fop_fd->mod_time = (uint32_t)st.st_mtime;
fflags |= LWS_FOP_FLAG_MOD_TIME_VALID;
lws_hdr_copy(wsi, content_length_str,
sizeof(content_length_str) - 1,
WSI_TOKEN_HTTP_CONTENT_LENGTH);
- wsi->u.http.content_length = atoi(content_length_str);
+ wsi->u.http.content_length = atoll(content_length_str);
}
if (wsi->http2_substream) {
NULL, /* replace with cgi path */
NULL
};
- unsigned char *p, *end, buffer[1024];
lwsl_debug("%s: cgi\n", __func__);
cmd[0] = hit->origin;
lwsl_err("%s: cgi failed\n", __func__);
return -1;
}
- p = buffer + LWS_PRE;
- end = p + sizeof(buffer) - LWS_PRE;
-
- if (lws_add_http_header_status(wsi, HTTP_STATUS_OK, &p, end))
- return 1;
- if (lws_add_http_header_by_token(wsi, WSI_TOKEN_CONNECTION,
- (unsigned char *)"close", 5, &p, end))
- return 1;
- n = lws_write(wsi, buffer + LWS_PRE,
- p - (buffer + LWS_PRE),
- LWS_WRITE_HTTP_HEADERS);
goto deal_body;
}
#endif
}
-
int
lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len)
{
*/
lwsl_info("defaulting to prot handler %d\n",
wsi->vhost->default_protocol_index);
- n = 0;
+ n = wsi->vhost->default_protocol_index;
wsi->protocol = &wsi->vhost->protocols[
(int)wsi->vhost->default_protocol_index];
}
goto bail_nuke_ah;
}
- /*
- * stitch protocol choice into the vh protocol linked list
- * We always insert ourselves at the start of the list
- *
- * X <-> B
- * X <-> pAn <-> pB
- */
- //lwsl_err("%s: pre insert vhost start wsi %p, that wsi prev == %p\n",
- // __func__,
- // wsi->vhost->same_vh_protocol_list[n],
- // wsi->same_vh_protocol_prev);
- wsi->same_vh_protocol_prev = /* guy who points to us */
- &wsi->vhost->same_vh_protocol_list[n];
- wsi->same_vh_protocol_next = /* old first guy is our next */
- wsi->vhost->same_vh_protocol_list[n];
- /* we become the new first guy */
- wsi->vhost->same_vh_protocol_list[n] = wsi;
-
- if (wsi->same_vh_protocol_next)
- /* old first guy points back to us now */
- wsi->same_vh_protocol_next->same_vh_protocol_prev =
- &wsi->same_vh_protocol_next;
-
-
+ lws_same_vh_protocol_insert(wsi, n);
/* we are upgrading to ws, so http/1.1 and keepalive +
* pipelined header considerations about keeping the ah around
*/
if (wsi->vhost->use_ssl &&
- wsi->context->simultaneous_ssl == wsi->context->simultaneous_ssl_restriction) {
+ wsi->context->simultaneous_ssl_restriction &&
+ wsi->context->simultaneous_ssl ==
+ wsi->context->simultaneous_ssl_restriction) {
lwsl_info("%s: simultaneous_ssl_restriction and nothing pipelined\n", __func__);
return 1;
}
{
struct lws_context *context = vh->context;
struct lws *new_wsi = lws_create_new_server_wsi(vh);
+ struct lws_context_per_thread *pt;
int n, ssl = 0;
if (!new_wsi) {
compatible_close(fd.sockfd);
return NULL;
}
+ pt = &context->pt[(int)new_wsi->tsi];
+ lws_stats_atomic_bump(context, pt, LWSSTATS_C_CONNECTIONS, 1);
if (parent) {
new_wsi->parent = parent;
vh_prot_name, new_wsi->vhost->name);
goto bail;
}
- if (lws_ensure_user_space(new_wsi))
+ if (lws_ensure_user_space(new_wsi)) {
+ lwsl_notice("OOM trying to get user_space\n");
goto bail;
+ }
} else
- new_wsi->protocol = &context->vhost_list->
- protocols[vh->default_protocol_index];
+ if (type & LWS_ADOPT_HTTP) /* he will transition later */
+ new_wsi->protocol =
+ &vh->protocols[vh->default_protocol_index];
+ else { /* this is the only time he will transition */
+ lws_bind_protocol(new_wsi,
+ &vh->protocols[vh->raw_protocol_index]);
+ lws_union_transition(new_wsi, LWSCM_RAW);
+ }
if (type & LWS_ADOPT_SOCKET) { /* socket desc */
lwsl_debug("%s: new wsi %p, sockfd %d\n", __func__, new_wsi,
(int)(size_t)fd.sockfd);
- /* the transport is accepted... give him time to negotiate */
- lws_set_timeout(new_wsi, PENDING_TIMEOUT_ESTABLISH_WITH_SERVER,
- context->timeout_secs);
+ if (type & LWS_ADOPT_HTTP)
+ /* the transport is accepted...
+ * give him time to negotiate */
+ lws_set_timeout(new_wsi,
+ PENDING_TIMEOUT_ESTABLISH_WITH_SERVER,
+ context->timeout_secs);
#if LWS_POSIX == 0
#if defined(LWS_WITH_ESP8266)
else
n = LWS_CALLBACK_RAW_ADOPT;
}
- if ((new_wsi->protocol->callback)(
- new_wsi, n, NULL, NULL, 0)) {
- if (type & LWS_ADOPT_SOCKET) {
- /* force us off the timeout list by hand */
- lws_set_timeout(new_wsi, NO_PENDING_TIMEOUT, 0);
- compatible_close(new_wsi->desc.sockfd);
- }
- goto bail;
- }
if (!LWS_SSL_ENABLED(new_wsi->vhost) || !(type & LWS_ADOPT_ALLOW_SSL) ||
!(type & LWS_ADOPT_SOCKET)) {
goto fail;
}
- if (type & LWS_ADOPT_HTTP)
- if (!lws_header_table_attach(new_wsi, 0))
+ /*
+ * by deferring callback to this point, after insertion to fds,
+ * lws_callback_on_writable() can work from the callback
+ */
+ if ((new_wsi->protocol->callback)(
+ new_wsi, n, new_wsi->user_space, NULL, 0))
+ goto fail;
+
+ if (type & LWS_ADOPT_HTTP) {
+ if (!lws_header_table_attach(new_wsi, 0)) {
lwsl_debug("Attached ah immediately\n");
+ } else {
+ lwsl_notice("%s: waiting for ah\n", __func__);
+ }
+ }
return new_wsi;
return NULL;
bail:
+ lwsl_notice("%s: exiting on bail\n", __func__);
if (parent)
parent->child_list = new_wsi->sibling_list;
if (new_wsi->user_space)
lws_free(new_wsi->user_space);
lws_free(new_wsi);
+ compatible_close(fd.sockfd);
return NULL;
}
struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
lws_sockfd_type accept_fd = LWS_SOCK_INVALID;
struct allocated_headers *ah;
+ lws_sock_file_fd_type fd;
+ int opts = LWS_ADOPT_SOCKET | LWS_ADOPT_ALLOW_SSL;
#if LWS_POSIX
- struct sockaddr_in cli_addr;
+ struct sockaddr_storage cli_addr;
socklen_t clilen;
#endif
int n, len;
}
if (wsi->mode == LWSCM_RAW) {
+ lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_WRITEABLE_CB, 1);
+#if defined(LWS_WITH_STATS)
+ {
+ uint64_t ul = time_in_microseconds() - wsi->active_writable_req_us;
+
+ lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_MS_WRITABLE_DELAY, ul);
+ lws_stats_atomic_max(wsi->context, pt, LWSSTATS_MS_WORST_WRITABLE_DELAY, ul);
+ wsi->active_writable_req_us = 0;
+ }
+#endif
n = user_callback_handle_rxflow(wsi->protocol->callback,
wsi, LWS_CALLBACK_RAW_WRITEABLE,
wsi->user_space, NULL, 0);
break;
if (wsi->state != LWSS_HTTP_ISSUING_FILE) {
+
+ lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_WRITEABLE_CB, 1);
+#if defined(LWS_WITH_STATS)
+ {
+ uint64_t ul = time_in_microseconds() - wsi->active_writable_req_us;
+
+ lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_MS_WRITABLE_DELAY, ul);
+ lws_stats_atomic_max(wsi->context, pt, LWSSTATS_MS_WORST_WRITABLE_DELAY, ul);
+ wsi->active_writable_req_us = 0;
+ }
+#endif
+
n = user_callback_handle_rxflow(wsi->protocol->callback,
wsi, LWS_CALLBACK_HTTP_WRITEABLE,
wsi->user_space, NULL, 0);
*/
if (wsi->vhost->use_ssl &&
- context->simultaneous_ssl == context->simultaneous_ssl_restriction)
+ context->simultaneous_ssl_restriction &&
+ context->simultaneous_ssl ==
+ context->simultaneous_ssl_restriction)
/* no... ignore it, he won't come again until we are
* below the simultaneous_ssl_restriction limit and
* POLLIN is enabled on him again
lws_plat_set_socket_options(wsi->vhost, accept_fd);
- lwsl_debug("accepted new conn port %u on fd=%d\n",
- ntohs(cli_addr.sin_port), accept_fd);
+#if defined(LWS_USE_IPV6)
+ lwsl_debug("accepted new conn port %u on fd=%d\n",
+ ((cli_addr.ss_family == AF_INET6) ?
+ ntohs(((struct sockaddr_in6 *) &cli_addr)->sin6_port) :
+ ntohs(((struct sockaddr_in *) &cli_addr)->sin_port)),
+ accept_fd);
+#else
+ lwsl_debug("accepted new conn port %u on fd=%d\n",
+ ntohs(((struct sockaddr_in *) &cli_addr)->sin_port),
+ accept_fd);
+#endif
#else
/* not very beautiful... */
break;
}
- if (!lws_adopt_socket_vhost(wsi->vhost, accept_fd))
+ if (!(wsi->vhost->options & LWS_SERVER_OPTION_ONLY_RAW))
+ opts |= LWS_ADOPT_HTTP;
+
+ fd.sockfd = accept_fd;
+ if (!lws_adopt_descriptor_vhost(wsi->vhost, opts, fd,
+ NULL, NULL))
/* already closed cleanly as necessary */
return 1;
unsigned char *response = pt->serv_buf + LWS_PRE;
unsigned char *p = response;
unsigned char *end = p + context->pt_serv_buf_size - LWS_PRE;
- unsigned long computed_total_content_length;
+ lws_filepos_t computed_total_content_length;
int ret = 0, cclen = 8, n = HTTP_STATUS_OK;
lws_fop_flags_t fflags = LWS_O_RDONLY;
#if defined(LWS_WITH_RANGES)
* Precompute it for the main response header
*/
- computed_total_content_length = (unsigned long)rp->agg +
+ computed_total_content_length = (lws_filepos_t)rp->agg +
6 /* final _lws\r\n */;
lws_ranges_reset(rp);
}
if (ranges == 1) {
- computed_total_content_length = (unsigned long)rp->agg;
+ computed_total_content_length = (lws_filepos_t)rp->agg;
n = lws_snprintf(cache_control, sizeof(cache_control), "bytes %llu-%llu/%llu",
rp->start, rp->end, rp->extent);