agoo 2.5.7 → 2.6.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.

Potentially problematic release.


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

Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +38 -0
  4. data/ext/agoo/agoo.c +11 -2
  5. data/ext/agoo/bind.c +15 -20
  6. data/ext/agoo/con.c +32 -25
  7. data/ext/agoo/debug.c +225 -162
  8. data/ext/agoo/debug.h +31 -51
  9. data/ext/agoo/doc.c +278 -5
  10. data/ext/agoo/doc.h +6 -1
  11. data/ext/agoo/err.c +1 -0
  12. data/ext/agoo/err.h +1 -0
  13. data/ext/agoo/error_stream.c +3 -6
  14. data/ext/agoo/gqlcobj.c +12 -0
  15. data/ext/agoo/gqlcobj.h +25 -0
  16. data/ext/agoo/gqleval.c +520 -0
  17. data/ext/agoo/gqleval.h +49 -0
  18. data/ext/agoo/gqlintro.c +1237 -97
  19. data/ext/agoo/gqlintro.h +8 -0
  20. data/ext/agoo/gqljson.c +460 -0
  21. data/ext/agoo/gqljson.h +15 -0
  22. data/ext/agoo/gqlvalue.c +679 -136
  23. data/ext/agoo/gqlvalue.h +29 -7
  24. data/ext/agoo/graphql.c +841 -362
  25. data/ext/agoo/graphql.h +180 -90
  26. data/ext/agoo/hook.c +8 -16
  27. data/ext/agoo/http.c +3 -4
  28. data/ext/agoo/log.c +22 -25
  29. data/ext/agoo/log.h +1 -0
  30. data/ext/agoo/page.c +24 -40
  31. data/ext/agoo/pub.c +23 -21
  32. data/ext/agoo/queue.c +2 -4
  33. data/ext/agoo/ready.c +9 -9
  34. data/ext/agoo/req.c +80 -5
  35. data/ext/agoo/req.h +2 -0
  36. data/ext/agoo/res.c +1 -3
  37. data/ext/agoo/rgraphql.c +753 -0
  38. data/ext/agoo/rresponse.c +9 -15
  39. data/ext/agoo/rserver.c +18 -17
  40. data/ext/agoo/sdl.c +1264 -120
  41. data/ext/agoo/sdl.h +8 -1
  42. data/ext/agoo/sectime.c +136 -0
  43. data/ext/agoo/sectime.h +19 -0
  44. data/ext/agoo/server.c +1 -3
  45. data/ext/agoo/subject.c +2 -4
  46. data/ext/agoo/text.c +124 -18
  47. data/ext/agoo/text.h +5 -1
  48. data/ext/agoo/upgraded.c +2 -4
  49. data/lib/agoo/version.rb +1 -1
  50. data/test/base_handler_test.rb +43 -40
  51. data/test/bind_test.rb +49 -48
  52. data/test/graphql_test.rb +1019 -0
  53. data/test/hijack_test.rb +1 -1
  54. data/test/rack_handler_test.rb +40 -34
  55. data/test/static_test.rb +33 -32
  56. metadata +17 -6
@@ -15,6 +15,7 @@
15
15
  #include "debug.h"
16
16
  #include "dtime.h"
17
17
  #include "log.h"
18
+ #include "sectime.h"
18
19
 
19
20
  // lower gives faster response but burns more CPU. This is a reasonable compromise.
20
21
  #define RETRY_SECS 0.0001
@@ -183,12 +184,14 @@ classic_write(agooLogEntry e, FILE *file) {
183
184
  min = t % 3600 / 60;
184
185
  sec = t % 60;
185
186
  } else {
186
- struct tm *tm = gmtime(&t);
187
+ struct _agooTime at;
187
188
 
188
- hour = tm->tm_hour;
189
- min = tm->tm_min;
190
- sec = tm->tm_sec;
191
- sprintf(agoo_log.day_buf, "%04d/%02d/%02d ", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
189
+ agoo_sectime(t, &at);
190
+
191
+ hour = at.hour;
192
+ min = at.min;
193
+ sec = at.sec;
194
+ sprintf(agoo_log.day_buf, "%04d/%02d/%02d ", at.year, at.mon, at.day);
192
195
  agoo_log.day_start = t - (hour * 3600 + min * 60 + sec);
193
196
  agoo_log.day_end = agoo_log.day_start + 86400;
194
197
  }
@@ -325,12 +328,10 @@ loop(void *ctx) {
325
328
  }
326
329
  }
