rage-iodine 2.1.1 → 2.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff8127ea56a3459eae3f01e41f5ec2b11b983d4c26733141ba008e91892b0ed8
4
- data.tar.gz: fec97c38ebb1abcdb13fb7fdd96381c93e1d0d9f6b38017eb13ab7a349df396b
3
+ metadata.gz: 0c7dd77022028a6bdd65a929622793240c5c6d844ed91b46741a7964ef8b734b
4
+ data.tar.gz: a03c8b323b45d88304cb628201bce9a90d8eb31263b0bc7ebf303beb09c2ce25
5
5
  SHA512:
6
- metadata.gz: 4cc5c93fc4180649b61ca5e9d5e8e1b2bf60630b4b9893e6c9aa68439d07c78e750d3f51446eb89fb3809864a0841b975e8c3add2422e581a44799297dcf7088
7
- data.tar.gz: 5434a1988b2f764cf285ac6d239c5c488d371b315944a5123fc397e9f0a98af9da8d4408c0adafb67b9ac2b1937ac175f13769a1ba36dac7477eada2270c4fdd
6
+ metadata.gz: e5d438ae9a488b9d814b43bb915adb2035bf64f094740d8ead2ef4a402f3e095ac894e50608bba819e7bb5abc26c8aff1cfe902022cebb8deb165976ff1095f3
7
+ data.tar.gz: fc9ae3246f6226feafca77dc6c0d52d73629c107daea5fffaa95bb89cfe4775b522d8222f90336e8dcc4e30a794a678a0dab316ebcb564c28d932107d485ede5
data/ext/iodine/fio.c CHANGED
@@ -2051,7 +2051,7 @@ static size_t fio_poll(void) {
2051
2051
  epoll_wait(internal[j].data.fd, events, FIO_POLL_MAX_EVENTS, 0);
2052
2052
  if (active_count > 0) {
2053
2053
  for (int i = 0; i < active_count; i++) {
2054
- if (events[i].events & (~(EPOLLIN | EPOLLOUT))) {
2054
+ if (events[i].events & (~(EPOLLIN | EPOLLOUT | EPOLLHUP | EPOLLRDHUP))) {
2055
2055
  // errors are hendled as disconnections (on_close)
2056
2056
  fio_force_close_in_poll(fd2uuid(events[i].data.fd));
2057
2057
  } else {
@@ -2060,9 +2060,14 @@ static size_t fio_poll(void) {
2060
2060
  fio_defer_push_urgent(deferred_on_ready,
2061
2061
  (void *)fd2uuid(events[i].data.fd), NULL);
2062
2062
  }
2063
- if (events[i].events & EPOLLIN)
2063
+ if (events[i].events & EPOLLIN) {
2064
2064
  fio_defer_push_task(deferred_on_data,
2065
2065
  (void *)fd2uuid(events[i].data.fd), NULL);
2066
+ }
2067
+ if (events[i].events & (EPOLLHUP | EPOLLRDHUP)) {
2068
+ fio_defer_push_task(fio_force_close_in_poll,
2069
+ (void *)fd2uuid(events[i].data.fd), NULL);
2070
+ }
2066
2071
  }
2067
2072
  } // end for loop
2068
2073
  total += active_count;
@@ -2197,7 +2202,8 @@ static size_t fio_poll(void) {
2197
2202
  NULL);
2198
2203
  }
2199
2204
  if (events[i].flags & (EV_EOF | EV_ERROR)) {
2200
- fio_force_close_in_poll(fd2uuid(events[i].udata));
2205
+ fio_defer_push_task(fio_force_close_in_poll,
2206
+ (void *)fd2uuid(events[i].udata), NULL);
2201
2207
  }
2202
2208
  }
2203
2209
  } else if (active_count < 0) {
data/ext/iodine/http.c CHANGED
@@ -2361,6 +2361,43 @@ size_t http_date2rfc7231(char *target, struct tm *tmbuf) {
2361
2361
  return pos - target;
2362
2362
  }
2363
2363
 
2364
+ size_t http_date2timestamp(char *target, struct tm *tmbuf) {
2365
+ char *pos = target;
2366
+ uint16_t tmp;
2367
+ pos += fio_ltoa(pos, tmbuf->tm_year + 1900, 10);
2368
+ *(pos++) = '-';
2369
+ tmp = (tmbuf->tm_mon + 1) / 10;
2370
+ pos[0] = '0' + tmp;
2371
+ pos[1] = '0' + ((tmbuf->tm_mon + 1) - (tmp * 10));
2372
+ pos += 2;
2373
+ *(pos++) = '-';
2374
+ tmp = (tmbuf->tm_mday) / 10;
2375
+ pos[0] = '0' + tmp;
2376
+ pos[1] = '0' + (tmbuf->tm_mday - (tmp * 10));
2377
+ pos += 2;
2378
+ *(pos++) = 'T';
2379
+ tmp = tmbuf->tm_hour / 10;
2380
+ pos[0] = '0' + tmp;
2381
+ pos[1] = '0' + (tmbuf->tm_hour - (tmp * 10));
2382
+ pos[2] = ':';
2383
+ tmp = tmbuf->tm_min / 10;
2384
+ pos[3] = '0' + tmp;
2385
+ pos[4] = '0' + (tmbuf->tm_min - (tmp * 10));
2386
+ pos[5] = ':';
2387
+ tmp = tmbuf->tm_sec / 10;
2388
+ pos[6] = '0' + tmp;
2389
+ pos[7] = '0' + (tmbuf->tm_sec - (tmp * 10));
2390
+ pos += 8;
2391
+ pos[0] = '+';
2392
+ pos[1] = '0';
2393
+ pos[2] = '0';
2394
+ pos[3] = ':';
2395
+ pos[4] = '0';
2396
+ pos[5] = '0';
2397
+ pos += 6;
2398
+ return pos - target;
2399
+ }
2400
+
2364
2401
  size_t http_date2str(char *target, struct tm *tmbuf);
2365
2402
 
2366
2403
  size_t http_date2rfc2822(char *target, struct tm *tmbuf) {
data/ext/iodine/http.h CHANGED
@@ -918,6 +918,8 @@ size_t http_date2rfc7231(char *target, struct tm *tmbuf);
918
918
  size_t http_date2rfc2109(char *target, struct tm *tmbuf);
919
919
  /** Writes an RFC 2822 date representation to target. */
920
920
  size_t http_date2rfc2822(char *target, struct tm *tmbuf);
921
+ /** Writes a timestamp to target. */
922
+ size_t http_date2timestamp(char *target, struct tm *tmbuf);
921
923
  /**
922
924
  Writes an HTTP date string to the `target` buffer.
923
925
 
@@ -456,6 +456,38 @@ static VALUE parse_multipart(VALUE self, VALUE rack_io, VALUE content_type) {
456
456
  (void)self;
457
457
  }
458
458
 
459
+ /**
460
+ Generate a timestamp to use in logs.
461
+ */
462
+ static VALUE gen_timestamp(VALUE self) {
463
+ struct tm tm;
464
+ time_t last_tick = fio_last_tick().tv_sec;
465
+ http_gmtime(last_tick, &tm);
466
+
467
+ char buffer[32];
468
+ size_t len = http_date2timestamp(buffer, &tm);
469
+
470
+ return rb_str_new(buffer, len);
471
+ }
472
+
473
+ static const char request_tag_seed[] = "abcdefghijklmnopqrstuvwxyz0123456789";
474
+ static const uint8_t request_tag_len = 16;
475
+
476
+ /**
477
+ Generate a request tag to use in logs.
478
+ */
479
+ static VALUE gen_request_tag(VALUE self) {
480
+ char buffer[request_tag_len];
481
+ uint8_t i, random_index;
482
+
483
+ for (i = 0; i < request_tag_len; i++) {
484
+ random_index = rand() % 36;
485
+ buffer[i] = request_tag_seed[random_index];
486
+ }
487
+
488
+ return rb_str_new(buffer, request_tag_len);
489
+ }
490
+
459
491
  /* *****************************************************************************
460
492
  Ruby Initialization
461
493
  ***************************************************************************** */
@@ -511,6 +543,8 @@ Results:
511
543
  rb_define_module_function(tmp, "parse_nested_query", parse_nested_query, 1);
512
544
  rb_define_module_function(tmp, "parse_urlencoded_nested_query", parse_urlencoded_nested_query, 1);
513
545
  rb_define_module_function(tmp, "parse_multipart", parse_multipart, 2);
546
+ rb_define_module_function(tmp, "gen_timestamp", gen_timestamp, 0);
547
+ rb_define_module_function(tmp, "gen_request_tag", gen_request_tag, 0);
514
548
 
515
549
  /*
516
550
  The monkey-patched methods are in this module, allowing Iodine::Rack::Utils to
@@ -529,4 +563,6 @@ include non-patched methods as well.
529
563
  rb_define_singleton_method(tmp, "rfc2109", iodine_rfc2109, 1);
530
564
  rb_define_singleton_method(tmp, "rfc2822", iodine_rfc2822, 1);
531
565
  // rb_define_module_function(IodineUtils, "time2str", date_str, -1);
566
+
567
+ srand(time(0));
532
568
  }
@@ -130,8 +130,9 @@ static VALUE iodine_scheduler_write(VALUE self, VALUE r_fd, VALUE r_buffer, VALU
130
130
  Check_Type(r_offset, T_FIXNUM);
131
131
  int offset = FIX2INT(r_offset);
132
132
 
133
- fio_write2(fio_fd2uuid(fd), .data.buffer = buffer, .length = length, .offset = offset,
134
- .after.dealloc = FIO_DEALLOC_NOOP);
133
+ void *cpy = fio_malloc(length);
134
+ memcpy(cpy, buffer, length);
135
+ fio_write2(fio_fd2uuid(fd), .data.buffer = cpy, .length = length, .offset = offset, .after.dealloc = fio_free);
135
136
 
136
137
  return r_length;
137
138
 
@@ -1,3 +1,3 @@
1
1
  module Iodine
2
- VERSION = '2.1.1'.freeze
2
+ VERSION = '2.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rage-iodine
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-09 00:00:00.000000000 Z
11
+ date: 2023-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake