@scriptc/runtime 0.0.24 → 0.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/scr_net.c +12 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scriptc/runtime",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "scriptc native runtime — C sources, compiled into every scriptc binary",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://scriptc.dev",
package/src/scr_net.c CHANGED
@@ -987,15 +987,21 @@ static bool scr_net_sock_deliver(ScrNetSocket *s, const char *buf, size_t n) {
987
987
  return true;
988
988
  }
989
989
 
990
- /* One readable wake: read until EAGAIN/EOF, one 'data' emit per read(2)
991
- * chunk (Node's chunking is arrival-driven too — only the reassembled
992
- * bytes are contractual, the stdin stance). Peeked/unshifted bytes in
993
- * the receive buffer deliver first they precede the kernel's in the
994
- * stream. A TLS socket drains those through the engine's bio instead. */
990
+ /* One readable wake: read until EAGAIN/EOF OR a bounded batch, one 'data'
991
+ * emit per read(2) chunk (Node's chunking is arrival-driven too — only the
992
+ * reassembled bytes are contractual, the stdin stance). The batch bound is
993
+ * the loop's fairness fence: a continuously writing peer can otherwise keep
994
+ * every nonblocking read successful forever and strand timers plus every
995
+ * other fd inside this function. All poller arms are level-triggered, so
996
+ * unread kernel bytes make the socket ready again on the next loop turn.
997
+ * Peeked/unshifted bytes in the receive buffer deliver first — they precede
998
+ * the kernel's in the stream. A TLS socket drains those through the engine's
999
+ * bio instead. */
995
1000
  static void scr_net_sock_append_rbuf(ScrNetSocket *s, const char *data, size_t len);
996
1001
  static void scr_net_sock_transport_pump(ScrNetSocket *s);
997
1002
 
998
1003
  static void scr_net_sock_read(ScrNetSocket *s) {
1004
+ size_t reads_left = 32; /* at most 2 MiB with the 64 KiB read buffer */
999
1005
  if (s->tops && !s->t_est) return; /* readiness feeds the handshake pump instead */
1000
1006
  for (;;) {
1001
1007
  if (s->fd < 0 || s->user_paused) return;
@@ -1061,6 +1067,7 @@ static void scr_net_sock_read(ScrNetSocket *s) {
1061
1067
  }
1062
1068
  }
1063
1069
  scr_net_sock_update_read(s); /* a once-listener may have been the last consumer */
1070
+ if (--reads_left == 0) return;
1064
1071
  }
1065
1072
  }
1066
1073