327
330
  if (NULL != e->whatp) {
328
- free(e->whatp);
329
- DEBUG_FREE(mem_agoo_log_what, e->whatp)
331
+ AGOO_FREE(e->whatp);
330
332
  }
331
333
  if (NULL != e->tidp) {
332
- free(e->tidp);
333
- DEBUG_FREE(mem_agoo_log_tid, e->tidp)
334
+ AGOO_FREE(e->tidp);
334
335
  }
335
336
  e->ready = false;
336
337
  }
@@ -391,8 +392,7 @@ agoo_log_close() {
391
392
  agoo_log.file = NULL;
392
393
  }
393
394
  if (NULL != agoo_log.q) {
394
- DEBUG_FREE(mem_agoo_log_entry, agoo_log.q);
395
- free(agoo_log.q);
395
+ AGOO_FREE(agoo_log.q);
396
396
  agoo_log.q = NULL;
397
397
  agoo_log.end = NULL;
398
398
  }
@@ -449,8 +449,8 @@ agoo_log_cat_find(const char *label) {
449
449
  }
450
450
 
451
451
  #ifdef CLOCK_REALTIME
452
- static int64_t
453
- now_nano() {
452
+ int64_t
453
+ agoo_now_nano() {
454
454
  struct timespec ts;
455
455
 
456
456
  clock_gettime(CLOCK_REALTIME, &ts);
@@ -458,8 +458,8 @@ now_nano() {
458
458
  return (int64_t)ts.tv_sec * 1000000000LL + (int64_t)ts.tv_nsec;
459
459
  }
460
460
  #else
461
- static int64_t
462
- now_nano() {
461
+ int64_t
462
+ agoo_now_nano() {
463
463
  struct timeval tv;
464
464
  struct timezone tz;
465
465
 
@@ -476,23 +476,21 @@ set_entry(agooLogEntry e, agooLogCat cat, const char *tid, const char *fmt, va_l
476
476
  va_copy(ap2, ap);
477
477
 
478
478
  e->cat = cat;
479
- e->when = now_nano();
479
+ e->when = agoo_now_nano();
480
480
  e->whatp = NULL;
481
481
  if ((int)sizeof(e->what) <= (cnt = vsnprintf(e->what, sizeof(e->what), fmt, ap))) {
482
- e->whatp = (char*)malloc(cnt + 1);
482
+ e->whatp = (char*)AGOO_MALLOC(cnt + 1);
483
483
 
484
- DEBUG_ALLOC(mem_log_what, e->whatp)
485
-
486
- if (NULL != e->whatp) {
487
- vsnprintf(e->whatp, cnt + 1, fmt, ap2);
488
- }
484
+ if (NULL != e->whatp) {
485
+ vsnprintf(e->whatp, cnt + 1, fmt, ap2);
486
+ }
489
487
  }
490
488
  if (NULL != tid) {
491
489
  e->tidp = NULL;
492
490
  if (strlen(tid) < sizeof(e->tid)) {
493
491
  strcpy(e->tid, tid);
494
492
  } else {
495
- if (NULL != (e->tidp = strdup(tid))) {
493
+ if (NULL != (e->tidp = AGOO_STRDUP(tid))) {
496
494
  *e->tid = '\0';
497
495
  }
498
496
  }
@@ -617,8 +615,7 @@ agoo_log_init(const char *app) {
617
615
  *agoo_log.day_buf = '\0';
618
616
  agoo_log.thread = 0;
619
617
 
620
- agoo_log.q = (agooLogEntry)malloc(sizeof(struct _agooLogEntry) * qsize);
621
- DEBUG_ALLOC(mem_log_entry, agoo_log.q)
618
+ agoo_log.q = (agooLogEntry)AGOO_MALLOC(sizeof(struct _agooLogEntry) * qsize);
622
619
  agoo_log.end = agoo_log.q + qsize;
623
620
  memset(agoo_log.q, 0, sizeof(struct _agooLogEntry) * qsize);
624
621
  atomic_init(&agoo_log.head, agoo_log.q);
@@ -124,5 +124,6 @@ extern void agoo_log_catv(agooLogCat cat, const char *tid, const char *fmt, va_
124
124
  extern int agoo_log_start(agooErr err, bool with_pid);
125
125
 
126
126
  extern agooColor find_color(const char *name);
127
+ extern int64_t agoo_now_nano();
127
128
 
128
129
  #endif /* AGOO_LOG_H */
@@ -195,16 +195,14 @@ mime_set(agooErr err, const char *key, const char *value) {
195
195
  if (h == (int64_t)s->hash && len == s->klen &&
196
196
  ((0 <= len && len <= MAX_KEY_UNIQ) || 0 == strncmp(s->key, key, len))) {
197
197
 
198
- DEBUG_FREE(mem_mime_slot, s->value);
199
- free(s->value);
200
- s->value = strdup(value);
198
+ AGOO_FREE(s->value);
199
+ s->value = AGOO_STRDUP(value);
201
200
  return AGOO_ERR_OK;
202
201
  }
203
202
  }
204
- if (NULL == (s = (MimeSlot)malloc(sizeof(struct _mimeSlot)))) {
203
+ if (NULL == (s = (MimeSlot)AGOO_MALLOC(sizeof(struct _mimeSlot)))) {
205
204
  return agoo_err_set(err, AGOO_ERR_ARG, "out of memory adding %s", key);
206
205
  }
207
- DEBUG_ALLOC(mem_mime_slot, s);
208
206
  s->hash = h;
209
207
  s->klen = len;
210
208
  if (NULL == key) {
@@ -212,7 +210,7 @@ mime_set(agooErr err, const char *key, const char *value) {
212
210
  } else {
213
211
  strcpy(s->key, key);
214
212
  }
215
- s->value = strdup(value);
213
+ s->value = AGOO_STRDUP(value);
216
214
  s->next = *bucket;
217
215
  *bucket = s;
218
216
 
@@ -241,10 +239,9 @@ cache_set(const char *key, int klen, agooPage value) {
241
239
  return old;
242
240
  }
243
241
  }
244
- if (NULL == (s = (Slot)malloc(sizeof(struct _slot)))) {
242
+ if (NULL == (s = (Slot)AGOO_MALLOC(sizeof(struct _slot)))) {
245
243
  return value;
246
244
  }
247
- DEBUG_ALLOC(mem_page_slot, s)
248
245
  s->hash = h;
249
246
  s->klen = len;
250
247
  if (NULL == key) {
@@ -266,7 +263,7 @@ agoo_pages_init() {
266
263
  struct _agooErr err = AGOO_ERR_INIT;
267
264
 
268
265
  memset(&cache, 0, sizeof(struct _cache));
269
- cache.root = strdup(".");
266
+ cache.root = AGOO_STRDUP(".");
270
267
  for (m = mime_map; NULL != m->suffix; m++) {
271
268
  mime_set(&err, m->suffix, m->type);
272
269
  }
@@ -274,11 +271,11 @@ agoo_pages_init() {
274
271
 
275
272
  void
276
273
  agoo_pages_set_root(const char *root) {
277
- free(cache.root);
274
+ AGOO_FREE(cache.root);
278
275
  if (NULL == root) {
279
276
  cache.root = NULL;
280
277
  } else {
281
- cache.root = strdup(root);
278
+ cache.root = AGOO_STRDUP(root);
282
279
  }
283
280
  }
284
281
 
@@ -288,10 +285,8 @@ agoo_page_destroy(agooPage p) {
288
285
  agoo_text_release(p->resp);
289
286
  p->resp = NULL;
290
287
  }
291
- DEBUG_FREE(mem_page_path, p->path);
292
- DEBUG_FREE(mem_page, p);
293
- free(p->path);
294
- free(p);
288
+ AGOO_FREE(p->path);
289
+ AGOO_FREE(p);
295
290
  }
296
291
 
297
292
  void
@@ -307,21 +302,20 @@ agoo_pages_cleanup() {
307
302
  for (i = PAGE_BUCKET_SIZE; 0 < i; i--, sp++) {
308
303
  for (s = *sp; NULL != s; s = n) {
309
304
  n = s->next;
310
- DEBUG_FREE(mem_page_slot, s);
311
305
  agoo_page_destroy(s->value);
312
- free(s);
306
+ AGOO_FREE(s);
313
307
  }
314
308
  *sp = NULL;
315
309
  }
316
310
  for (i = MIME_BUCKET_SIZE; 0 < i; i--, mp++) {
317
311
  for (sm = *mp; NULL != sm; sm = m) {
318
312
  m = sm->next;
319
- DEBUG_FREE(mem_mime_slot, sm);
320
- free(sm);
313
+ AGOO_FREE(sm->value);
314
+ AGOO_FREE(sm);
321
315
  }
322
316
  *mp = NULL;
323
317
  }
324
- free(cache.root);
318
+ AGOO_FREE(cache.root);
325
319
  }
326
320
 
327
321
  static const char*
@@ -349,16 +343,14 @@ path_mime(const char *path) {
349
343
  // allocations.
350
344
  agooPage
351
345
  agoo_page_create(const char *path) {
352
- agooPage p = (agooPage)malloc(sizeof(struct _agooPage));
346
+ agooPage p = (agooPage)AGOO_MALLOC(sizeof(struct _agooPage));
353
347
 
354
348
  if (NULL != p) {
355
- DEBUG_ALLOC(mem_page, p);
356
349
  p->resp = NULL;
357
350
  if (NULL == path) {
358
351
  p->path = NULL;
359
352
  } else {
360
- p->path = strdup(path);
361
- DEBUG_ALLOC(mem_page_path, p->path);
353
+ p->path = AGOO_STRDUP(path);
362
354
  }
363
355
  p->mtime = 0;
364
356
  p->last_check = 0.0;
@@ -369,7 +361,7 @@ agoo_page_create(const char *path) {
369
361
 
370
362
  agooPage
371
363
  agoo_page_immutable(agooErr err, const char *path, const char *content, int clen) {
372
- agooPage p = (agooPage)malloc(sizeof(struct _agooPage));
364
+ agooPage p = (agooPage)AGOO_MALLOC(sizeof(struct _agooPage));
373
365
  const char *mime = path_mime(path);
374
366
  long msize;
375
367
  int cnt;
@@ -379,13 +371,11 @@ agoo_page_immutable(agooErr err, const char *path, const char *content, int clen
379
371
  agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocate memory for page.");
380
372
  return NULL;
381
373
  }
382
- DEBUG_ALLOC(mem_page, p);
383
374
  if (NULL == path) {
384
375
  p->path = NULL;
385
376
  } else {
386
- p->path = strdup(path);
377
+ p->path = AGOO_STRDUP(path);
387
378
  plen = (int)strlen(path);
388
- DEBUG_ALLOC(mem_page_path, p->path);
389
379
  }
390
380
  p->mtime = 0;
391
381
  p->last_check = 0.0;
@@ -401,8 +391,7 @@ agoo_page_immutable(agooErr err, const char *path, const char *content, int clen
401
391
  // padding. Then add the content length.
402
392
  msize = sizeof(page_fmt) + 60 + clen;
403
393
  if (NULL == (p->resp = agoo_text_allocate((int)msize))) {
404
- DEBUG_FREE(mem_page, p);
405
- free(p);
394
+ AGOO_FREE(p);
406
395
  agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocate memory for page content.");
407
396
  return NULL;
408
397
  }
@@ -532,9 +521,8 @@ agoo_page_remove(agooPage p) {
532
521
  } else {
533
522
  prev->next = s->next;
534
523
  }
535
- DEBUG_FREE(mem_page_slot, s);
536
524
  agoo_page_destroy(s->value);
537
- free(s);
525
+ AGOO_FREE(s);
538
526
 
539
527
  break;
540
528
  }
@@ -677,15 +665,13 @@ group_get(agooErr err, const char *path, int plen) {
677
665
 
678
666
  agooGroup
679
667
  group_create(const char *path) {
680
- agooGroup g = (agooGroup)malloc(sizeof(struct _agooGroup));
668
+ agooGroup g = (agooGroup)AGOO_MALLOC(sizeof(struct _agooGroup));
681
669
 
682
670
  if (NULL != g) {
683
- DEBUG_ALLOC(mem_group, g);
684
671
  g->next = cache.groups;
685
672
  cache.groups = g;
686
- g->path = strdup(path);
673
+ g->path = AGOO_STRDUP(path);
687
674
  g->plen = (int)strlen(path);
688
- DEBUG_ALLOC(mem_group_path, g->path);
689
675
  g->dirs = NULL;
690
676
  }
691
677
  return g;
@@ -693,14 +679,12 @@ group_create(const char *path) {
693
679
 
694
680
  void
695
681
  group_add(agooGroup g, const char *dir) {
696
- agooDir d = (agooDir)malloc(sizeof(struct _agooDir));
682
+ agooDir d = (agooDir)AGOO_MALLOC(sizeof(struct _agooDir));
697
683
 
698
684
  if (NULL != d) {
699
- DEBUG_ALLOC(mem_dir, d);
700
685
  d->next = g->dirs;
701
686
  g->dirs = d;
702
- d->path = strdup(dir);
687
+ d->path = AGOO_STRDUP(dir);
703
688
  d->plen = (int)strlen(dir);
704
- DEBUG_ALLOC(mem_dir_path, d->path);
705
689
  }
706
690
  }
@@ -12,10 +12,9 @@
12
12
 
13
13
  agooPub
14
14
  agoo_pub_close(agooUpgraded up) {
15
- agooPub p = (agooPub)malloc(sizeof(struct _agooPub));
15
+ agooPub p = (agooPub)AGOO_MALLOC(sizeof(struct _agooPub));
16
16
 
17
17
  if (NULL != p) {
18
- DEBUG_ALLOC(mem_pub, p);
19
18
  p->next = NULL;
20
19
  p->kind = AGOO_PUB_CLOSE;
21
20
  p->up = up;
@@ -27,10 +26,9 @@ agoo_pub_close(agooUpgraded up) {
27
26
 
28
27
  agooPub
29
28
  agoo_pub_subscribe(agooUpgraded up, const char *subject, int slen) {
30
- agooPub p = (agooPub)malloc(sizeof(struct _agooPub));
29
+ agooPub p = (agooPub)AGOO_MALLOC(sizeof(struct _agooPub));
31
30
 
32
31
  if (NULL != p) {
33
- DEBUG_ALLOC(mem_pub, p);
34
32
  p->next = NULL;
35
33
  p->kind = AGOO_PUB_SUB;
36
34
  p->up = up;
@@ -42,10 +40,9 @@ agoo_pub_subscribe(agooUpgraded up, const char *subject, int slen) {
42
40
 
43
41
  agooPub
44
42
  agoo_pub_unsubscribe(agooUpgraded up, const char *subject, int slen) {
45
- agooPub p = (agooPub)malloc(sizeof(struct _agooPub));
43
+ agooPub p = (agooPub)AGOO_MALLOC(sizeof(struct _agooPub));
46
44
 
47
45
  if (NULL != p) {
48
- DEBUG_ALLOC(mem_pub, p);
49
46
  p->next = NULL;
50
47
  p->kind = AGOO_PUB_UN;
51
48
  p->up = up;
@@ -61,17 +58,16 @@ agoo_pub_unsubscribe(agooUpgraded up, const char *subject, int slen) {
61
58
 
62
59
  agooPub
63
60
  agoo_pub_publish(const char *subject, int slen, const char *message, size_t mlen) {
64
- agooPub p = (agooPub)malloc(sizeof(struct _agooPub));
61
+ agooPub p = (agooPub)AGOO_MALLOC(sizeof(struct _agooPub));
65
62
 
66
63
  if (NULL != p) {
67
- DEBUG_ALLOC(mem_pub, p);
68
64
  p->next = NULL;
69
65
  p->kind = AGOO_PUB_MSG;
70
66
  p->up = NULL;
71
67
  p->subject = agoo_subject_create(subject, slen);
72
- // Allocate an extra 24 bytes so the message can be expanded in place
68
+ // Allocate an extra 32 bytes so the message can be expanded in place
73
69
  // if a WebSocket or SSE write.
74
- p->msg = agoo_text_append(agoo_text_allocate((int)mlen + 24), message, (int)mlen);
70
+ p->msg = agoo_text_append(agoo_text_allocate((int)mlen + 32), message, (int)mlen);
75
71
  agoo_text_ref(p->msg);
76
72
  }
77
73
  return p;
@@ -81,17 +77,16 @@ agooPub
81
77
  agoo_pub_write(agooUpgraded up, const char *message, size_t mlen, bool bin) {
82
78
  // Allocate an extra 16 bytes so the message can be expanded in place if a
83
79
  // WebSocket write.
84
- agooPub p = (agooPub)malloc(sizeof(struct _agooPub));
80
+ agooPub p = (agooPub)AGOO_MALLOC(sizeof(struct _agooPub));
85
81
 
86
82
  if (NULL != p) {
87
- DEBUG_ALLOC(mem_pub, p);
88
83
  p->next = NULL;
89
84
  p->kind = AGOO_PUB_WRITE;
90
85
  p->up = up;
91
86
  p->subject = NULL;
92
- // Allocate an extra 16 bytes so the message can be expanded in place
93
- // if a WebSocket write.
94
- p->msg = agoo_text_append(agoo_text_allocate((int)mlen + 16), message, (int)mlen);
87
+ // Allocate an extra 32 bytes so the message can be expanded in place
88
+ // if a WebSocket or SSE write.
89
+ p->msg = agoo_text_append(agoo_text_allocate((int)mlen + 32), message, (int)mlen);
95
90
  p->msg->bin = bin;
96
91
  agoo_text_ref(p->msg);
97
92
  }
@@ -100,16 +95,24 @@ agoo_pub_write(agooUpgraded up, const char *message, size_t mlen, bool bin) {
100
95
 
101
96
  agooPub
102
97
  agoo_pub_dup(agooPub src) {
103
- agooPub p = (agooPub)malloc(sizeof(struct _agooPub));
98
+ agooPub p = (agooPub)AGOO_MALLOC(sizeof(struct _agooPub));
104
99
 
105
100
  if (NULL != p) {
106
- DEBUG_ALLOC(mem_pub, p);
107
101
  p->next = NULL;
108
102
  p->kind = src->kind;
109
103
  p->up = src->up;
110
- p->subject = agoo_subject_create(src->subject->pattern, strlen(src->subject->pattern));
104
+ if (NULL != p->up) {
105
+ agoo_upgraded_ref(p->up);
106
+ }
107
+ if (NULL == src->subject) {
108
+ p->subject = NULL;
109
+ } else {
110
+ p->subject = agoo_subject_create(src->subject->pattern, strlen(src->subject->pattern));
111
+ }
111
112
  p->msg = src->msg;
112
- agoo_text_ref(p->msg);
113
+ if (NULL != p->msg) {
114
+ agoo_text_ref(p->msg);
115
+ }
113
116
  }
114
117
  return p;
115
118
  }
@@ -125,7 +128,6 @@ agoo_pub_destroy(agooPub pub) {
125
128
  if (NULL != pub->up) {
126
129
  agoo_upgraded_release(pub->up);
127
130
  }
128
- DEBUG_FREE(mem_pub, pub);
129
- free(pub);
131
+ AGOO_FREE(pub);
130
132
  }
131
133
 
@@ -36,8 +36,7 @@ agoo_queue_multi_init(agooQueue q, size_t qsize, bool multi_push, bool multi_pop
36
36
  if (qsize < 4) {
37
37
  qsize = 4;
38
38
  }
39
- q->q = (agooQItem*)malloc(sizeof(agooQItem) * qsize);
40
- DEBUG_ALLOC(mem_qitem, q->q)
39
+ q->q = (agooQItem*)AGOO_MALLOC(sizeof(agooQItem) * qsize);
41
40
  q->end = q->q + qsize;
42
41
 
43
42
  memset(q->q, 0, sizeof(agooQItem) * qsize);
@@ -55,8 +54,7 @@ agoo_queue_multi_init(agooQueue q, size_t qsize, bool multi_push, bool multi_pop
55
54
 
56
55
  void
57
56
  agoo_queue_cleanup(agooQueue q) {
58
- DEBUG_FREE(mem_qitem, q->q)
59
- free(q->q);
57
+ AGOO_FREE(q->q);
60
58
  q->q = NULL;
61
59
  q->end = NULL;
62
60
  if (0 < q->wsock) {
@@ -13,6 +13,7 @@
13
13
  #include <poll.h>
14
14
  #endif
15
15
 
16
+ #include "debug.h"
16
17
  #include "dtime.h"
17
18
  #include "log.h"
18
19
  #include "ready.h"
@@ -55,7 +56,7 @@ struct _agooReady {
55
56
  static Link
56
57
  link_create(agooErr err, int fd, void *ctx, agooHandler handler) {
57
58
  // TBD use block allocator
58
- Link link = (Link)malloc(sizeof(struct _link));
59
+ Link link = (Link)AGOO_MALLOC(sizeof(struct _link));
59
60
 
60
61
  if (NULL == link) {
61
62
  agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocate memory for a connection link.");
@@ -72,7 +73,7 @@ link_create(agooErr err, int fd, void *ctx, agooHandler handler) {
72
73
 
73
74
  agooReady
74
75
  agoo_ready_create(agooErr err) {
75
- agooReady ready = (agooReady)malloc(sizeof(struct _agooReady));
76
+ agooReady ready = (agooReady)AGOO_MALLOC(sizeof(struct _agooReady));
76
77
 
77
78
  if (NULL == ready) {
78
79
  agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocate memory for a connection manager.");
@@ -90,7 +91,7 @@ agoo_ready_create(agooErr err) {
90
91
  {
91
92
  size_t size = sizeof(struct pollfd) * INITIAL_POLL_SIZE;
92
93
 
93
- ready->pa = (struct pollfd*)malloc(size);
94
+ ready->pa = (struct pollfd*)AGOO_MALLOC(size);
94
95
  ready->pend = ready->pa + INITIAL_POLL_SIZE;
95
96
  memset(ready->pa, 0, size);
96
97
  }
@@ -108,14 +109,14 @@ agoo_ready_destroy(agooReady ready) {
108
109
  if (NULL != link->handler->destroy) {
109
110
  link->handler->destroy(link->ctx);
110
111
  }
111
- free(link);
112
+ AGOO_FREE(link);
112
113
  }
113
114
  #if HAVE_SYS_EPOLL_H
114
115
  close(ready->epoll_fd);
115
116
  #else
116
- free(ready->pa);
117
+ AGOO_FREE(ready->pa);
117
118
  #endif
118
- free(ready);
119
+ AGOO_FREE(ready);
119
120
  }
120
121
 
121
122
  int
@@ -155,7 +156,7 @@ agoo_ready_add(agooErr err,
155
156
  size_t cnt = (ready->pend - ready->pa) * 2;
156
157
  size_t size = cnt * sizeof(struct pollfd);
157
158
 
158
- if (NULL == (ready->pa = (struct pollfd*)realloc(ready->pa, size))) {
159
+ if (NULL == (ready->pa = (struct pollfd*)AGOO_REALLOC(ready->pa, size))) {
159
160
  agoo_err_set(err, AGOO_ERR_MEMORY, "Failed to allocate memory for a connection pool.");
160
161
  agoo_log_cat(&agoo_error_cat, "Out of memory.");
161
162
  agoo_log_close();
@@ -196,8 +197,7 @@ ready_remove(agooReady ready, Link link) {
196
197
  if (NULL != link->handler->destroy) {
197
198
  link->handler->destroy(link->ctx);
198
199
  }
199
- //DEBUG_FREE(mem_???, c);
200
- free(link);
200
+ AGOO_FREE(link);
201
201
  ready->lcnt--;
202
202
  }
203
203