context = wsi->context;
pt = &context->pt[(int)wsi->tsi];
+ lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_API_CLOSE, 1);
/* if we have children, close them first */
if (wsi->child_list) {
}
pcgi = &(*pcgi)->cgi_list;
}
+ if (wsi->cgi->headers_buf) {
+ lwsl_debug("close: freed cgi headers\n");
+ lws_free_set_NULL(wsi->cgi->headers_buf);
+ }
/* we have a cgi going, we must kill it */
wsi->cgi->being_closed = 1;
lws_cgi_kill(wsi);
!wsi->socket_is_permanently_unusable) {
#ifdef LWS_OPENSSL_SUPPORT
if (lws_is_ssl(wsi) && wsi->ssl)
- {
- lwsl_info("%s: shutting down SSL connection: %p (ssl %p, sock %d, state %d)\n", __func__, wsi, wsi->ssl, (int)(long)wsi->desc.sockfd, wsi->state);
+ {
+ lwsl_info("%s: shutting down SSL connection: %p (ssl %p, sock %d, state %d)\n", __func__, wsi, wsi->ssl, (int)(long)wsi->desc.sockfd, wsi->state);
n = SSL_shutdown(wsi->ssl);
- if (n == 1) /* If finished the SSL shutdown, then do socket shutdown, else need to retry SSL shutdown */
- n = shutdown(wsi->desc.sockfd, SHUT_WR);
- else
- lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN);
- }
+ if (n == 1) /* If finished the SSL shutdown, then do socket shutdown, else need to retry SSL shutdown */
+ n = shutdown(wsi->desc.sockfd, SHUT_WR);
+ else if (n == 0)
+ lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN);
+ else /* n < 0 */
+ {
+ int shutdown_error = SSL_get_error(wsi->ssl, n);
+ lwsl_debug("SSL_shutdown returned %d, SSL_get_error: %d\n", n, shutdown_error);
+ if (shutdown_error == SSL_ERROR_WANT_READ) {
+ lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN);
+ n = 0;
+ } else if (shutdown_error == SSL_ERROR_WANT_WRITE) {
+ lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLOUT);
+ n = 0;
+ } else { // actual error occurred, just close the connection
+ n = shutdown(wsi->desc.sockfd, SHUT_WR);
+ }
+ }
+ }
else
#endif
{
return -1;
}
+#if defined(LWS_WITH_SOCKS5)
+LWS_VISIBLE int
+lws_set_socks(struct lws_vhost *vhost, const char *socks)
+{
+#if !defined(LWS_WITH_ESP8266)
+ char *p_at, *p_colon;
+ char user[96];
+ char password[96];
+
+ if (!socks)
+ return -1;
+
+ vhost->socks_user[0] = '\0';
+ vhost->socks_password[0] = '\0';
+
+ p_at = strchr(socks, '@');
+ if (p_at) { /* auth is around */
+ if ((unsigned int)(p_at - socks) > (sizeof(user)
+ + sizeof(password) - 2)) {
+ lwsl_err("Socks auth too long\n");
+ goto bail;
+ }
+
+ p_colon = strchr(socks, ':');
+ if (p_colon) {
+ if ((unsigned int)(p_colon - socks) > (sizeof(user)
+ - 1) ) {
+ lwsl_err("Socks user too long\n");
+ goto bail;
+ }
+ if ((unsigned int)(p_at - p_colon) > (sizeof(password)
+ - 1) ) {
+ lwsl_err("Socks password too long\n");
+ goto bail;
+ }
+ }
+ strncpy(vhost->socks_user, socks, p_colon - socks);
+ strncpy(vhost->socks_password, p_colon + 1,
+ p_at - (p_colon + 1));
+
+ lwsl_info(" Socks auth, user: %s, password: %s\n",
+ vhost->socks_user, vhost->socks_password );
+
+ socks = p_at + 1;
+ }
+
+ strncpy(vhost->socks_proxy_address, socks,
+ sizeof(vhost->socks_proxy_address) - 1);
+ vhost->socks_proxy_address[sizeof(vhost->socks_proxy_address) - 1]
+ = '\0';
+
+ p_colon = strchr(vhost->socks_proxy_address, ':');
+ if (!p_colon && !vhost->socks_proxy_port) {
+ lwsl_err("socks_proxy needs to be address:port\n");
+ return -1;
+ } else {
+ if (p_colon) {
+ *p_colon = '\0';
+ vhost->socks_proxy_port = atoi(p_colon + 1);
+ }
+ }
+
+ lwsl_info(" Socks %s:%u\n", vhost->socks_proxy_address,
+ vhost->socks_proxy_port);
+
+ return 0;
+
+bail:
+#endif
+ return -1;
+}
+#endif
+
LWS_VISIBLE const struct lws_protocols *
lws_get_protocol(struct lws *wsi)
{
#endif
struct sockaddr_in serv_addr4;
#ifndef LWS_PLAT_OPTEE
- socklen_t len = sizeof(struct sockaddr);
+ socklen_t len = sizeof(struct sockaddr_storage);
#endif
int n;
- struct sockaddr_in sin;
+ struct sockaddr_storage sin;
struct sockaddr *v;
#ifdef LWS_USE_UNIX_SOCK
v = (struct sockaddr *)&serv_addr6;
n = sizeof(struct sockaddr_in6);
bzero((char *) &serv_addr6, sizeof(serv_addr6));
- if (iface &&
- interface_to_sa(vhost, iface,
- (struct sockaddr_in *)v, n) < 0) {
- lwsl_err("Unable to find interface %s\n", iface);
- return -1;
- }
-
if (iface) {
- struct ifaddrs *addrs, *addr;
- char ip[NI_MAXHOST];
- unsigned int i;
-
- getifaddrs(&addrs);
- for (addr = addrs; addr; addr = addr->ifa_next) {
- if (!addr->ifa_addr ||
- addr->ifa_addr->sa_family != AF_INET6)
- continue;
-
- getnameinfo(addr->ifa_addr,
- sizeof(struct sockaddr_in6),
- ip, sizeof(ip),
- NULL, 0, NI_NUMERICHOST);
-
- i = 0;
- while (ip[i])
- if (ip[i++] == '%') {
- ip[i - 1] = '\0';
- break;
- }
-
- if (!strcmp(ip, iface)) {
- serv_addr6.sin6_scope_id =
- if_nametoindex(addr->ifa_name);
- break;
- }
+ if (interface_to_sa(vhost, iface,
+ (struct sockaddr_in *)v, n) < 0) {
+ lwsl_err("Unable to find interface %s\n", iface);
+ return -1;
}
- freeifaddrs(addrs);
+ serv_addr6.sin6_scope_id = lws_get_addr_scope(iface);
}
serv_addr6.sin6_family = AF_INET6;
lwsl_warn("getsockname: %s\n", strerror(LWS_ERRNO));
else
#endif
- port = ntohs(sin.sin_port);
+#if defined(LWS_USE_IPV6)
+ port = (sin.ss_family == AF_INET6) ?
+ ntohs(((struct sockaddr_in6 *) &sin)->sin6_port) :
+ ntohs(((struct sockaddr_in *) &sin)->sin_port);
+#else
+ port = ntohs(((struct sockaddr_in *) &sin)->sin_port);
+#endif
#endif
return port;
}
+#if defined(LWS_USE_IPV6)
+LWS_EXTERN unsigned long
+lws_get_addr_scope(const char *ipaddr)
+{
+ unsigned long scope = 0;
+
+#ifndef WIN32
+ struct ifaddrs *addrs, *addr;
+ char ip[NI_MAXHOST];
+ unsigned int i;
+
+ getifaddrs(&addrs);
+ for (addr = addrs; addr; addr = addr->ifa_next) {
+ if (!addr->ifa_addr ||
+ addr->ifa_addr->sa_family != AF_INET6)
+ continue;
+
+ getnameinfo(addr->ifa_addr,
+ sizeof(struct sockaddr_in6),
+ ip, sizeof(ip),
+ NULL, 0, NI_NUMERICHOST);
+
+ i = 0;
+ while (ip[i])
+ if (ip[i++] == '%') {
+ ip[i - 1] = '\0';
+ break;
+ }
+
+ if (!strcmp(ip, ipaddr)) {
+ scope = if_nametoindex(addr->ifa_name);
+ break;
+ }
+ }
+ freeifaddrs(addrs);
+#else
+ PIP_ADAPTER_ADDRESSES adapter, addrs = NULL;
+ PIP_ADAPTER_UNICAST_ADDRESS addr;
+ ULONG size = 0;
+ DWORD ret;
+ struct sockaddr_in6 *sockaddr;
+ char ip[NI_MAXHOST];
+ unsigned int i;
+ int found = 0;
+
+ for (i = 0; i < 5; i++)
+ {
+ ret = GetAdaptersAddresses(AF_INET6, GAA_FLAG_INCLUDE_PREFIX,
+ NULL, addrs, &size);
+ if ((ret == NO_ERROR) || (ret == ERROR_NO_DATA)) {
+ break;
+ } else if (ret == ERROR_BUFFER_OVERFLOW)
+ {
+ if (addrs)
+ free(addrs);
+ addrs = (IP_ADAPTER_ADDRESSES *) malloc(size);
+ } else
+ {
+ if (addrs)
+ {
+ free(addrs);
+ addrs = NULL;
+ }
+ lwsl_err("Failed to get IPv6 address table (%d)", ret);
+ break;
+ }
+ }
+
+ if ((ret == NO_ERROR) && (addrs))
+ {
+ adapter = addrs;
+ while ((adapter) && (!found))
+ {
+ addr = adapter->FirstUnicastAddress;
+ while ((addr) && (!found))
+ {
+ if (addr->Address.lpSockaddr->sa_family == AF_INET6)
+ {
+ sockaddr = (struct sockaddr_in6 *) (addr->Address.lpSockaddr);
+
+ lws_plat_inet_ntop(sockaddr->sin6_family, &sockaddr->sin6_addr,
+ ip, sizeof(ip));
+
+ if (!strcmp(ip, ipaddr)) {
+ scope = sockaddr->sin6_scope_id;
+ found = 1;
+ break;
+ }
+ }
+ addr = addr->Next;
+ }
+ adapter = adapter->Next;
+ }
+ }
+ if (addrs)
+ free(addrs);
+#endif
+
+ return scope;
+}
+#endif
+
LWS_EXTERN void
lws_restart_ws_ping_pong_timer(struct lws *wsi)
{
return -1;
}
+ wsi->cgi->response_code = HTTP_STATUS_OK;
+
cgi = wsi->cgi;
cgi->wsi = wsi; /* set cgi's owning wsi */
* process is OK. Stuff that happens after the execvpe() is OK.
*/
- for (n = 0; n < 3; n++)
+ for (n = 0; n < 3; n++) {
if (dup2(cgi->pipe_fds[n][!(n == 0)], n) < 0) {
lwsl_err("%s: stdin dup2 failed\n", __func__);
goto bail3;
}
+ close(cgi->pipe_fds[n][!(n == 0)]);
+ }
#if !defined(LWS_HAVE_VFORK) || !defined(LWS_HAVE_EXECVPE)
for (m = 0; m < n; m++) {
return -1;
}
+/* we have to parse out these headers in the CGI output */
+
+static const char * const significant_hdr[SIGNIFICANT_HDR_COUNT] = {
+ "content-length: ",
+ "location: ",
+ "status: ",
+ "transfer-encoding: chunked",
+};
+
LWS_VISIBLE LWS_EXTERN int
lws_cgi_write_split_stdout_headers(struct lws *wsi)
{
- int n, m, match = 0, lp = 0;
- static const char * const content_length = "content-length: ";
- char buf[LWS_PRE + 1024], *start = &buf[LWS_PRE], *p = start,
- *end = &buf[sizeof(buf) - 1 - LWS_PRE], c, l[12];
+ int n, m;
+ unsigned char buf[LWS_PRE + 1024], *start = &buf[LWS_PRE], *p = start,
+ *end = &buf[sizeof(buf) - 1 - LWS_PRE];
+ char c;
if (!wsi->cgi)
return -1;
* payload chunks, since they need to be
* handled separately
*/
+
+ switch (wsi->hdr_state) {
+
+ case LHCS_RESPONSE:
+ lwsl_info("LHCS_RESPONSE: issuing response %d\n",
+ wsi->cgi->response_code);
+ if (lws_add_http_header_status(wsi, wsi->cgi->response_code, &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, start, p - start,
+ LWS_WRITE_HTTP_HEADERS);
+
+ /* finalize cached headers before dumping them */
+ if (lws_finalize_http_header(wsi,
+ (unsigned char **)&wsi->cgi->headers_pos,
+ (unsigned char *)wsi->cgi->headers_end)) {
+
+ lwsl_notice("finalize failed\n");
+ return -1;
+ }
+
+ wsi->hdr_state = LHCS_DUMP_HEADERS;
+ wsi->reason_bf |= 8;
+ lws_callback_on_writable(wsi);
+ /* back to the loop for writeability again */
+ return 0;
+
+ case LHCS_DUMP_HEADERS:
+
+ n = wsi->cgi->headers_pos - wsi->cgi->headers_dumped;
+ if (n > 512)
+ n = 512;
+
+ lwsl_debug("LHCS_DUMP_HEADERS: %d\n", n);
+
+ m = lws_write(wsi, (unsigned char *)wsi->cgi->headers_dumped,
+ n, LWS_WRITE_HTTP_HEADERS);
+ if (m < 0) {
+ lwsl_debug("%s: write says %d\n", __func__, m);
+ return -1;
+ }
+ wsi->cgi->headers_dumped += n;
+ if (wsi->cgi->headers_dumped == wsi->cgi->headers_pos) {
+ wsi->hdr_state = LHCS_PAYLOAD;
+ lws_free_set_NULL(wsi->cgi->headers_buf);
+ lwsl_debug("freed cgi headers\n");
+ } else {
+ wsi->reason_bf |= 8;
+ lws_callback_on_writable(wsi);
+ }
+
+ /* writeability becomes uncertain now we wrote
+ * something, we must return to the event loop
+ */
+ return 0;
+ }
+
+ if (!wsi->cgi->headers_buf) {
+ /* if we don't already have a headers buf, cook one up */
+ n = 2048;
+ wsi->cgi->headers_buf = malloc(n);
+ if (!wsi->cgi->headers_buf) {
+ lwsl_err("OOM\n");
+ return -1;
+ }
+
+ lwsl_debug("allocated cgi hdrs\n");
+ wsi->cgi->headers_pos = wsi->cgi->headers_buf;
+ wsi->cgi->headers_dumped = wsi->cgi->headers_pos;
+ wsi->cgi->headers_end = wsi->cgi->headers_buf + n - 1;
+
+ for (n = 0; n < SIGNIFICANT_HDR_COUNT; n++) {
+ wsi->cgi->match[n] = 0;
+ wsi->cgi->lp = 0;
+ }
+ }
+
n = read(lws_get_socket_fd(wsi->cgi->stdwsi[LWS_STDOUT]), &c, 1);
if (n < 0) {
if (errno != EAGAIN) {
}
else
n = 0;
+
+ if (wsi->cgi->headers_pos >= wsi->cgi->headers_end - 4) {
+ lwsl_notice("CGI headers larger than buffer size\n");
+
+ return -1;
+ }
}
if (n) {
- lwsl_debug("-- 0x%02X %c\n", (unsigned char)c, c);
+ lwsl_debug("-- 0x%02X %c %d %d\n", (unsigned char)c, c, wsi->cgi->match[1], wsi->hdr_state);
+ if (!c)
+ return -1;
switch (wsi->hdr_state) {
case LCHS_HEADER:
- if (!content_length[match] &&
- (c >= '0' && c <= '9') &&
- lp < sizeof(l) - 1) {
- l[lp++] = c;
- l[lp] = '\0';
- wsi->cgi->content_length = atol(l);
+ hdr:
+ for (n = 0; n < SIGNIFICANT_HDR_COUNT; n++) {
+ /* significant headers with numeric decimal payloads */
+ if (!significant_hdr[n][wsi->cgi->match[n]] &&
+ (c >= '0' && c <= '9') &&
+ wsi->cgi->lp < sizeof(wsi->cgi->l) - 1) {
+ wsi->cgi->l[wsi->cgi->lp++] = c;
+ wsi->cgi->l[wsi->cgi->lp] = '\0';
+ switch (n) {
+ case SIGNIFICANT_HDR_CONTENT_LENGTH:
+ wsi->cgi->content_length = atol(wsi->cgi->l);
+ break;
+ case SIGNIFICANT_HDR_STATUS:
+ wsi->cgi->response_code = atol(wsi->cgi->l);
+ lwsl_debug("Status set to %d\n", wsi->cgi->response_code);
+ break;
+ default:
+ break;
+ }
+ }
+ /* hits up to the NUL are sticky until next hdr */
+ if (significant_hdr[n][wsi->cgi->match[n]]) {
+ if (tolower(c) == significant_hdr[n][wsi->cgi->match[n]])
+ wsi->cgi->match[n]++;
+ else
+ wsi->cgi->match[n] = 0;
+ }
}
- if (tolower(c) == content_length[match])
- match++;
- else
- match = 0;
/* some cgi only send us \x0a for EOL */
if (c == '\x0a') {
wsi->hdr_state = LCHS_SINGLE_0A;
- *p++ = '\x0d';
+ *wsi->cgi->headers_pos++ = '\x0d';
}
- *p++ = c;
- if (c == '\x0d') {
+ *wsi->cgi->headers_pos++ = c;
+ if (c == '\x0d')
wsi->hdr_state = LCHS_LF1;
- break;
+
+ if (wsi->hdr_state != LCHS_HEADER &&
+ !significant_hdr[SIGNIFICANT_HDR_TRANSFER_ENCODING][wsi->cgi->match[SIGNIFICANT_HDR_TRANSFER_ENCODING]]) {
+ lwsl_debug("cgi produced chunked\n");
+ wsi->cgi->explicitly_chunked = 1;
+ }
+
+ /* presence of Location: mandates 302 retcode */
+ if (wsi->hdr_state != LCHS_HEADER &&
+ !significant_hdr[SIGNIFICANT_HDR_LOCATION][wsi->cgi->match[SIGNIFICANT_HDR_LOCATION]]) {
+ lwsl_debug("CGI: Location hdr seen\n");
+ wsi->cgi->response_code = 302;
}
break;
case LCHS_LF1:
- *p++ = c;
+ *wsi->cgi->headers_pos++ = c;
if (c == '\x0a') {
wsi->hdr_state = LCHS_CR2;
break;
break;
}
wsi->hdr_state = LCHS_HEADER;
- match = 0;
- *p++ = c;
- break;
+ for (n = 0; n < SIGNIFICANT_HDR_COUNT; n++)
+ wsi->cgi->match[n] = 0;
+ wsi->cgi->lp = 0;
+ goto hdr;
+
case LCHS_LF2:
case LCHS_SINGLE_0A:
m = wsi->hdr_state;
if (c == '\x0a') {
lwsl_debug("Content-Length: %ld\n", wsi->cgi->content_length);
- wsi->hdr_state = LHCS_PAYLOAD;
+ wsi->hdr_state = LHCS_RESPONSE;
/* drop the \0xa ... finalize will add it if needed */
- if (lws_finalize_http_header(wsi,
- (unsigned char **)&p,
- (unsigned char *)end))
- return -1;
break;
}
if (m == LCHS_LF2)
/* we got \r\n\r[^\n]... it's unreasonable */
return -1;
/* we got \x0anext header, it's reasonable */
- *p++ = c;
+ *wsi->cgi->headers_pos++ = c;
wsi->hdr_state = LCHS_HEADER;
+ for (n = 0; n < SIGNIFICANT_HDR_COUNT; n++)
+ wsi->cgi->match[n] = 0;
+ wsi->cgi->lp = 0;
break;
case LHCS_PAYLOAD:
break;
}
/* ran out of input, ended the headers, or filled up the headers buf */
- if (!n || wsi->hdr_state == LHCS_PAYLOAD || (p + 4) == end) {
-
- m = lws_write(wsi, (unsigned char *)start,
- p - start, LWS_WRITE_HTTP_HEADERS);
- if (m < 0) {
- lwsl_debug("%s: write says %d\n", __func__, m);
- return -1;
- }
- /* writeability becomes uncertain now we wrote
- * something, we must return to the event loop
- */
-
+ if (!n || wsi->hdr_state == LHCS_PAYLOAD)
return 0;
- }
}
+ /* payload processing */
+
n = read(lws_get_socket_fd(wsi->cgi->stdwsi[LWS_STDOUT]),
start, sizeof(buf) - LWS_PRE);
if (cgi->pid <= 0)
continue;
+ /* finish sending cached headers */
+ if (cgi->headers_buf)
+ continue;
+
/* wait for stdout to be drained */
if (cgi->content_length > cgi->content_length_seen)
continue;
lwsl_debug("%s: found PID %d on cgi list\n",
__func__, n);
- if (!cgi->content_length) {
+ if (!cgi->content_length && cgi->explicitly_chunked) {
/*
* well, if he sends chunked... give him 5s after the
* cgi terminated to send buffered
goto finish_him;
}
+ /* finish sending cached headers */
+ if (cgi->headers_buf)
+ continue;
+
/* wait for stdout to be drained */
if (cgi->content_length > cgi->content_length_seen)
continue;
}
#endif
+
+#if defined(LWS_WITH_STATS)
+
+LWS_VISIBLE LWS_EXTERN uint64_t
+lws_stats_get(struct lws_context *context, int index)
+{
+ if (index >= LWSSTATS_SIZE)
+ return 0;
+
+ return context->lws_stats[index];
+}
+
+LWS_VISIBLE LWS_EXTERN void
+lws_stats_log_dump(struct lws_context *context)
+{
+ struct lws_vhost *v = context->vhost_list;
+ int n;
+
+ if (!context->updated)
+ return;
+
+ context->updated = 0;
+
+ lwsl_notice("\n");
+ lwsl_notice("LWS internal statistics dump ----->\n");
+ lwsl_notice("LWSSTATS_C_CONNECTIONS: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_C_CONNECTIONS));
+ lwsl_notice("LWSSTATS_C_API_CLOSE: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_C_API_CLOSE));
+ lwsl_notice("LWSSTATS_C_API_READ: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_C_API_READ));
+ lwsl_notice("LWSSTATS_C_API_LWS_WRITE: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_C_API_LWS_WRITE));
+ lwsl_notice("LWSSTATS_C_API_WRITE: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_C_API_WRITE));
+ lwsl_notice("LWSSTATS_C_WRITE_PARTIALS: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_C_WRITE_PARTIALS));
+ lwsl_notice("LWSSTATS_C_WRITEABLE_CB_REQ: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_C_WRITEABLE_CB_REQ));
+ lwsl_notice("LWSSTATS_C_WRITEABLE_CB_EFF_REQ: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_C_WRITEABLE_CB_EFF_REQ));
+ lwsl_notice("LWSSTATS_C_WRITEABLE_CB: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_C_WRITEABLE_CB));
+ lwsl_notice("LWSSTATS_C_SSL_CONNECTIONS_FAILED: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_C_SSL_CONNECTIONS_FAILED));
+ lwsl_notice("LWSSTATS_C_SSL_CONNECTIONS_ACCEPTED: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_C_SSL_CONNECTIONS_ACCEPTED));
+ lwsl_notice("LWSSTATS_C_SSL_CONNS_HAD_RX: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_C_SSL_CONNS_HAD_RX));
+
+ lwsl_notice("LWSSTATS_C_TIMEOUTS: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_C_TIMEOUTS));
+ lwsl_notice("LWSSTATS_C_SERVICE_ENTRY: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_C_SERVICE_ENTRY));
+ lwsl_notice("LWSSTATS_B_READ: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_B_READ));
+ lwsl_notice("LWSSTATS_B_WRITE: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_B_WRITE));
+ lwsl_notice("LWSSTATS_B_PARTIALS_ACCEPTED_PARTS: %8llu\n", (unsigned long long)lws_stats_get(context, LWSSTATS_B_PARTIALS_ACCEPTED_PARTS));
+ lwsl_notice("LWSSTATS_MS_SSL_CONNECTIONS_ACCEPTED_DELAY: %8llums\n", (unsigned long long)lws_stats_get(context, LWSSTATS_MS_SSL_CONNECTIONS_ACCEPTED_DELAY) / 1000);
+ if (lws_stats_get(context, LWSSTATS_C_SSL_CONNECTIONS_ACCEPTED))
+ lwsl_notice(" Avg accept delay: %8llums\n",
+ (unsigned long long)(lws_stats_get(context, LWSSTATS_MS_SSL_CONNECTIONS_ACCEPTED_DELAY) /
+ lws_stats_get(context, LWSSTATS_C_SSL_CONNECTIONS_ACCEPTED)) / 1000);
+ lwsl_notice("LWSSTATS_MS_SSL_RX_DELAY: %8llums\n", (unsigned long long)lws_stats_get(context, LWSSTATS_MS_SSL_RX_DELAY) / 1000);
+ if (lws_stats_get(context, LWSSTATS_C_SSL_CONNS_HAD_RX))
+ lwsl_notice(" Avg accept-rx delay: %8llums\n",
+ (unsigned long long)(lws_stats_get(context, LWSSTATS_MS_SSL_RX_DELAY) /
+ lws_stats_get(context, LWSSTATS_C_SSL_CONNS_HAD_RX)) / 1000);
+
+ lwsl_notice("LWSSTATS_MS_WRITABLE_DELAY: %8lluus\n",
+ (unsigned long long)lws_stats_get(context, LWSSTATS_MS_WRITABLE_DELAY));
+ lwsl_notice("LWSSTATS_MS_WORST_WRITABLE_DELAY: %8lluus\n",
+ (unsigned long long)lws_stats_get(context, LWSSTATS_MS_WORST_WRITABLE_DELAY));
+ if (lws_stats_get(context, LWSSTATS_C_WRITEABLE_CB))
+ lwsl_notice(" Avg writable delay: %8lluus\n",
+ (unsigned long long)(lws_stats_get(context, LWSSTATS_MS_WRITABLE_DELAY) /
+ lws_stats_get(context, LWSSTATS_C_WRITEABLE_CB)));
+ lwsl_notice("Simultaneous SSL restriction: %8d/%d/%d\n", context->simultaneous_ssl,
+ context->simultaneous_ssl_restriction, context->ssl_gate_accepts);
+
+ lwsl_notice("Live wsi: %8d\n", context->count_wsi_allocated);
+
+#if defined(LWS_WITH_STATS)
+ context->updated = 1;
+#endif
+
+ while (v) {
+ if (v->use_ssl && v->lserv_wsi) {
+ struct lws_context_per_thread *pt = &context->pt[(int)v->lserv_wsi->tsi];
+ struct lws_pollfd *pfd;
+
+ pfd = &pt->fds[v->lserv_wsi->position_in_fds_table];
+
+ lwsl_notice(" Listen port %d actual POLLIN: %d\n",
+ v->listen_port, (int)pfd->events & LWS_POLLIN);
+ }
+
+ v = v->vhost_next;
+ }
+
+ for (n = 0; n < context->count_threads; n++) {
+ struct lws_context_per_thread *pt = &context->pt[n];
+ struct lws *wl;
+ int m = 0;
+
+ lwsl_notice("PT %d\n", n + 1);
+
+ lws_pt_lock(pt);
+
+ lwsl_notice(" AH in use / max: %d / %d\n",
+ pt->ah_count_in_use,
+ context->max_http_header_pool);
+
+ wl = pt->ah_wait_list;
+ while (wl) {
+ m++;
+ wl = wl->u.hdr.ah_wait_list;
+ }
+
+ lwsl_notice(" AH wait list count / actual: %d / %d\n",
+ pt->ah_wait_list_length, m);
+
+ lws_pt_unlock(pt);
+ }
+
+ lwsl_notice("\n");
+}
+
+void
+lws_stats_atomic_bump(struct lws_context * context,
+ struct lws_context_per_thread *pt, int index, uint64_t bump)
+{
+ lws_pt_lock(pt);
+ context->lws_stats[index] += bump;
+ if (index != LWSSTATS_C_SERVICE_ENTRY)
+ context->updated = 1;
+ lws_pt_unlock(pt);
+}
+
+void
+lws_stats_atomic_max(struct lws_context * context,
+ struct lws_context_per_thread *pt, int index, uint64_t val)
+{
+ lws_pt_lock(pt);
+ if (val > context->lws_stats[index]) {
+ context->lws_stats[index] = val;
+ context->updated = 1;
+ }
+ lws_pt_unlock(pt);
+}
+
+#endif