agoo 2.8.1 → 2.8.2

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

Potentially problematic release.


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

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af291829d85f65bcbc9f124b1f63e470f78d2650c84bc78cba437b46cd994eac
4
- data.tar.gz: 9b894a8bc473f26667617da0c47704a853afb97b6a04c3e5f4dd4c427879fbc2
3
+ metadata.gz: 47c645a0bab39e564510cdf0971a61f2ea710f3d4015eed73b18e32f464b9ee9
4
+ data.tar.gz: 5bc646705ef75cf6a1eb2105a1c59cd8bf81dc5940c4ef358542e989caa13fb4
5
5
  SHA512:
6
- metadata.gz: e4eae332a464287827a3c4fd8a6f833cbf2a451e24df78c7f8e7424f428abcc8cce6983bb08e7ec73c1dcb6a1b4193213297ea163c2d769e65223043b1da31ba
7
- data.tar.gz: cc930402da457aeecc9c6279278ea8ac89fd607d6b11add8512dec5c293d8738041d27f2f1c30ce1a98e2544bd6017c20f64b615c1f93f2b26e5fe7cf5a195bc
6
+ metadata.gz: 75a2d84ce4ec662f7abcaa8875b3f35d94969114e6a9a6b14cc3dc60d4e751889bbb2d8abbd89493d148a5f8786917122d53b7301b7b58d89f16110f77abfcbb
7
+ data.tar.gz: 6eb587543a0b4ffed788c2d43e72fa26302d5844a4cb4b5a2444d982144e8da63239e815ae5f75d2fed5786f3f00b3bf416a1638ad5ef78054eb468059645053
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ### 2.8.2 - 2019-03-08
4
+
5
+ Rack compatibility improvement.
6
+
7
+ - Add miss `close` method to `Agoo::ErrorStream`.
8
+
9
+ - Rack builder wrapper added.
10
+
3
11
  ### 2.8.1 - 2019-03-01
4
12
 
5
13
  Add missing options.
data/bin/agoo CHANGED
@@ -190,6 +190,22 @@ else
190
190
  end
191
191
  ::Rack::Handler::Agoo.run(handler, options)
192
192
  end
193
- puts " Running #{@run_file}" if 1 <= @verbose
194
- load(@run_file)
193
+
194
+ path = File.expand_path(@run_file)
195
+ if @run_file.end_with?('.ru')
196
+ begin
197
+ require 'rack'
198
+ puts " Racking #{@run_file}" if 1 <= @verbose
199
+ app = Rack::Builder.new {
200
+ eval(File.open(path).read)
201
+ }
202
+ run app
203
+ rescue LoadError
204
+ puts " Running #{path}" if 1 <= @verbose
205
+ load(path)
206
+ end
207
+ else
208
+ puts " Running #{path}" if 1 <= @verbose
209
+ load(path)
210
+ end
195
211
  end
