iodine 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of iodine might be problematic. Click here for more details.

@@ -412,9 +412,8 @@ static VALUE iodine_pubsub_redis_new(int argc, VALUE *argv, VALUE self) {
412
412
  /* parse URL assume redis://redis:password@localhost:6379 */
413
413
  http_url_s info = http_url_parse(RSTRING_PTR(url), RSTRING_LEN(url));
414
414
 
415
- fprintf(
416
- stderr,
417
- "INFO: Initializing Redis engine for address: %s - port: %s - auth %s\n",
415
+ FIO_LOG_INFO(
416
+ "Initializing Redis engine for address: %s - port: %s - auth %s\n",
418
417
  info.host.data ? info.host.data : "-",
419
418
  info.port.data ? info.port.data : "-",
420
419
  info.password.data ? info.password.data : "-");
@@ -22,23 +22,26 @@ API
22
22
 
23
23
  /** Adds an object to the storage (or increases it's reference count). */
24
24
  static VALUE storage_add(VALUE obj) {
25
- if (obj == Qnil || obj == Qtrue || obj == Qfalse)
25
+ if (!obj || obj == Qnil || obj == Qtrue || obj == Qfalse)
26
26
  return obj;
27
27
  fio_lock(&lock);
28
- uintptr_t *val = fio_hash_insert(&storage, obj, 0);
29
- ++val[0];
28
+ uintptr_t old = 0;
29
+ fio_hash_overwrite(&storage, obj, 1, &old);
30
+ if (old)
31
+ fio_hash_overwrite(&storage, obj, old + 1, NULL);
30
32
  fio_unlock(&lock);
31
33
  return obj;
32
34
  }
33
35
  /** Removes an object from the storage (or decreases it's reference count). */
34
36
  static VALUE storage_remove(VALUE obj) {
35
- if (obj == Qnil || obj == Qtrue || obj == Qfalse || storage.map == NULL ||
37
+ if (!obj || obj == Qnil || obj == Qtrue || obj == Qfalse ||
36
38
  storage.count == 0)
37
39
  return obj;
38
40
  fio_lock(&lock);
39
- uintptr_t *val = fio_hash_find(&storage, obj, 0);
40
- if (val && *val <= 1)
41
- fio_hash_remove(&storage, obj, 0);
41
+ uintptr_t old = 0;
42
+ fio_hash_remove(&storage, obj, 0, &old);
43
+ if (old > 1)
44
+ fio_hash_overwrite(&storage, obj, old - 1, NULL);
42
45
  fio_unlock(&lock);
43
46
  return obj;
44
47
  }
@@ -47,7 +50,7 @@ static void storage_after_fork(void) { lock = FIO_LOCK_INIT; }
47
50
 
48
51
  /** Prints debugging information to the console. */
49
52
  static void storage_print(void) {
50
- fprintf(stderr, "Ruby <=> C Memory storage stats (pid: %d):\n", getpid());
53
+ FIO_LOG_DEBUG("Ruby <=> C Memory storage stats (pid: %d):\n", getpid());
51
54
  fio_lock(&lock);
52
55
  uintptr_t index = 0;
53
56
  FIO_SET_FOR_LOOP(&storage, pos) {
@@ -58,7 +61,7 @@ static void storage_print(void) {
58
61
  }
59
62
  fprintf(stderr, "Total of %" PRIuPTR " objects protected form GC\n", index);
60
63
  fprintf(stderr,
61
- "Storage uses %" PRIuPTR " Hash bins for %" PRIuPTR " objects\n",
64
+ "Storage uses %" PRIuPTR " Hash bins for %" PRIuPTR " objects",
62
65
  storage.capa, storage.count);
63
66
  fio_unlock(&lock);
64
67
  }
@@ -78,9 +81,8 @@ GC protection
78
81
  /* a callback for the GC (marking active objects) */
79
82
  static void storage_mark(void *ignore) {
80
83
  (void)ignore;
81
- #if IODINE_DEBUG
82
- storage_print();
83
- #endif
84
+ if (FIO_LOG_LEVEL >= FIO_LOG_LEVEL_DEBUG)
85
+ storage_print();
84
86
  fio_lock(&lock);
85
87
  // fio_hash_compact(&storage);
86
88
  FIO_SET_FOR_LOOP(&storage, pos) {
@@ -94,9 +96,7 @@ static void storage_mark(void *ignore) {
94
96
  /* clear the registry (end of lifetime) */
95
97
  static void storage_clear(void *ignore) {
96
98
  (void)ignore;
97
- #if IODINE_DEBUG == 1
98
- fprintf(stderr, "* INFO: Ruby<=>C Storage cleared.\n");
99
- #endif
99
+ FIO_LOG_DEBUG("Ruby<=>C Storage cleared.\n");
100
100
  fio_lock(&lock);
101
101
  fio_hash_free(&storage);
102
102
  storage = (fio_hash_s)FIO_SET_INIT;
@@ -39,7 +39,7 @@ typedef struct {
39
39
  static void *iodine_tcp_on_data_in_GIL(void *b_) {
40
40
  iodine_buffer_s *b = b_;
41
41
  if (!b) {
42
- fprintf(stderr, "FATAL ERROR: (iodine->tcp/ip->on_data->GIL) WTF?!\n");
42
+ FIO_LOG_FATAL("(iodine->tcp/ip->on_data->GIL) WTF?!\n");
43
43
  }
44
44
  VALUE data = IodineStore.add(rb_str_new(b->buffer, b->len));
45
45
  rb_enc_associate(data, IodineBinaryEncoding);
@@ -360,8 +360,7 @@ static void resp_on_sub_message(struct redis_engine_internal_s *i, FIOBJ msg) {
360
360
  fiobj_obj2cstr(msg).data[0] != 'P') {
361
361
  FIO_LOG_WARNING("(redis) unexpected data format in "
362
362
  "subscription stream:");
363
- fio_str_info_s tmp = fiobj_obj2cstr(msg);
364
- FIO_LOG_STATE(" %s\n", tmp.data);
363
+ FIO_LOG_STATE(" %s\n", fiobj_obj2cstr(msg).data);
365
364
  }
366
365
  } else {
367
366
  // FIOBJ *ary = fiobj_ary2ptr(msg);
@@ -327,10 +327,7 @@ static void destroy_ws(ws_s *ws) {
327
327
  void websocket_attach(intptr_t uuid, http_settings_s *http_settings,
328
328
  websocket_settings_s *args, void *data, size_t length) {
329
329
  ws_s *ws = new_websocket(uuid);
330
- if (!ws) {
331
- FIO_LOG_FATAL("couldn't allocate Websocket protocol object");
332
- exit(errno);
333
- }
330
+ FIO_ASSERT_ALLOC(ws);
334
331
  // we have an active websocket connection - prep the connection buffer
335
332
  ws->buffer = create_ws_buffer(ws);
336
333
  // Setup ws callbacks
@@ -531,11 +528,11 @@ typedef struct {
531
528
 
532
529
  static void websocket_on_unsubscribe(void *u1, void *u2) {
533
530
  websocket_sub_data_s *d = u2;
534
- (void)u1;
535
531
  if (d->on_unsubscribe) {
536
532
  d->on_unsubscribe(d->udata);
537
533
  }
538
534
  free(d);
535
+ (void)u1;
539
536
  }
540
537
 
541
538
  static inline void websocket_on_pubsub_message_direct_internal(fio_msg_s *msg,
@@ -615,7 +612,7 @@ static void websocket_on_pubsub_message(fio_msg_s *msg) {
615
612
  */
616
613
  #undef websocket_subscribe
617
614
  uintptr_t websocket_subscribe(struct websocket_subscribe_s args) {
618
- if (!args.ws)
615
+ if (!args.ws || !fio_is_valid(args.ws->fd))
619
616
  goto error;
620
617
  websocket_sub_data_s *d = malloc(sizeof(*d));
621
618
  FIO_ASSERT_ALLOC(d);
@@ -637,14 +634,15 @@ uintptr_t websocket_subscribe(struct websocket_subscribe_s args) {
637
634
  : websocket_on_pubsub_message_direct),
638
635
  .udata1 = (void *)args.ws->fd, .udata2 = d);
639
636
  if (!sub) {
640
- /* don't free `d`, return (`d` freed by callback) */
637
+ /* don't free `d`, return (`d` freed by fio_subscribe) */
641
638
  return 0;
642
639
  }
640
+ fio_ls_s *pos;
643
641
  fio_lock(&args.ws->sub_lock);
644
- fio_ls_push(&args.ws->subscriptions, sub);
642
+ pos = fio_ls_push(&args.ws->subscriptions, sub);
645
643
  fio_unlock(&args.ws->sub_lock);
646
644
 
647
- return (uintptr_t)args.ws->subscriptions.prev;
645
+ return (uintptr_t)pos;
648
646
  error:
649
647
  if (args.on_unsubscribe)
650
648
  args.on_unsubscribe(args.udata);
@@ -106,6 +106,10 @@ if ARGV.index('-tout') && ARGV[ARGV.index('-tout') + 1]
106
106
  end
107
107
  Iodine::DEFAULT_HTTP_ARGS[:log] = true if ARGV.index('-v')
108
108
 
109
+ if ARGV.index('-logging') && ARGV[ARGV.index('-logging') + 1] && ARGV[ARGV.index('-logging') + 1].to_s[0] >= '0' && ARGV[ARGV.index('-logging') + 1].to_s[0] <= '9'
110
+ Iodine.verbosity = ARGV[ARGV.index('-logging') + 1].to_i
111
+ end
112
+
109
113
  if ARGV.index('-t') && ARGV[ARGV.index('-t') + 1].to_i != 0
110
114
  Iodine.threads = ARGV[ARGV.index('-t') + 1].to_i
111
115
  end
@@ -1,3 +1,3 @@
1
1
  module Iodine
2
- VERSION = '0.7.2'.freeze
2
+ VERSION = '0.7.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iodine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-03 00:00:00.000000000 Z
11
+ date: 2018-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack