iodine 0.6.5 → 0.7.0

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.

Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +4 -4
  4. data/SPEC-Websocket-Draft.md +3 -6
  5. data/bin/mustache.rb +128 -0
  6. data/examples/test_template.mustache +16 -0
  7. data/ext/iodine/fio.c +9397 -0
  8. data/ext/iodine/fio.h +4723 -0
  9. data/ext/iodine/fio_ary.h +353 -54
  10. data/ext/iodine/fio_cli.c +351 -361
  11. data/ext/iodine/fio_cli.h +84 -105
  12. data/ext/iodine/fio_hashmap.h +70 -16
  13. data/ext/iodine/fio_json_parser.h +35 -24
  14. data/ext/iodine/fio_siphash.c +104 -4
  15. data/ext/iodine/fio_siphash.h +18 -2
  16. data/ext/iodine/fio_str.h +1218 -0
  17. data/ext/iodine/fio_tmpfile.h +1 -1
  18. data/ext/iodine/fiobj.h +13 -8
  19. data/ext/iodine/fiobj4sock.h +6 -8
  20. data/ext/iodine/fiobj_ary.c +107 -17
  21. data/ext/iodine/fiobj_ary.h +36 -4
  22. data/ext/iodine/fiobj_data.c +146 -127
  23. data/ext/iodine/fiobj_data.h +25 -23
  24. data/ext/iodine/fiobj_hash.c +7 -7
  25. data/ext/iodine/fiobj_hash.h +6 -5
  26. data/ext/iodine/fiobj_json.c +20 -17
  27. data/ext/iodine/fiobj_json.h +5 -5
  28. data/ext/iodine/fiobj_mem.h +71 -0
  29. data/ext/iodine/fiobj_mustache.c +310 -0
  30. data/ext/iodine/fiobj_mustache.h +40 -0
  31. data/ext/iodine/fiobj_numbers.c +199 -94
  32. data/ext/iodine/fiobj_numbers.h +7 -7
  33. data/ext/iodine/fiobj_str.c +142 -333
  34. data/ext/iodine/fiobj_str.h +65 -55
  35. data/ext/iodine/fiobject.c +49 -11
  36. data/ext/iodine/fiobject.h +40 -39
  37. data/ext/iodine/http.c +382 -190
  38. data/ext/iodine/http.h +124 -80
  39. data/ext/iodine/http1.c +99 -127
  40. data/ext/iodine/http1.h +5 -5
  41. data/ext/iodine/http1_parser.c +3 -2
  42. data/ext/iodine/http1_parser.h +2 -2
  43. data/ext/iodine/http_internal.c +14 -12
  44. data/ext/iodine/http_internal.h +25 -19
  45. data/ext/iodine/iodine.c +37 -18
  46. data/ext/iodine/iodine.h +4 -0
  47. data/ext/iodine/iodine_caller.c +9 -2
  48. data/ext/iodine/iodine_caller.h +2 -0
  49. data/ext/iodine/iodine_connection.c +82 -117
  50. data/ext/iodine/iodine_defer.c +57 -50
  51. data/ext/iodine/iodine_defer.h +0 -1
  52. data/ext/iodine/iodine_fiobj2rb.h +4 -2
  53. data/ext/iodine/iodine_helpers.c +4 -4
  54. data/ext/iodine/iodine_http.c +25 -32
  55. data/ext/iodine/iodine_json.c +2 -1
  56. data/ext/iodine/iodine_mustache.c +423 -0
  57. data/ext/iodine/iodine_mustache.h +6 -0
  58. data/ext/iodine/iodine_pubsub.c +48 -153
  59. data/ext/iodine/iodine_pubsub.h +5 -4
  60. data/ext/iodine/iodine_rack_io.c +7 -5
  61. data/ext/iodine/iodine_store.c +16 -13
  62. data/ext/iodine/iodine_tcp.c +26 -34
  63. data/ext/iodine/mustache_parser.h +1085 -0
  64. data/ext/iodine/redis_engine.c +740 -646
  65. data/ext/iodine/redis_engine.h +13 -15
  66. data/ext/iodine/resp_parser.h +11 -5
  67. data/ext/iodine/websocket_parser.h +13 -13
  68. data/ext/iodine/websockets.c +240 -393
  69. data/ext/iodine/websockets.h +52 -113
  70. data/lib/iodine.rb +1 -1
  71. data/lib/iodine/mustache.rb +140 -0
  72. data/lib/iodine/version.rb +1 -1
  73. metadata +15 -28
  74. data/ext/iodine/defer.c +0 -566
  75. data/ext/iodine/defer.h +0 -148
  76. data/ext/iodine/evio.c +0 -26
  77. data/ext/iodine/evio.h +0 -161
  78. data/ext/iodine/evio_callbacks.c +0 -26
  79. data/ext/iodine/evio_epoll.c +0 -251
  80. data/ext/iodine/evio_kqueue.c +0 -194
  81. data/ext/iodine/facil.c +0 -2325
  82. data/ext/iodine/facil.h +0 -616
  83. data/ext/iodine/fio_base64.c +0 -277
  84. data/ext/iodine/fio_base64.h +0 -71
  85. data/ext/iodine/fio_llist.h +0 -257
  86. data/ext/iodine/fio_mem.c +0 -675
  87. data/ext/iodine/fio_mem.h +0 -143
  88. data/ext/iodine/fio_random.c +0 -248
  89. data/ext/iodine/fio_random.h +0 -45
  90. data/ext/iodine/fio_sha1.c +0 -362
  91. data/ext/iodine/fio_sha1.h +0 -107
  92. data/ext/iodine/fio_sha2.c +0 -842
  93. data/ext/iodine/fio_sha2.h +0 -169
  94. data/ext/iodine/pubsub.c +0 -867
  95. data/ext/iodine/pubsub.h +0 -221
  96. data/ext/iodine/sock.c +0 -1366
  97. data/ext/iodine/sock.h +0 -566
  98. data/ext/iodine/spnlock.inc +0 -111