@@ -14,10 +14,12 @@ typedef struct _errorStream {
14
14
 
15
15
  static void
16
16
  es_free(void *ptr) {
17
- ErrorStream es = (ErrorStream)ptr;
17
+ if (NULL != ptr) {
18
+ ErrorStream es = (ErrorStream)ptr;
18
19
 
19
- AGOO_FREE(es->text); // allocated with malloc
20
- AGOO_FREE(ptr);
20
+ AGOO_FREE(es->text); // allocated with malloc
21
+ AGOO_FREE(ptr);
22
+ }
21
23
  }
22
24
 
23
25
  VALUE
@@ -45,6 +47,9 @@ static VALUE
45
47
  es_puts(VALUE self, VALUE str) {
46
48
  ErrorStream es = (ErrorStream)DATA_PTR(self);
47
49
 
50
+ if (NULL == es) {
51
+ rb_raise(rb_eIOError, "error stream has been closed.");
52
+ }
48
53
  es->text = agoo_text_append(es->text, StringValuePtr(str), (int)RSTRING_LEN(str));
49
54
  es->text = agoo_text_append(es->text, "\n", 1);
50
55
  if (NULL == es->text) {
@@ -64,6 +69,9 @@ es_write(VALUE self, VALUE str) {
64
69
  ErrorStream es = (ErrorStream)DATA_PTR(self);
65
70
  int cnt = (int)RSTRING_LEN(str);
66
71
 
72
+ if (NULL == es) {
73
+ rb_raise(rb_eIOError, "error stream has been closed.");
74
+ }
67
75
  if (NULL == (es->text = agoo_text_append(es->text, StringValuePtr(str), cnt))) {
68
76
  rb_raise(rb_eNoMemError, "Failed to allocate memory for the error stream puts.");
69
77
  }
@@ -80,12 +88,32 @@ static VALUE
80
88
  es_flush(VALUE self) {
81
89
  ErrorStream es = (ErrorStream)DATA_PTR(self);
82
90
 
91
+ if (NULL == es) {
92
+ rb_raise(rb_eIOError, "error stream has been closed.");
93
+ }
83
94
  agoo_log_cat(&agoo_error_cat, "%s", es->text->text);
84
95
  es->text->len = 0;
85
96
 
86
97
  return self;
87
98
  }
88
99
 
100
+ /* Document-method: close
101
+
102
+ * call-seq: close()
103
+ *
104
+ * Closes the stream.
105
+ */
106
+ static VALUE
107
+ es_close(VALUE self) {
108
+ ErrorStream es = (ErrorStream)DATA_PTR(self);
109
+
110
+ es_flush(self);
111
+ DATA_PTR(self) = NULL;
112
+ es_free(es);
113
+
114
+ return self;
115
+ }
116
+
89
117
  /* Document-class: Agoo::ErrorStream
90
118
  *
91
119
  * Used in a reqquest as the _rack.errors_ attribute. Writing to the stream
@@ -98,4 +126,5 @@ error_stream_init(VALUE mod) {
98
126
  rb_define_method(es_class, "puts", es_puts, 1);
99
127
  rb_define_method(es_class, "write", es_write, 1);
100
128
  rb_define_method(es_class, "flush", es_flush, 0);
129
+ rb_define_method(es_class, "close", es_close, 0);
101
130
  }
@@ -108,6 +108,7 @@ agooQItem
108
108
  agoo_queue_pop(agooQueue q, double timeout) {
109
109
  agooQItem item;
110
110
  agooQItem *next;
111
+ int cnt;
111
112
 
112
113
  if (q->multi_pop) {
113
114
  while (atomic_flag_test_and_set(&q->pop_lock)) {
@@ -129,7 +130,7 @@ agoo_queue_pop(agooQueue q, double timeout) {
129
130
  next = q->q;
130
131
  }
131
132
  // If the next is the tail then wait for something to be appended.
132
- for (int cnt = (int)(timeout / (double)WAIT_MSECS * 1000.0); atomic_load(&q->tail) == next; cnt--) {
133
+ for (cnt = (int)(timeout / (double)WAIT_MSECS * 1000.0); atomic_load(&q->tail) == next; cnt--) {
133
134
  struct pollfd pa;
134
135
 
135
136
  if (cnt <= 0) {
@@ -919,7 +919,7 @@ handle(VALUE self, VALUE method, VALUE pattern, VALUE handler) {
919
919
  handler = resolve_classpath(StringValuePtr(handler), RSTRING_LEN(handler));
920
920
  }
921
921
  if (rb_respond_to(handler, static_id)) {
922
- if (Qtrue == rb_funcall(handler, static_id, 0, Qnil)) {
922
+ if (Qtrue == rb_funcall(handler, static_id, 0)) {
923
923
  VALUE res = rb_funcall(handler, call_id, 1, Qnil);
924
924
  VALUE bv;
925
925
 
@@ -24,6 +24,8 @@
24
24
 
25
25
  struct _agooServer agoo_server = {false};
26
26
 
27
+ double agoo_io_loop_ratio = 0.5;
28
+
27
29
  int
28
30
  agoo_server_setup(agooErr err) {
29
31
  long i;
@@ -40,7 +42,7 @@ agoo_server_setup(agooErr err) {
40
42
  }
41
43
  agoo_server.loop_max = 4;
42
44
  if (0 < (i = sysconf(_SC_NPROCESSORS_ONLN))) {
43
- i /= 2;
45
+ i = (int)(i * agoo_io_loop_ratio);
44
46
  if (1 >= i) {
45
47
  i = 1;
46
48
  }
@@ -252,6 +254,7 @@ void
252
254
  agoo_server_bind(agooBind b) {
253
255
  // If a bind with the same port already exists, replace it.
254
256
  agooBind prev = NULL;
257
+ agooBind bx = NULL;
255
258
 
256
259
  if (NULL == b->read) {
257
260
  b->read = agoo_con_http_read;
@@ -262,7 +265,7 @@ agoo_server_bind(agooBind b) {
262
265
  if (NULL == b->events) {
263
266
  b->events = agoo_con_http_events;
264
267
  }
265
- for (agooBind bx = agoo_server.binds; NULL != bx; bx = bx->next) {
268
+ for (bx = agoo_server.binds; NULL != bx; bx = bx->next) {
266
269
  if (bx->port == b->port) {
267
270
  b->next = bx->next;
268
271
  if (NULL == prev) {
@@ -36,20 +36,18 @@ typedef struct _agooServer {
36
36
  int loop_max;
37
37
  int loop_cnt;
38
38
  atomic_int con_cnt;
39
-
39
+
40
40
  struct _agooUpgraded *up_list;
41
41
  pthread_mutex_t up_lock;
42
42
  int max_push_pending;
43
43
  void *env_nil_value;
44
44
  void *ctx_nil_value;
45
-
45
+
46
46
  // A count of the running threads from the wrapper or the server managed
47
47
  // threads.
48
48
  atomic_int running;
49
49
  } *agooServer;
50
50
 
51
- extern struct _agooServer agoo_server;
52
-
53
51
  extern int agoo_server_setup(agooErr err);
54
52
  extern void agoo_server_shutdown(const char *app_name, void (*stop)());
55
53
  extern void agoo_server_bind(agooBind b);
@@ -67,4 +65,8 @@ extern int agoo_server_add_func_hook(agooErr err,
67
65
 
68
66
  extern void agoo_server_publish(struct _agooPub *pub);
69
67
 
68
+ extern struct _agooServer agoo_server;
69
+
70
+ extern double agoo_io_loop_ratio;
71
+
70
72
  #endif // AGOO_SERVER_H
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Agoo
3
3
  # Agoo version.
4
- VERSION = '2.8.1'
4
+ VERSION = '2.8.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.1
4
+ version: 2.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-01 00:00:00.000000000 Z
11
+ date: 2019-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj