int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len)
{
struct lws_context *context = lws_get_context(wsi);
+ struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
size_t real_len = len;
unsigned int n;
int m;
+ lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_API_WRITE, 1);
+
if (!len)
return 0;
/* just ignore sends after we cleared the truncation buffer */
lwsl_warn("** error invalid sock but expected to send\n");
/* limit sending */
- n = wsi->protocol->rx_buffer_size;
- if (!n)
- n = context->pt_serv_buf_size;
+ if (wsi->protocol->tx_packet_size)
+ n = wsi->protocol->tx_packet_size;
+ else {
+ n = wsi->protocol->rx_buffer_size;
+ if (!n)
+ n = context->pt_serv_buf_size;
+ }
n += LWS_PRE + 4;
if (n > len)
n = len;
n = lws_ssl_capable_write(wsi, buf, n);
lws_latency(context, wsi, "send lws_issue_raw", n, n == len);
+ //lwsl_notice("lws_ssl_capable_write: %d\n", n);
+
switch (n) {
case LWS_SSL_CAPABLE_ERROR:
/* we're going to close, let close know sends aren't possible */
* Newly truncated send. Buffer the remainder (it will get
* first priority next time the socket is writable)
*/
- lwsl_info("%p new partial sent %d from %lu total\n", wsi, n,
+ lwsl_debug("%p new partial sent %d from %lu total\n", wsi, n,
(unsigned long)real_len);
+ lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_WRITE_PARTIALS, 1);
+ lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_B_PARTIALS_ACCEPTED_PARTS, n);
+
/*
* - if we still have a suitable malloc lying around, use it
* - or, if too small, reallocate it
int pre = 0, n;
size_t orig_len = len;
+ lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_API_LWS_WRITE, 1);
+
+ if ((int)len < 0) {
+ lwsl_err("%s: suspicious len int %d, ulong %lu\n", __func__,
+ (int)len, (unsigned long)len);
+ return -1;
+ }
+
+ lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_B_WRITE, len);
+
#ifdef LWS_WITH_ACCESS_LOG
wsi->access_log.sent += len;
#endif
wp == LWS_WRITE_HTTP_FINAL) &&
wsi->u.http.content_length) {
wsi->u.http.content_remain -= len;
- lwsl_info("%s: content_remain = %lu\n", __func__,
- (unsigned long)wsi->u.http.content_remain);
+ lwsl_info("%s: content_remain = %llu\n", __func__,
+ (unsigned long long)wsi->u.http.content_remain);
if (!wsi->u.http.content_remain) {
lwsl_info("%s: selecting final write mode\n", __func__);
wp = LWS_WRITE_HTTP_FINAL;
#endif
poss = context->pt_serv_buf_size - n;
+
+ /*
+ * if there is a hint about how much we will do well to send at one time,
+ * restrict ourselves to only trying to send that.
+ */
+ if (wsi->protocol->tx_packet_size && poss > wsi->protocol->tx_packet_size)
+ poss = wsi->protocol->tx_packet_size;
+
#if defined(LWS_WITH_RANGES)
if (wsi->u.http.range.count_ranges) {
if (wsi->u.http.range.count_ranges > 1)
if (wsi->sending_chunked) {
args.p = (char *)p;
args.len = n;
- args.max_len = poss + 128;
+ args.max_len = (unsigned int)poss + 128;
args.final = wsi->u.http.filepos + n ==
wsi->u.http.filelen;
if (user_callback_handle_rxflow(
LWS_VISIBLE int
lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len)
{
+ struct lws_context *context = wsi->context;
+ struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
int n;
+ lws_stats_atomic_bump(context, pt, LWSSTATS_C_API_READ, 1);
+
n = recv(wsi->desc.sockfd, (char *)buf, len, 0);
if (n >= 0) {
if (wsi->vhost)
wsi->vhost->conn_stats.rx += n;
+ lws_stats_atomic_bump(context, pt, LWSSTATS_B_READ, n);
lws_restart_ws_ping_pong_timer(wsi);
return n;
}
lws_ssl_pending_no_ssl(struct lws *wsi)
{
(void)wsi;
- return 1;
+#if defined(LWS_WITH_ESP32)
+ return 100;
+#else
+ return 0;
+#endif
}