@@ -1,111 +0,0 @@
1
- #ifndef H_SPNLOCK_H
2
- #define H_SPNLOCK_H
3
- /*
4
- Copyright: Boaz Segev, 2016-2017
5
- License: MIT
6
-
7
- Feel free to copy, use and enjoy according to the license provided.
8
- */
9
- /* *****************************************************************************
10
- spinlock / sync for tasks
11
- ***************************************************************************** */
12
- #if defined(__unix__) || defined(__APPLE__) || defined(__linux__)
13
- #ifndef _GNU_SOURCE
14
- #define _GNU_SOURCE
15
- #endif
16
- #include <time.h>
17
- #endif /* __unix__ */
18
- #include <stdlib.h>
19
-
20
- /* manage the way threads "wait" for the lock to release */
21
- #if defined(__unix__) || defined(__APPLE__) || defined(__linux__)
22
- /* nanosleep seems to be the most effective and efficient reschedule */
23
- #define reschedule_thread() \
24
- { \
25
- const struct timespec tm = {.tv_nsec = 1}; \
26
- nanosleep(&tm, NULL); \
27
- }
28
- #define throttle_thread(micosec) \
29
- { \
30
- const struct timespec tm = {.tv_nsec = (micosec & 0xfffff), \
31
- .tv_sec = (micosec >> 20)}; \
32
- nanosleep(&tm, NULL); \
33
- }
34
- #else /* no effective rescheduling, just spin... */
35
- #define reschedule_thread()
36
- #define throttle_thread(micosec)
37
- #endif
38
-
39
- /** locks use a single byte */
40
- typedef volatile unsigned char spn_lock_i;
41
-
42
- /** The initail value of an unlocked spinlock. */
43
- #define SPN_LOCK_INIT 0
44
-
45
- /* C11 Atomics are defined? */
46
- #if defined(__ATOMIC_RELAXED)
47
- #define SPN_LOCK_BUILTIN(...) __atomic_exchange_n(__VA_ARGS__, __ATOMIC_SEQ_CST)
48
- /** An atomic addition operation */
49
- #define spn_add(...) __atomic_add_fetch(__VA_ARGS__, __ATOMIC_SEQ_CST)
50
- /** An atomic subtraction operation */
51
- #define spn_sub(...) __atomic_sub_fetch(__VA_ARGS__, __ATOMIC_SEQ_CST)
52
-
53
- /* Select the correct compiler builtin method. */
54
- #elif defined(__has_builtin)
55
-
56
- #if __has_builtin(__sync_fetch_and_or)
57
- #define SPN_LOCK_BUILTIN(...) __sync_fetch_and_or(__VA_ARGS__)
58
- /** An atomic addition operation */
59
- #define spn_add(...) __sync_add_and_fetch(__VA_ARGS__)
60
- /** An atomic subtraction operation */
61
- #define spn_sub(...) __sync_sub_and_fetch(__VA_ARGS__)
62
-
63
- #else
64
- #error Required builtin "__sync_swap" or "__sync_fetch_and_or" missing from compiler.
65
- #endif /* defined(__has_builtin) */
66
-
67
- #elif __GNUC__ > 3
68
- #define SPN_LOCK_BUILTIN(...) __sync_fetch_and_or(__VA_ARGS__)
69
- /** An atomic addition operation */
70
- #define spn_add(...) __sync_add_and_fetch(__VA_ARGS__)
71
- /** An atomic subtraction operation */
72
- #define spn_sub(...) __sync_sub_and_fetch(__VA_ARGS__)
73
-
74
- #else
75
- #error Required builtin "__sync_swap" or "__sync_fetch_and_or" not found.
76
- #endif
77
-
78
- /** returns 1 and 0 if the lock was successfully aquired (TRUE == FAIL). */
79
- static inline int spn_trylock(spn_lock_i *lock) {
80
- return SPN_LOCK_BUILTIN(lock, 1);
81
- }
82
-
83
- /** Releases a lock. */
84
- static inline __attribute__((unused)) int spn_unlock(spn_lock_i *lock) {
85
- return SPN_LOCK_BUILTIN(lock, 0);
86
- }
87
-
88
- /** returns a lock's state (non 0 == Busy). */
89
- static inline __attribute__((unused)) int spn_is_locked(spn_lock_i *lock) {
90
- __asm__ volatile("" ::: "memory");
91
- return *lock;
92
- }
93
-
94
- /** Busy waits for the lock. */
95
- static inline __attribute__((unused)) void spn_lock(spn_lock_i *lock) {
96
- while (spn_trylock(lock)) {
97
- reschedule_thread();
98
- }
99
- }
100
-
101
- #if DEBUG_SPINLOCK
102
- /** Busy waits for a lock, reports contention. */
103
- #define spn_lock(lock) \
104
- while (spn_trylock(lock)) { \
105
- fprintf(stderr, "INFO: spinlock spin %s:%d\n", __FILE__, __LINE__); \
106
- reschedule_thread(); \
107
- }
108
- #include <stdio.h>
109
- #endif /* DEBUG */
110
-
111
- #endif /* H_SPNLOCK_H */