@velox0/cerver 0.6.1 → 0.6.2

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.
@@ -18,7 +18,6 @@ function run(opts) {
18
18
  }
19
19
  process.chdir(projectDir);
20
20
 
21
- // Prefer .exe on Windows, fall back to plain "server" for compat
22
21
  const binaryName = IS_WINDOWS ? "server.exe" : "server";
23
22
  const binaryPath = path.join(projectDir, "dist", binaryName);
24
23
  const legacyPath = path.join(projectDir, "dist", "server");
@@ -49,7 +48,7 @@ function run(opts) {
49
48
  stdio: "inherit",
50
49
  env,
51
50
  cwd: projectDir,
52
- shell: IS_WINDOWS, // On Windows, .exe may need shell resolution
51
+ shell: IS_WINDOWS,
53
52
  });
54
53
  } catch (err) {
55
54
  if (err.status !== null) {
@@ -12,8 +12,6 @@ const IS_WINDOWS = process.platform === "win32";
12
12
  /* ------------------------------------------------------------------ */
13
13
 
14
14
  function detectCompiler() {
15
- // On Windows, prefer clang (bundled with VS/LLVM) then gcc (MinGW/MSYS2)
16
- // On Unix, keep original preference order
17
15
  const candidates = IS_WINDOWS
18
16
  ? ["clang", "gcc", "cc", "x86_64-w64-mingw32-gcc"]
19
17
  : ["cc", "gcc", "clang"];
@@ -21,7 +19,6 @@ function detectCompiler() {
21
19
  for (const cc of candidates) {
22
20
  try {
23
21
  if (IS_WINDOWS) {
24
- // `which` doesn't exist on Windows; use `where`
25
22
  execFileSync("where", [cc], { stdio: "ignore", shell: false });
26
23
  } else {
27
24
  execFileSync("which", [cc], { stdio: "ignore" });
@@ -55,7 +52,7 @@ function supportsFlag(cc, flag) {
55
52
  {
56
53
  input: "int main(){}\n",
57
54
  stdio: ["pipe", "ignore", "ignore"],
58
- shell: IS_WINDOWS, // MinGW on Windows sometimes needs shell
55
+ shell: IS_WINDOWS,
59
56
  }
60
57
  );
61
58
  return true;
@@ -174,7 +171,7 @@ function compile(distDir, runtimeDir, opts) {
174
171
  }
175
172
 
176
173
  /* Windows-specific defines */
177
- args.push("-D_WIN32_WINNT=0x0601"); // Windows 7+
174
+ args.push("-D_WIN32_WINNT=0x0601");
178
175
  args.push("-DWIN32_LEAN_AND_MEAN");
179
176
 
180
177
  /* Produce a console binary (not a GUI window) */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velox0/cerver",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Compile restricted JavaScript server logic into optimized native C binaries (cross-platform: Linux, macOS, Windows)",
5
5
  "main": "bin/cerver.js",
6
6
  "bin": {
package/runtime/cerver.h CHANGED
@@ -304,4 +304,4 @@ int cerver_stat_cache_lookup(cerver_stat_cache_t* cache, const char* path, size
304
304
  void cerver_stat_cache_store(cerver_stat_cache_t* cache, const char* path, size_t file_size,
305
305
  time_t mtime);
306
306
 
307
- #endif /* CERVER_H */
307
+ #endif // CERVER_H
@@ -16,7 +16,7 @@
16
16
  #if !CERVER_PLATFORM_WINDOWS
17
17
  #include <unistd.h>
18
18
  #include <sys/uio.h>
19
- #endif
19
+ #endif // !CERVER_PLATFORM_WINDOWS
20
20
 
21
21
  /* ------------------------------------------------------------------ */
22
22
  /* sendfile — read-write fallback everywhere */
@@ -64,7 +64,7 @@ static ssize_t do_sendfile(cerver_sock_t out_fd, int in_fd, off_t offset, size_t
64
64
  if (lseek(in_fd, offset, SEEK_SET) == -1) return -1;
65
65
  size_t to_read = count > sizeof(buf) ? sizeof(buf) : count;
66
66
  ssize_t n_read = read(in_fd, buf, to_read);
67
- #endif
67
+ #endif // CERVER_PLATFORM_WINDOWS
68
68
  if (n_read <= 0) return (ssize_t)n_read;
69
69
  size_t written = 0;
70
70
  while (written < (size_t)n_read) {
@@ -74,7 +74,8 @@ static ssize_t do_sendfile(cerver_sock_t out_fd, int in_fd, off_t offset, size_t
74
74
  }
75
75
  return (ssize_t)written;
76
76
  }
77
- #endif
77
+ #endif // __linux__ && !CERVER_PLATFORM_WINDOWS
78
+ // !CERVER_PLATFORM_WINDOWS, else
78
79
 
79
80
  /* ------------------------------------------------------------------ */
80
81
  /* Portable full-write helper (send all bytes) */
@@ -87,7 +88,7 @@ static int send_all(cerver_sock_t fd, const char* buf, size_t len) {
87
88
  if (n < 0) {
88
89
  #if !CERVER_PLATFORM_WINDOWS
89
90
  if (errno == EINTR) continue;
90
- #endif
91
+ #endif // !CERVER_PLATFORM_WINDOWS
91
92
  return -1;
92
93
  }
93
94
  sent += (size_t)n;
@@ -167,7 +168,7 @@ int cerver_write_response(int fd, const cerver_response_t* res, int keepalive) {
167
168
  if (n < 0) {
168
169
  #if !CERVER_PLATFORM_WINDOWS
169
170
  if (errno == EINTR) continue;
170
- #endif
171
+ #endif // !CERVER_PLATFORM_WINDOWS
171
172
  return -1;
172
173
  }
173
174
  if (n == 0) break;
package/runtime/server.c CHANGED
@@ -34,7 +34,7 @@
34
34
  #include <netinet/in.h>
35
35
  #include <netinet/tcp.h>
36
36
  #include <arpa/inet.h>
37
- #endif
37
+ #endif // !CERVER_PLATFORM_WINDOWS
38
38
 
39
39
  #if defined(__APPLE__) || defined(__FreeBSD__)
40
40
  #define CERVER_USE_KQUEUE 1
@@ -49,11 +49,12 @@
49
49
  #else
50
50
  #define CERVER_USE_SELECT 1
51
51
  #include <sys/select.h>
52
- #endif
52
+ #endif // __APPLE__ || __FreeBSD__
53
+ // CERVER_PLATFORM_WINDOWS, else
53
54
 
54
55
  #ifdef __linux__
55
56
  #include <sched.h>
56
- #endif
57
+ #endif // __linux__
57
58
 
58
59
  /* Connection pool sizing */
59
60
  #define CERVER_CONN_POOL_SIZE 128
@@ -74,7 +75,7 @@ static void* cerver_memmem(const void* hay, size_t haylen, const void* needle, s
74
75
  return NULL;
75
76
  }
76
77
  #define memmem cerver_memmem
77
- #endif
78
+ #endif // !CERVER_PLATFORM_WINDOWS && !__APPLE__ && !_GNU_SOURCE
78
79
 
79
80
  /* Global for signal handler */
80
81
  static cerver_server_t* g_srv = NULL;
@@ -95,7 +96,7 @@ static int set_nonblocking(cerver_sock_t fd) {
95
96
  int flags = fcntl(fd, F_GETFL, 0);
96
97
  if (flags < 0) return -1;
97
98
  return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
98
- #endif
99
+ #endif // CERVER_PLATFORM_WINDOWS
99
100
  }
100
101
 
101
102
  static int get_cpu_count(void) {
@@ -103,7 +104,7 @@ static int get_cpu_count(void) {
103
104
  long n = cerver_nproc_win();
104
105
  #else
105
106
  long n = sysconf(_SC_NPROCESSORS_ONLN);
106
- #endif
107
+ #endif // CERVER_PLATFORM_WINDOWS
107
108
  if (n < 1) n = 1;
108
109
  if (n > 64) n = 64;
109
110
  return (int)n;
@@ -209,11 +210,6 @@ static char* read_full_request(cerver_sock_t fd, size_t* out_len) {
209
210
  char* buf = malloc(cap + 1);
210
211
  if (!buf) return NULL;
211
212
 
212
- #if CERVER_PLATFORM_WINDOWS
213
- /* On Windows set a blocking recv timeout via SO_RCVTIMEO (already set
214
- per-connection in handle_connection). Just read normally. */
215
- #endif
216
-
217
213
  while (len < (size_t)CERVER_READ_BUF_MAX) {
218
214
  ssize_t n = (ssize_t)cerver_sock_read(fd, buf + len, cap - len);
219
215
  if (n <= 0) break;
@@ -252,7 +248,7 @@ static void handle_connection(cerver_server_t* srv, cerver_sock_t client_fd) {
252
248
  int flags = fcntl(client_fd, F_GETFL, 0);
253
249
  if (flags >= 0 && (flags & O_NONBLOCK)) fcntl(client_fd, F_SETFL, flags & ~O_NONBLOCK);
254
250
  }
255
- #endif
251
+ #endif // !CERVER_PLATFORM_WINDOWS
256
252
 
257
253
  /* TCP_NODELAY */
258
254
  {
@@ -272,7 +268,7 @@ static void handle_connection(cerver_server_t* srv, cerver_sock_t client_fd) {
272
268
  #else
273
269
  struct timeval tv = {timeout_sec, 0};
274
270
  setsockopt(client_fd, SOL_SOCKET, SO_RCVTIMEO, CERVER_SETSOCKOPT_CAST & tv, sizeof(tv));
275
- #endif
271
+ #endif // CERVER_PLATFORM_WINDOWS
276
272
 
277
273
  size_t req_len = 0;
278
274
  char* buf = read_full_request(client_fd, &req_len);
@@ -300,7 +296,7 @@ static void handle_connection(cerver_server_t* srv, cerver_sock_t client_fd) {
300
296
  memset(&res, 0, sizeof(res));
301
297
  #if !CERVER_PLATFORM_WINDOWS
302
298
  res._file_fd = -1;
303
- #endif
299
+ #endif // !CERVER_PLATFORM_WINDOWS
304
300
 
305
301
  if (cerver_serve_static(srv, &req, &res) < 0) {
306
302
  cerver_handler_fn handler = cerver_dispatch(srv, &req);
@@ -321,7 +317,7 @@ static void handle_connection(cerver_server_t* srv, cerver_sock_t client_fd) {
321
317
  munmap((void*)res.body, res.body_len);
322
318
  else if (res._body_owned == 3 && res._file_fd >= 0)
323
319
  close(res._file_fd);
324
- #endif
320
+ #endif // !CERVER_PLATFORM_WINDOWS
325
321
 
326
322
  free(buf);
327
323
  if (write_err < 0) break;
@@ -391,7 +387,7 @@ static cerver_sock_t create_listener(int port, int reuseport) {
391
387
  perror("cerver: socket");
392
388
  return CERVER_INVALID_SOCK;
393
389
  }
394
- #endif
390
+ #endif // CERVER_PLATFORM_WINDOWS
395
391
 
396
392
  int opt = 1;
397
393
  setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, CERVER_SETSOCKOPT_CAST & opt, sizeof(opt));
@@ -400,7 +396,7 @@ static cerver_sock_t create_listener(int port, int reuseport) {
400
396
  if (reuseport) setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt));
401
397
  #else
402
398
  (void)reuseport;
403
- #endif
399
+ #endif // __linux__ || __APPLE__ || __FreeBSD__
404
400
 
405
401
  struct sockaddr_in addr;
406
402
  memset(&addr, 0, sizeof(addr));
@@ -434,7 +430,7 @@ static cerver_sock_t accept_connection(cerver_sock_t listen_fd) {
434
430
  return accept4(listen_fd, (struct sockaddr*)&ca, &cl, SOCK_CLOEXEC);
435
431
  #else
436
432
  return accept(listen_fd, (struct sockaddr*)&ca, &cl);
437
- #endif
433
+ #endif // __linux__
438
434
  }
439
435
 
440
436
  /* ------------------------------------------------------------------ */
@@ -553,7 +549,7 @@ static void* acceptor_loop(void* arg) {
553
549
  return NULL;
554
550
  }
555
551
 
556
- #else /* SELECT — used on Windows and other POSIX platforms */
552
+ #else
557
553
 
558
554
  static void* acceptor_loop(void* arg) {
559
555
  cerver_worker_t* w = (cerver_worker_t*)arg;
@@ -578,13 +574,13 @@ static void* acceptor_loop(void* arg) {
578
574
  #else
579
575
  struct timeval tv = {1, 0};
580
576
  int ret = select((int)w->listen_fd + 1, &rfds, NULL, NULL, &tv);
581
- #endif
577
+ #endif // CERVER_PLATFORM_WINDOWS
582
578
  if (ret < 0) {
583
579
  #if CERVER_PLATFORM_WINDOWS
584
580
  if (WSAGetLastError() == WSAEINTR) continue;
585
581
  #else
586
582
  if (errno == EINTR) continue;
587
- #endif
583
+ #endif // CERVER_PLATFORM_WINDOWS
588
584
  break;
589
585
  }
590
586
  if (ret > 0 && FD_ISSET(w->listen_fd, &rfds)) {
@@ -595,7 +591,7 @@ static void* acceptor_loop(void* arg) {
595
591
  if (cerver_would_block_win()) break;
596
592
  #else
597
593
  if (errno == EAGAIN || errno == EWOULDBLOCK) break;
598
- #endif
594
+ #endif // CERVER_PLATFORM_WINDOWS
599
595
  break;
600
596
  }
601
597
  if (cq_push(&g_conn_queue, cfd) < 0) {
@@ -606,7 +602,7 @@ static void* acceptor_loop(void* arg) {
606
602
  }
607
603
  return NULL;
608
604
  }
609
- #endif /* acceptor backends */
605
+ #endif // CERVER_USE_KQUEUE
610
606
 
611
607
  /* ------------------------------------------------------------------ */
612
608
  /* Stat cache */
@@ -676,7 +672,7 @@ int cerver_init(cerver_server_t* srv, int port, int threads) {
676
672
  cerver_stat_cache_init(&srv->stat_cache);
677
673
  #if CERVER_PLATFORM_WINDOWS
678
674
  cerver_wsa_startup();
679
- #endif
675
+ #endif // CERVER_PLATFORM_WINDOWS
680
676
  return 0;
681
677
  }
682
678
 
@@ -709,7 +705,7 @@ int cerver_listen(cerver_server_t* srv) {
709
705
  signal(SIGTERM, signal_handler);
710
706
  #if !CERVER_PLATFORM_WINDOWS
711
707
  signal(SIGPIPE, SIG_IGN);
712
- #endif
708
+ #endif // !CERVER_PLATFORM_WINDOWS
713
709
 
714
710
  srv->running = 1;
715
711
  srv->acceptor_count = 0;
@@ -723,7 +719,7 @@ int cerver_listen(cerver_server_t* srv) {
723
719
  /* Windows select-based acceptor: limit to 1 until IOCP is wired */
724
720
  #if CERVER_PLATFORM_WINDOWS
725
721
  acceptor_count = 1;
726
- #endif
722
+ #endif // CERVER_PLATFORM_WINDOWS
727
723
 
728
724
  int pool_size = configured_worker_count * 16;
729
725
  if (pool_size < CERVER_CONN_POOL_SIZE) pool_size = CERVER_CONN_POOL_SIZE;
@@ -802,7 +798,7 @@ int cerver_listen(cerver_server_t* srv) {
802
798
  if (w->listen_fd == CERVER_INVALID_SOCK) w->listen_fd = srv->sock_fd;
803
799
  #else
804
800
  w->listen_fd = srv->sock_fd;
805
- #endif
801
+ #endif // __linux__ || __APPLE__ || __FreeBSD__
806
802
  if (pthread_create(&w->thread, &attr, acceptor_loop, w) != 0) {
807
803
  perror("cerver: acceptor create");
808
804
  srv->running = 0;
@@ -875,13 +871,13 @@ void cerver_shutdown(cerver_server_t* srv) {
875
871
  if (srv->workers[i].listen_fd != srv->sock_fd &&
876
872
  srv->workers[i].listen_fd != CERVER_INVALID_SOCK)
877
873
  cerver_platform_close(srv->workers[i].listen_fd);
878
- #endif
874
+ #endif // __linux__ || __APPLE__ || __FreeBSD__
879
875
  if (srv->workers[i].event_fd >= 0)
880
876
  #if !CERVER_PLATFORM_WINDOWS
881
877
  close(srv->workers[i].event_fd);
882
878
  #else
883
879
  closesocket((SOCKET)srv->workers[i].event_fd);
884
- #endif
880
+ #endif // !CERVER_PLATFORM_WINDOWS
885
881
  }
886
882
  free(srv->workers);
887
883
  srv->workers = NULL;
@@ -902,7 +898,7 @@ void cerver_shutdown(cerver_server_t* srv) {
902
898
 
903
899
  #if CERVER_PLATFORM_WINDOWS
904
900
  cerver_wsa_cleanup();
905
- #endif
901
+ #endif // CERVER_PLATFORM_WINDOWS
906
902
 
907
903
  printf("\ncerver: server stopped\n");
908
904
  }
package/runtime/static.c CHANGED
@@ -19,11 +19,11 @@
19
19
  #include <unistd.h>
20
20
  #include <fcntl.h>
21
21
  #include <sys/mman.h>
22
- #endif
22
+ #endif // !CERVER_PLATFORM_WINDOWS
23
23
 
24
24
  #ifdef __linux__
25
25
  #include <sys/sendfile.h>
26
- #endif
26
+ #endif // __linux__
27
27
 
28
28
  /* ------------------------------------------------------------------ */
29
29
  /* FNV-1a hash for fast asset lookup */
@@ -257,7 +257,7 @@ static int serve_filesystem(cerver_server_t* srv, cerver_request_t* req, cerver_
257
257
  int fd = _open(full_path, _O_RDONLY | _O_BINARY);
258
258
  #else
259
259
  int fd = open(full_path, O_RDONLY);
260
- #endif
260
+ #endif // CERVER_PLATFORM_WINDOWS
261
261
  if (fd < 0) return -1;
262
262
 
263
263
  res->status = 200;
@@ -61,4 +61,4 @@ const char* mu_snip(const char* s, char* buf, size_t cap);
61
61
  } \
62
62
  } while (0)
63
63
 
64
- #endif
64
+ #endif // CERVER_MINUNIT_H
@@ -14,10 +14,10 @@
14
14
  /* ---- winsock / windows ------------------------------------------ */
15
15
  #ifndef WIN32_LEAN_AND_MEAN
16
16
  #define WIN32_LEAN_AND_MEAN
17
- #endif
17
+ #endif // WIN32_LEAN_AND_MEAN
18
18
  #ifndef _WIN32_WINNT
19
19
  #define _WIN32_WINNT 0x0601 /* Windows 7+ */
20
- #endif
20
+ #endif // _WIN32_WINNT
21
21
  #include <winsock2.h>
22
22
  #include <ws2tcpip.h>
23
23
  #include <windows.h>
@@ -30,7 +30,7 @@
30
30
  can stay unchanged. Only the primitives actually used by cerver are
31
31
  mapped; this is NOT a general replacement. */
32
32
 
33
- #include <pthread.h> /* pthreads4w / pthreads-win32, installed via mingw */
33
+ #include <pthread.h>
34
34
 
35
35
  /* ---- POSIX socket aliases --------------------------------------- */
36
36
  typedef SOCKET cerver_sock_t;
@@ -41,7 +41,7 @@ typedef SOCKET cerver_sock_t;
41
41
  #if !defined(ssize_t) && !defined(_SSIZE_T_DEFINED)
42
42
  typedef intptr_t ssize_t;
43
43
  #define _SSIZE_T_DEFINED
44
- #endif
44
+ #endif // !ssize_t && !_SSIZE_T_DEFINED
45
45
 
46
46
  /* read/write on a socket must go through recv/send on Windows */
47
47
  static inline ssize_t cerver_sock_read(int fd, void* buf, size_t n) {
@@ -75,7 +75,7 @@ static inline void* cerver_memmem_win(const void* hay, size_t hlen, const void*
75
75
  }
76
76
  #ifndef memmem
77
77
  #define memmem cerver_memmem_win
78
- #endif
78
+ #endif // memmem
79
79
 
80
80
  /* clock_gettime is missing before MSVC 2019 / older MinGW */
81
81
  #if defined(_MSC_VER) && _MSC_VER < 1900
@@ -96,8 +96,8 @@ static inline int clock_gettime(int, struct timespec* ts) {
96
96
  ts->tv_nsec = (long)((t % 10000000ULL) * 100);
97
97
  return 0;
98
98
  }
99
- #endif
100
- #endif
99
+ #endif // CLOCK_REALTIME
100
+ #endif // _MSC_VER && _MSC_VER < 1900
101
101
 
102
102
  /* Windows socket error → errno translation for the few codes we check */
103
103
  static inline int cerver_would_block_win(void) {
@@ -116,12 +116,12 @@ static inline long cerver_nproc_win(void) {
116
116
  /* sleep(n) → Sleep(n*1000) */
117
117
  #ifndef sleep
118
118
  #define sleep(n) Sleep((DWORD)((n) * 1000))
119
- #endif
119
+ #endif // sleep
120
120
 
121
121
  /* Signal shim — Windows has signal() but not SIGPIPE */
122
122
  #ifndef SIGPIPE
123
123
  #define SIGPIPE 13
124
- #endif
124
+ #endif // SIGPIPE
125
125
  /* SIG_IGN is defined in <signal.h> on Windows */
126
126
 
127
127
  /* Winsock init/teardown helpers ----------------------------------- */
@@ -136,9 +136,9 @@ static inline void cerver_wsa_cleanup(void) { WSACleanup(); }
136
136
 
137
137
  #else /* !Windows */
138
138
 
139
- #include <stddef.h> /* size_t */
140
- #include <sys/types.h> /* ssize_t */
141
- #include <unistd.h> /* read, write, close */
139
+ #include <stddef.h>
140
+ #include <sys/types.h>
141
+ #include <unistd.h>
142
142
 
143
143
  #define CERVER_PLATFORM_WINDOWS 0
144
144
  typedef int cerver_sock_t;
@@ -153,5 +153,5 @@ static inline ssize_t cerver_sock_write(int fd, const void* buf, size_t n) {
153
153
  static inline int cerver_wsa_startup(void) { return 0; }
154
154
  static inline void cerver_wsa_cleanup(void) {}
155
155
 
156
- #endif /* _WIN32 */
157
- #endif /* CERVER_WIN_COMPAT_H */
156
+ #endif // _WIN32 || _WIN64
157
+ #endif // CERVER_WIN_COMPAT_H