sidekick-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +52 -0
  6. data/VERSION +1 -0
  7. data/lib/ext/README +1 -0
  8. data/lib/ext/bunny-0.6.0/LICENSE +20 -0
  9. data/lib/ext/bunny-0.6.0/README.rdoc +66 -0
  10. data/lib/ext/bunny-0.6.0/Rakefile +24 -0
  11. data/lib/ext/bunny-0.6.0/bunny.gemspec +65 -0
  12. data/lib/ext/bunny-0.6.0/examples/simple_08.rb +30 -0
  13. data/lib/ext/bunny-0.6.0/examples/simple_09.rb +30 -0
  14. data/lib/ext/bunny-0.6.0/examples/simple_ack_08.rb +33 -0
  15. data/lib/ext/bunny-0.6.0/examples/simple_ack_09.rb +33 -0
  16. data/lib/ext/bunny-0.6.0/examples/simple_consumer_08.rb +53 -0
  17. data/lib/ext/bunny-0.6.0/examples/simple_consumer_09.rb +53 -0
  18. data/lib/ext/bunny-0.6.0/examples/simple_fanout_08.rb +39 -0
  19. data/lib/ext/bunny-0.6.0/examples/simple_fanout_09.rb +39 -0
  20. data/lib/ext/bunny-0.6.0/examples/simple_headers_08.rb +40 -0
  21. data/lib/ext/bunny-0.6.0/examples/simple_headers_09.rb +40 -0
  22. data/lib/ext/bunny-0.6.0/examples/simple_publisher_08.rb +27 -0
  23. data/lib/ext/bunny-0.6.0/examples/simple_publisher_09.rb +27 -0
  24. data/lib/ext/bunny-0.6.0/examples/simple_topic_08.rb +59 -0
  25. data/lib/ext/bunny-0.6.0/examples/simple_topic_09.rb +59 -0
  26. data/lib/ext/bunny-0.6.0/lib/bunny/channel08.rb +39 -0
  27. data/lib/ext/bunny-0.6.0/lib/bunny/channel09.rb +39 -0
  28. data/lib/ext/bunny-0.6.0/lib/bunny/client08.rb +494 -0
  29. data/lib/ext/bunny-0.6.0/lib/bunny/client09.rb +460 -0
  30. data/lib/ext/bunny-0.6.0/lib/bunny/exchange08.rb +175 -0
  31. data/lib/ext/bunny-0.6.0/lib/bunny/exchange09.rb +177 -0
  32. data/lib/ext/bunny-0.6.0/lib/bunny/queue08.rb +389 -0
  33. data/lib/ext/bunny-0.6.0/lib/bunny/queue09.rb +395 -0
  34. data/lib/ext/bunny-0.6.0/lib/bunny/subscription08.rb +85 -0
  35. data/lib/ext/bunny-0.6.0/lib/bunny/subscription09.rb +85 -0
  36. data/lib/ext/bunny-0.6.0/lib/bunny.rb +87 -0
  37. data/lib/ext/bunny-0.6.0/lib/qrack/channel.rb +18 -0
  38. data/lib/ext/bunny-0.6.0/lib/qrack/client.rb +204 -0
  39. data/lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol08.rb +132 -0
  40. data/lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb +133 -0
  41. data/lib/ext/bunny-0.6.0/lib/qrack/protocol/spec08.rb +823 -0
  42. data/lib/ext/bunny-0.6.0/lib/qrack/protocol/spec09.rb +521 -0
  43. data/lib/ext/bunny-0.6.0/lib/qrack/qrack08.rb +23 -0
  44. data/lib/ext/bunny-0.6.0/lib/qrack/qrack09.rb +23 -0
  45. data/lib/ext/bunny-0.6.0/lib/qrack/queue.rb +53 -0
  46. data/lib/ext/bunny-0.6.0/lib/qrack/subscription.rb +102 -0
  47. data/lib/ext/bunny-0.6.0/lib/qrack/transport/buffer08.rb +276 -0
  48. data/lib/ext/bunny-0.6.0/lib/qrack/transport/buffer09.rb +276 -0
  49. data/lib/ext/bunny-0.6.0/lib/qrack/transport/frame08.rb +112 -0
  50. data/lib/ext/bunny-0.6.0/lib/qrack/transport/frame09.rb +94 -0
  51. data/lib/ext/bunny-0.6.0/spec/spec_08/bunny_spec.rb +65 -0
  52. data/lib/ext/bunny-0.6.0/spec/spec_08/connection_spec.rb +12 -0
  53. data/lib/ext/bunny-0.6.0/spec/spec_08/exchange_spec.rb +162 -0
  54. data/lib/ext/bunny-0.6.0/spec/spec_08/queue_spec.rb +206 -0
  55. data/lib/ext/bunny-0.6.0/spec/spec_09/bunny_spec.rb +65 -0
  56. data/lib/ext/bunny-0.6.0/spec/spec_09/connection_spec.rb +12 -0
  57. data/lib/ext/bunny-0.6.0/spec/spec_09/exchange_spec.rb +162 -0
  58. data/lib/ext/bunny-0.6.0/spec/spec_09/queue_spec.rb +205 -0
  59. data/lib/ext/eventmachine-0.12.10/.gitignore +14 -0
  60. data/lib/ext/eventmachine-0.12.10/README +82 -0
  61. data/lib/ext/eventmachine-0.12.10/Rakefile +374 -0
  62. data/lib/ext/eventmachine-0.12.10/docs/COPYING +60 -0
  63. data/lib/ext/eventmachine-0.12.10/docs/ChangeLog +211 -0
  64. data/lib/ext/eventmachine-0.12.10/docs/DEFERRABLES +133 -0
  65. data/lib/ext/eventmachine-0.12.10/docs/EPOLL +141 -0
  66. data/lib/ext/eventmachine-0.12.10/docs/GNU +281 -0
  67. data/lib/ext/eventmachine-0.12.10/docs/INSTALL +13 -0
  68. data/lib/ext/eventmachine-0.12.10/docs/KEYBOARD +38 -0
  69. data/lib/ext/eventmachine-0.12.10/docs/LEGAL +25 -0
  70. data/lib/ext/eventmachine-0.12.10/docs/LIGHTWEIGHT_CONCURRENCY +70 -0
  71. data/lib/ext/eventmachine-0.12.10/docs/PURE_RUBY +75 -0
  72. data/lib/ext/eventmachine-0.12.10/docs/RELEASE_NOTES +94 -0
  73. data/lib/ext/eventmachine-0.12.10/docs/SMTP +2 -0
  74. data/lib/ext/eventmachine-0.12.10/docs/SPAWNED_PROCESSES +89 -0
  75. data/lib/ext/eventmachine-0.12.10/docs/TODO +8 -0
  76. data/lib/ext/eventmachine-0.12.10/eventmachine.gemspec +40 -0
  77. data/lib/ext/eventmachine-0.12.10/examples/ex_channel.rb +43 -0
  78. data/lib/ext/eventmachine-0.12.10/examples/ex_queue.rb +2 -0
  79. data/lib/ext/eventmachine-0.12.10/examples/helper.rb +2 -0
  80. data/lib/ext/eventmachine-0.12.10/ext/binder.cpp +125 -0
  81. data/lib/ext/eventmachine-0.12.10/ext/binder.h +46 -0
  82. data/lib/ext/eventmachine-0.12.10/ext/cmain.cpp +827 -0
  83. data/lib/ext/eventmachine-0.12.10/ext/cplusplus.cpp +202 -0
  84. data/lib/ext/eventmachine-0.12.10/ext/ed.cpp +1893 -0
  85. data/lib/ext/eventmachine-0.12.10/ext/ed.h +424 -0
  86. data/lib/ext/eventmachine-0.12.10/ext/em.cpp +2282 -0
  87. data/lib/ext/eventmachine-0.12.10/ext/em.h +232 -0
  88. data/lib/ext/eventmachine-0.12.10/ext/emwin.cpp +300 -0
  89. data/lib/ext/eventmachine-0.12.10/ext/emwin.h +94 -0
  90. data/lib/ext/eventmachine-0.12.10/ext/epoll.cpp +26 -0
  91. data/lib/ext/eventmachine-0.12.10/ext/epoll.h +25 -0
  92. data/lib/ext/eventmachine-0.12.10/ext/eventmachine.h +122 -0
  93. data/lib/ext/eventmachine-0.12.10/ext/eventmachine_cpp.h +96 -0
  94. data/lib/ext/eventmachine-0.12.10/ext/extconf.rb +148 -0
  95. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/extconf.rb +83 -0
  96. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.cpp +214 -0
  97. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.h +59 -0
  98. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/rubymain.cpp +127 -0
  99. data/lib/ext/eventmachine-0.12.10/ext/files.cpp +94 -0
  100. data/lib/ext/eventmachine-0.12.10/ext/files.h +65 -0
  101. data/lib/ext/eventmachine-0.12.10/ext/kb.cpp +81 -0
  102. data/lib/ext/eventmachine-0.12.10/ext/page.cpp +107 -0
  103. data/lib/ext/eventmachine-0.12.10/ext/page.h +51 -0
  104. data/lib/ext/eventmachine-0.12.10/ext/pipe.cpp +349 -0
  105. data/lib/ext/eventmachine-0.12.10/ext/project.h +151 -0
  106. data/lib/ext/eventmachine-0.12.10/ext/rubymain.cpp +1166 -0
  107. data/lib/ext/eventmachine-0.12.10/ext/sigs.cpp +89 -0
  108. data/lib/ext/eventmachine-0.12.10/ext/sigs.h +32 -0
  109. data/lib/ext/eventmachine-0.12.10/ext/ssl.cpp +460 -0
  110. data/lib/ext/eventmachine-0.12.10/ext/ssl.h +94 -0
  111. data/lib/ext/eventmachine-0.12.10/java/.classpath +8 -0
  112. data/lib/ext/eventmachine-0.12.10/java/.project +17 -0
  113. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactor.java +570 -0
  114. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  115. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableChannel.java +69 -0
  116. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -0
  117. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -0
  118. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Application.java +194 -0
  119. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Connection.java +74 -0
  120. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/ConnectionFactory.java +37 -0
  121. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +46 -0
  122. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/PeriodicTimer.java +38 -0
  123. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Timer.java +54 -0
  124. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -0
  125. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -0
  126. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  127. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  128. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestServers.java +75 -0
  129. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -0
  130. data/lib/ext/eventmachine-0.12.10/lib/em/buftok.rb +138 -0
  131. data/lib/ext/eventmachine-0.12.10/lib/em/callback.rb +26 -0
  132. data/lib/ext/eventmachine-0.12.10/lib/em/channel.rb +57 -0
  133. data/lib/ext/eventmachine-0.12.10/lib/em/connection.rb +564 -0
  134. data/lib/ext/eventmachine-0.12.10/lib/em/deferrable.rb +192 -0
  135. data/lib/ext/eventmachine-0.12.10/lib/em/file_watch.rb +54 -0
  136. data/lib/ext/eventmachine-0.12.10/lib/em/future.rb +61 -0
  137. data/lib/ext/eventmachine-0.12.10/lib/em/messages.rb +66 -0
  138. data/lib/ext/eventmachine-0.12.10/lib/em/process_watch.rb +44 -0
  139. data/lib/ext/eventmachine-0.12.10/lib/em/processes.rb +119 -0
  140. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/header_and_content.rb +138 -0
  141. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient.rb +263 -0
  142. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient2.rb +590 -0
  143. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/line_and_text.rb +125 -0
  144. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/linetext2.rb +161 -0
  145. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/memcache.rb +323 -0
  146. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/object_protocol.rb +45 -0
  147. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/postgres3.rb +247 -0
  148. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/saslauth.rb +175 -0
  149. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpclient.rb +357 -0
  150. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpserver.rb +547 -0
  151. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/socks4.rb +66 -0
  152. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/stomp.rb +200 -0
  153. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/tcptest.rb +53 -0
  154. data/lib/ext/eventmachine-0.12.10/lib/em/protocols.rb +36 -0
  155. data/lib/ext/eventmachine-0.12.10/lib/em/queue.rb +61 -0
  156. data/lib/ext/eventmachine-0.12.10/lib/em/spawnable.rb +85 -0
  157. data/lib/ext/eventmachine-0.12.10/lib/em/streamer.rb +130 -0
  158. data/lib/ext/eventmachine-0.12.10/lib/em/timers.rb +56 -0
  159. data/lib/ext/eventmachine-0.12.10/lib/em/version.rb +3 -0
  160. data/lib/ext/eventmachine-0.12.10/lib/eventmachine.rb +1592 -0
  161. data/lib/ext/eventmachine-0.12.10/lib/evma/callback.rb +32 -0
  162. data/lib/ext/eventmachine-0.12.10/lib/evma/container.rb +75 -0
  163. data/lib/ext/eventmachine-0.12.10/lib/evma/factory.rb +77 -0
  164. data/lib/ext/eventmachine-0.12.10/lib/evma/protocol.rb +87 -0
  165. data/lib/ext/eventmachine-0.12.10/lib/evma/reactor.rb +48 -0
  166. data/lib/ext/eventmachine-0.12.10/lib/evma.rb +32 -0
  167. data/lib/ext/eventmachine-0.12.10/lib/jeventmachine.rb +257 -0
  168. data/lib/ext/eventmachine-0.12.10/lib/pr_eventmachine.rb +1022 -0
  169. data/lib/ext/eventmachine-0.12.10/setup.rb +1585 -0
  170. data/lib/ext/eventmachine-0.12.10/tasks/cpp.rake_example +77 -0
  171. data/lib/ext/eventmachine-0.12.10/tests/client.crt +31 -0
  172. data/lib/ext/eventmachine-0.12.10/tests/client.key +51 -0
  173. data/lib/ext/eventmachine-0.12.10/tests/test_attach.rb +126 -0
  174. data/lib/ext/eventmachine-0.12.10/tests/test_basic.rb +284 -0
  175. data/lib/ext/eventmachine-0.12.10/tests/test_channel.rb +63 -0
  176. data/lib/ext/eventmachine-0.12.10/tests/test_connection_count.rb +35 -0
  177. data/lib/ext/eventmachine-0.12.10/tests/test_defer.rb +47 -0
  178. data/lib/ext/eventmachine-0.12.10/tests/test_epoll.rb +160 -0
  179. data/lib/ext/eventmachine-0.12.10/tests/test_error_handler.rb +35 -0
  180. data/lib/ext/eventmachine-0.12.10/tests/test_errors.rb +82 -0
  181. data/lib/ext/eventmachine-0.12.10/tests/test_exc.rb +55 -0
  182. data/lib/ext/eventmachine-0.12.10/tests/test_file_watch.rb +49 -0
  183. data/lib/ext/eventmachine-0.12.10/tests/test_futures.rb +198 -0
  184. data/lib/ext/eventmachine-0.12.10/tests/test_get_sock_opt.rb +30 -0
  185. data/lib/ext/eventmachine-0.12.10/tests/test_handler_check.rb +37 -0
  186. data/lib/ext/eventmachine-0.12.10/tests/test_hc.rb +218 -0
  187. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb +218 -0
  188. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb +153 -0
  189. data/lib/ext/eventmachine-0.12.10/tests/test_inactivity_timeout.rb +50 -0
  190. data/lib/ext/eventmachine-0.12.10/tests/test_kb.rb +60 -0
  191. data/lib/ext/eventmachine-0.12.10/tests/test_ltp.rb +182 -0
  192. data/lib/ext/eventmachine-0.12.10/tests/test_ltp2.rb +317 -0
  193. data/lib/ext/eventmachine-0.12.10/tests/test_next_tick.rb +133 -0
  194. data/lib/ext/eventmachine-0.12.10/tests/test_object_protocol.rb +37 -0
  195. data/lib/ext/eventmachine-0.12.10/tests/test_pause.rb +70 -0
  196. data/lib/ext/eventmachine-0.12.10/tests/test_pending_connect_timeout.rb +48 -0
  197. data/lib/ext/eventmachine-0.12.10/tests/test_process_watch.rb +48 -0
  198. data/lib/ext/eventmachine-0.12.10/tests/test_processes.rb +128 -0
  199. data/lib/ext/eventmachine-0.12.10/tests/test_proxy_connection.rb +92 -0
  200. data/lib/ext/eventmachine-0.12.10/tests/test_pure.rb +125 -0
  201. data/lib/ext/eventmachine-0.12.10/tests/test_queue.rb +44 -0
  202. data/lib/ext/eventmachine-0.12.10/tests/test_running.rb +42 -0
  203. data/lib/ext/eventmachine-0.12.10/tests/test_sasl.rb +72 -0
  204. data/lib/ext/eventmachine-0.12.10/tests/test_send_file.rb +242 -0
  205. data/lib/ext/eventmachine-0.12.10/tests/test_servers.rb +76 -0
  206. data/lib/ext/eventmachine-0.12.10/tests/test_smtpclient.rb +83 -0
  207. data/lib/ext/eventmachine-0.12.10/tests/test_smtpserver.rb +85 -0
  208. data/lib/ext/eventmachine-0.12.10/tests/test_spawn.rb +322 -0
  209. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_args.rb +79 -0
  210. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_methods.rb +50 -0
  211. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_verify.rb +82 -0
  212. data/lib/ext/eventmachine-0.12.10/tests/test_timers.rb +162 -0
  213. data/lib/ext/eventmachine-0.12.10/tests/test_ud.rb +36 -0
  214. data/lib/ext/eventmachine-0.12.10/tests/testem.rb +31 -0
  215. data/lib/ext/eventmachine-0.12.10/web/whatis +7 -0
  216. data/lib/ext/misc/README +1 -0
  217. data/lib/ext/misc/indifferent_access.rb +131 -0
  218. data/lib/ext/uuidtools-2.1.1/CHANGELOG +56 -0
  219. data/lib/ext/uuidtools-2.1.1/LICENSE +20 -0
  220. data/lib/ext/uuidtools-2.1.1/README +13 -0
  221. data/lib/ext/uuidtools-2.1.1/Rakefile +48 -0
  222. data/lib/ext/uuidtools-2.1.1/lib/compat/securerandom.rb +202 -0
  223. data/lib/ext/uuidtools-2.1.1/lib/uuidtools/version.rb +35 -0
  224. data/lib/ext/uuidtools-2.1.1/lib/uuidtools.rb +618 -0
  225. data/lib/ext/uuidtools-2.1.1/spec/spec.opts +1 -0
  226. data/lib/ext/uuidtools-2.1.1/spec/spec_helper.rb +7 -0
  227. data/lib/ext/uuidtools-2.1.1/spec/uuidtools/mac_address_spec.rb +15 -0
  228. data/lib/ext/uuidtools-2.1.1/spec/uuidtools/utility_spec.rb +21 -0
  229. data/lib/ext/uuidtools-2.1.1/spec/uuidtools/uuid_creation_spec.rb +121 -0
  230. data/lib/ext/uuidtools-2.1.1/spec/uuidtools/uuid_parsing_spec.rb +127 -0
  231. data/lib/ext/uuidtools-2.1.1/tasks/benchmark.rake +38 -0
  232. data/lib/ext/uuidtools-2.1.1/tasks/clobber.rake +2 -0
  233. data/lib/ext/uuidtools-2.1.1/tasks/gem.rake +68 -0
  234. data/lib/ext/uuidtools-2.1.1/tasks/git.rake +40 -0
  235. data/lib/ext/uuidtools-2.1.1/tasks/metrics.rake +22 -0
  236. data/lib/ext/uuidtools-2.1.1/tasks/rdoc.rake +29 -0
  237. data/lib/ext/uuidtools-2.1.1/tasks/rubyforge.rake +89 -0
  238. data/lib/ext/uuidtools-2.1.1/tasks/spec.rake +64 -0
  239. data/lib/ext/uuidtools-2.1.1/website/index.html +95 -0
  240. data/lib/sidekick/client/sidekick_client.rb +46 -0
  241. data/lib/sidekick/shared/sidekick_logger.rb +14 -0
  242. data/lib/sidekick/shared/sidekick_queue_publisher.rb +91 -0
  243. data/lib/sidekick-client.rb +7 -0
  244. data/sidekick-client.gemspec +289 -0
  245. data/test/helper.rb +10 -0
  246. data/test/test_sidekick-client.rb +7 -0
  247. metadata +311 -0
@@ -0,0 +1,94 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: files.cpp
6
+ Date: 26Aug06
7
+
8
+ Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: blackhedd
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of either: 1) the GNU General Public License
13
+ as published by the Free Software Foundation; either version 2 of the
14
+ License, or (at your option) any later version; or 2) Ruby's License.
15
+
16
+ See the file COPYING for complete licensing information.
17
+
18
+ *****************************************************************************/
19
+
20
+ #include "project.h"
21
+
22
+
23
+ /******************************************
24
+ FileStreamDescriptor::FileStreamDescriptor
25
+ ******************************************/
26
+
27
+ FileStreamDescriptor::FileStreamDescriptor (int fd, EventMachine_t *em):
28
+ EventableDescriptor (fd, em),
29
+ OutboundDataSize (0)
30
+ {
31
+ cerr << "#####";
32
+ }
33
+
34
+
35
+ /*******************************************
36
+ FileStreamDescriptor::~FileStreamDescriptor
37
+ *******************************************/
38
+
39
+ FileStreamDescriptor::~FileStreamDescriptor()
40
+ {
41
+ // Run down any stranded outbound data.
42
+ for (size_t i=0; i < OutboundPages.size(); i++)
43
+ OutboundPages[i].Free();
44
+ }
45
+
46
+
47
+ /**************************
48
+ FileStreamDescriptor::Read
49
+ **************************/
50
+
51
+ void FileStreamDescriptor::Read()
52
+ {
53
+ }
54
+
55
+ /***************************
56
+ FileStreamDescriptor::Write
57
+ ***************************/
58
+
59
+ void FileStreamDescriptor::Write()
60
+ {
61
+ }
62
+
63
+
64
+ /*******************************
65
+ FileStreamDescriptor::Heartbeat
66
+ *******************************/
67
+
68
+ void FileStreamDescriptor::Heartbeat()
69
+ {
70
+ }
71
+
72
+
73
+ /***********************************
74
+ FileStreamDescriptor::SelectForRead
75
+ ***********************************/
76
+
77
+ bool FileStreamDescriptor::SelectForRead()
78
+ {
79
+ cerr << "R?";
80
+ return false;
81
+ }
82
+
83
+
84
+ /************************************
85
+ FileStreamDescriptor::SelectForWrite
86
+ ************************************/
87
+
88
+ bool FileStreamDescriptor::SelectForWrite()
89
+ {
90
+ cerr << "W?";
91
+ return false;
92
+ }
93
+
94
+
@@ -0,0 +1,65 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: files.h
6
+ Date: 26Aug06
7
+
8
+ Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: blackhedd
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of either: 1) the GNU General Public License
13
+ as published by the Free Software Foundation; either version 2 of the
14
+ License, or (at your option) any later version; or 2) Ruby's License.
15
+
16
+ See the file COPYING for complete licensing information.
17
+
18
+ *****************************************************************************/
19
+
20
+
21
+ #ifndef __FileStreamDescriptor__H_
22
+ #define __FileStreamDescriptor__H_
23
+
24
+
25
+
26
+ /**************************
27
+ class FileStreamDescriptor
28
+ **************************/
29
+
30
+ class FileStreamDescriptor: public EventableDescriptor
31
+ {
32
+ public:
33
+ FileStreamDescriptor (int, EventMachine_t*);
34
+ virtual ~FileStreamDescriptor();
35
+
36
+ virtual void Read();
37
+ virtual void Write();
38
+ virtual void Heartbeat();
39
+
40
+ virtual bool SelectForRead();
41
+ virtual bool SelectForWrite();
42
+
43
+ // Do we have any data to write? This is used by ShouldDelete.
44
+ virtual int GetOutboundDataSize() {return OutboundDataSize;}
45
+
46
+ protected:
47
+ struct OutboundPage {
48
+ OutboundPage (const char *b, int l, int o=0): Buffer(b), Length(l), Offset(o) {}
49
+ void Free() {if (Buffer) free ((char*)Buffer); }
50
+ const char *Buffer;
51
+ int Length;
52
+ int Offset;
53
+ };
54
+
55
+ protected:
56
+ deque<OutboundPage> OutboundPages;
57
+ int OutboundDataSize;
58
+
59
+ private:
60
+
61
+ };
62
+
63
+
64
+ #endif // __FileStreamDescriptor__H_
65
+
@@ -0,0 +1,81 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: kb.cpp
6
+ Date: 24Aug07
7
+
8
+ Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: blackhedd
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of either: 1) the GNU General Public License
13
+ as published by the Free Software Foundation; either version 2 of the
14
+ License, or (at your option) any later version; or 2) Ruby's License.
15
+
16
+ See the file COPYING for complete licensing information.
17
+
18
+ *****************************************************************************/
19
+
20
+ #include "project.h"
21
+
22
+
23
+ /**************************************
24
+ KeyboardDescriptor::KeyboardDescriptor
25
+ **************************************/
26
+
27
+ KeyboardDescriptor::KeyboardDescriptor (EventMachine_t *parent_em):
28
+ EventableDescriptor (0, parent_em),
29
+ bReadAttemptedAfterClose (false),
30
+ LastIo (gCurrentLoopTime),
31
+ InactivityTimeout (0)
32
+ {
33
+ #ifdef HAVE_EPOLL
34
+ EpollEvent.events = EPOLLIN;
35
+ #endif
36
+ #ifdef HAVE_KQUEUE
37
+ MyEventMachine->ArmKqueueReader (this);
38
+ #endif
39
+ }
40
+
41
+
42
+ /***************************************
43
+ KeyboardDescriptor::~KeyboardDescriptor
44
+ ***************************************/
45
+
46
+ KeyboardDescriptor::~KeyboardDescriptor()
47
+ {
48
+ }
49
+
50
+
51
+ /*************************
52
+ KeyboardDescriptor::Write
53
+ *************************/
54
+
55
+ void KeyboardDescriptor::Write()
56
+ {
57
+ // Why are we here?
58
+ throw std::runtime_error ("bad code path in keyboard handler");
59
+ }
60
+
61
+
62
+ /*****************************
63
+ KeyboardDescriptor::Heartbeat
64
+ *****************************/
65
+
66
+ void KeyboardDescriptor::Heartbeat()
67
+ {
68
+ // no-op
69
+ }
70
+
71
+
72
+ /************************
73
+ KeyboardDescriptor::Read
74
+ ************************/
75
+
76
+ void KeyboardDescriptor::Read()
77
+ {
78
+ char c;
79
+ read (GetSocket(), &c, 1);
80
+ _GenericInboundDispatch(&c, 1);
81
+ }
@@ -0,0 +1,107 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: page.cpp
6
+ Date: 30Apr06
7
+
8
+ Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: blackhedd
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of either: 1) the GNU General Public License
13
+ as published by the Free Software Foundation; either version 2 of the
14
+ License, or (at your option) any later version; or 2) Ruby's License.
15
+
16
+ See the file COPYING for complete licensing information.
17
+
18
+ *****************************************************************************/
19
+
20
+
21
+ #include "project.h"
22
+
23
+
24
+ /******************
25
+ PageList::PageList
26
+ ******************/
27
+
28
+ PageList::PageList()
29
+ {
30
+ }
31
+
32
+
33
+ /*******************
34
+ PageList::~PageList
35
+ *******************/
36
+
37
+ PageList::~PageList()
38
+ {
39
+ while (HasPages())
40
+ PopFront();
41
+ }
42
+
43
+
44
+ /***************
45
+ PageList::Front
46
+ ***************/
47
+
48
+ void PageList::Front (const char **page, int *length)
49
+ {
50
+ assert (page && length);
51
+
52
+ if (HasPages()) {
53
+ Page p = Pages.front();
54
+ *page = p.Buffer;
55
+ *length = p.Size;
56
+ }
57
+ else {
58
+ *page = NULL;
59
+ *length = 0;
60
+ }
61
+ }
62
+
63
+
64
+ /******************
65
+ PageList::PopFront
66
+ ******************/
67
+
68
+ void PageList::PopFront()
69
+ {
70
+ if (HasPages()) {
71
+ Page p = Pages.front();
72
+ Pages.pop_front();
73
+ if (p.Buffer)
74
+ free ((void*)p.Buffer);
75
+ }
76
+ }
77
+
78
+
79
+ /******************
80
+ PageList::HasPages
81
+ ******************/
82
+
83
+ bool PageList::HasPages()
84
+ {
85
+ return (Pages.size() > 0) ? true : false;
86
+ }
87
+
88
+
89
+ /**************
90
+ PageList::Push
91
+ **************/
92
+
93
+ void PageList::Push (const char *buf, int size)
94
+ {
95
+ if (buf && (size > 0)) {
96
+ char *copy = (char*) malloc (size);
97
+ if (!copy)
98
+ throw runtime_error ("no memory in pagelist");
99
+ memcpy (copy, buf, size);
100
+ Pages.push_back (Page (copy, size));
101
+ }
102
+ }
103
+
104
+
105
+
106
+
107
+
@@ -0,0 +1,51 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: page.h
6
+ Date: 30Apr06
7
+
8
+ Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: blackhedd
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of either: 1) the GNU General Public License
13
+ as published by the Free Software Foundation; either version 2 of the
14
+ License, or (at your option) any later version; or 2) Ruby's License.
15
+
16
+ See the file COPYING for complete licensing information.
17
+
18
+ *****************************************************************************/
19
+
20
+
21
+ #ifndef __PageManager__H_
22
+ #define __PageManager__H_
23
+
24
+
25
+ /**************
26
+ class PageList
27
+ **************/
28
+
29
+ class PageList
30
+ {
31
+ struct Page {
32
+ Page (const char *b, size_t s): Buffer(b), Size(s) {}
33
+ const char *Buffer;
34
+ size_t Size;
35
+ };
36
+
37
+ public:
38
+ PageList();
39
+ virtual ~PageList();
40
+
41
+ void Push (const char*, int);
42
+ bool HasPages();
43
+ void Front (const char**, int*);
44
+ void PopFront();
45
+
46
+ private:
47
+ deque<Page> Pages;
48
+ };
49
+
50
+
51
+ #endif // __PageManager__H_
@@ -0,0 +1,349 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: pipe.cpp
6
+ Date: 30May07
7
+
8
+ Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: blackhedd
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of either: 1) the GNU General Public License
13
+ as published by the Free Software Foundation; either version 2 of the
14
+ License, or (at your option) any later version; or 2) Ruby's License.
15
+
16
+ See the file COPYING for complete licensing information.
17
+
18
+ *****************************************************************************/
19
+
20
+ #include "project.h"
21
+
22
+
23
+ #ifdef OS_UNIX
24
+ // THIS ENTIRE FILE IS ONLY COMPILED ON UNIX-LIKE SYSTEMS.
25
+
26
+ /******************************
27
+ PipeDescriptor::PipeDescriptor
28
+ ******************************/
29
+
30
+ PipeDescriptor::PipeDescriptor (int fd, pid_t subpid, EventMachine_t *parent_em):
31
+ EventableDescriptor (fd, parent_em),
32
+ bReadAttemptedAfterClose (false),
33
+ LastIo (gCurrentLoopTime),
34
+ InactivityTimeout (0),
35
+ OutboundDataSize (0),
36
+ SubprocessPid (subpid)
37
+ {
38
+ #ifdef HAVE_EPOLL
39
+ EpollEvent.events = EPOLLIN;
40
+ #endif
41
+ #ifdef HAVE_KQUEUE
42
+ MyEventMachine->ArmKqueueReader (this);
43
+ #endif
44
+ }
45
+
46
+
47
+ /*******************************
48
+ PipeDescriptor::~PipeDescriptor
49
+ *******************************/
50
+
51
+ PipeDescriptor::~PipeDescriptor()
52
+ {
53
+ // Run down any stranded outbound data.
54
+ for (size_t i=0; i < OutboundPages.size(); i++)
55
+ OutboundPages[i].Free();
56
+
57
+ /* As a virtual destructor, we come here before the base-class
58
+ * destructor that closes our file-descriptor.
59
+ * We have to make sure the subprocess goes down (if it's not
60
+ * already down) and we have to reap the zombie.
61
+ *
62
+ * This implementation is PROVISIONAL and will surely be improved.
63
+ * The intention here is that we never block, hence the highly
64
+ * undesirable sleeps. But if we can't reap the subprocess even
65
+ * after sending it SIGKILL, then something is wrong and we
66
+ * throw a fatal exception, which is also not something we should
67
+ * be doing.
68
+ *
69
+ * Eventually the right thing to do will be to have the reactor
70
+ * core respond to SIGCHLD by chaining a handler on top of the
71
+ * one Ruby may have installed, and dealing with a list of dead
72
+ * children that are pending cleanup.
73
+ *
74
+ * Since we want to have a signal processor integrated into the
75
+ * client-visible API, let's wait until that is done before cleaning
76
+ * this up.
77
+ *
78
+ * Added a very ugly hack to support passing the subprocess's exit
79
+ * status to the user. It only makes logical sense for user code to access
80
+ * the subprocess exit status in the unbind callback. But unbind is called
81
+ * back during the EventableDescriptor destructor. So by that time there's
82
+ * no way to call back this object through an object binding, because it's
83
+ * already been cleaned up. We might have added a parameter to the unbind
84
+ * callback, but that would probably break a huge amount of existing code.
85
+ * So the hack-solution is to define an instance variable in the EventMachine
86
+ * object and stick the exit status in there, where it can easily be accessed
87
+ * with an accessor visible to user code.
88
+ * User code should ONLY access the exit status from within the unbind callback.
89
+ * Otherwise there's no guarantee it'll be valid.
90
+ * This hack won't make it impossible to run multiple EventMachines in a single
91
+ * process, but it will make it impossible to reliably nest unbind calls
92
+ * within other unbind calls. (Not sure if that's even possible.)
93
+ */
94
+
95
+ assert (MyEventMachine);
96
+
97
+ /* Another hack to make the SubprocessPid available to get_subprocess_status */
98
+ MyEventMachine->SubprocessPid = SubprocessPid;
99
+
100
+ /* 01Mar09: Updated to use a small nanosleep in a loop. When nanosleep is interrupted by SIGCHLD,
101
+ * it resumes the system call after processing the signal (resulting in unnecessary latency).
102
+ * Calling nanosleep in a loop avoids this problem.
103
+ */
104
+ struct timespec req = {0, 50000000}; // 0.05s
105
+ int n;
106
+
107
+ // wait 0.25s for the process to die
108
+ for (n=0; n<5; n++) {
109
+ if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) != 0) return;
110
+ nanosleep (&req, NULL);
111
+ }
112
+
113
+ // send SIGTERM and wait another 0.5s
114
+ kill (SubprocessPid, SIGTERM);
115
+ for (n=0; n<10; n++) {
116
+ nanosleep (&req, NULL);
117
+ if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) != 0) return;
118
+ }
119
+
120
+ // send SIGKILL and wait another 1s
121
+ kill (SubprocessPid, SIGKILL);
122
+ for (n=0; n<20; n++) {
123
+ nanosleep (&req, NULL);
124
+ if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) != 0) return;
125
+ }
126
+
127
+ // still not dead, give up!
128
+ throw std::runtime_error ("unable to reap subprocess");
129
+ }
130
+
131
+
132
+
133
+ /********************
134
+ PipeDescriptor::Read
135
+ ********************/
136
+
137
+ void PipeDescriptor::Read()
138
+ {
139
+ int sd = GetSocket();
140
+ if (sd == INVALID_SOCKET) {
141
+ assert (!bReadAttemptedAfterClose);
142
+ bReadAttemptedAfterClose = true;
143
+ return;
144
+ }
145
+
146
+ LastIo = gCurrentLoopTime;
147
+
148
+ int total_bytes_read = 0;
149
+ char readbuffer [16 * 1024];
150
+
151
+ for (int i=0; i < 10; i++) {
152
+ // Don't read just one buffer and then move on. This is faster
153
+ // if there is a lot of incoming.
154
+ // But don't read indefinitely. Give other sockets a chance to run.
155
+ // NOTICE, we're reading one less than the buffer size.
156
+ // That's so we can put a guard byte at the end of what we send
157
+ // to user code.
158
+ // Use read instead of recv, which on Linux gives a "socket operation
159
+ // on nonsocket" error.
160
+
161
+
162
+ int r = read (sd, readbuffer, sizeof(readbuffer) - 1);
163
+ //cerr << "<R:" << r << ">";
164
+
165
+ if (r > 0) {
166
+ total_bytes_read += r;
167
+
168
+ // Add a null-terminator at the the end of the buffer
169
+ // that we will send to the callback.
170
+ // DO NOT EVER CHANGE THIS. We want to explicitly allow users
171
+ // to be able to depend on this behavior, so they will have
172
+ // the option to do some things faster. Additionally it's
173
+ // a security guard against buffer overflows.
174
+ readbuffer [r] = 0;
175
+ _GenericInboundDispatch(readbuffer, r);
176
+ }
177
+ else if (r == 0) {
178
+ break;
179
+ }
180
+ else {
181
+ // Basically a would-block, meaning we've read everything there is to read.
182
+ break;
183
+ }
184
+
185
+ }
186
+
187
+
188
+ if (total_bytes_read == 0) {
189
+ // If we read no data on a socket that selected readable,
190
+ // it generally means the other end closed the connection gracefully.
191
+ ScheduleClose (false);
192
+ //bCloseNow = true;
193
+ }
194
+
195
+ }
196
+
197
+ /*********************
198
+ PipeDescriptor::Write
199
+ *********************/
200
+
201
+ void PipeDescriptor::Write()
202
+ {
203
+ int sd = GetSocket();
204
+ assert (sd != INVALID_SOCKET);
205
+
206
+ LastIo = gCurrentLoopTime;
207
+ char output_buffer [16 * 1024];
208
+ size_t nbytes = 0;
209
+
210
+ while ((OutboundPages.size() > 0) && (nbytes < sizeof(output_buffer))) {
211
+ OutboundPage *op = &(OutboundPages[0]);
212
+ if ((nbytes + op->Length - op->Offset) < sizeof (output_buffer)) {
213
+ memcpy (output_buffer + nbytes, op->Buffer + op->Offset, op->Length - op->Offset);
214
+ nbytes += (op->Length - op->Offset);
215
+ op->Free();
216
+ OutboundPages.pop_front();
217
+ }
218
+ else {
219
+ int len = sizeof(output_buffer) - nbytes;
220
+ memcpy (output_buffer + nbytes, op->Buffer + op->Offset, len);
221
+ op->Offset += len;
222
+ nbytes += len;
223
+ }
224
+ }
225
+
226
+ // We should never have gotten here if there were no data to write,
227
+ // so assert that as a sanity check.
228
+ // Don't bother to make sure nbytes is less than output_buffer because
229
+ // if it were we probably would have crashed already.
230
+ assert (nbytes > 0);
231
+
232
+ assert (GetSocket() != INVALID_SOCKET);
233
+ int bytes_written = write (GetSocket(), output_buffer, nbytes);
234
+
235
+ if (bytes_written > 0) {
236
+ OutboundDataSize -= bytes_written;
237
+ if ((size_t)bytes_written < nbytes) {
238
+ int len = nbytes - bytes_written;
239
+ char *buffer = (char*) malloc (len + 1);
240
+ if (!buffer)
241
+ throw std::runtime_error ("bad alloc throwing back data");
242
+ memcpy (buffer, output_buffer + bytes_written, len);
243
+ buffer [len] = 0;
244
+ OutboundPages.push_front (OutboundPage (buffer, len));
245
+ }
246
+ #ifdef HAVE_EPOLL
247
+ EpollEvent.events = (EPOLLIN | (SelectForWrite() ? EPOLLOUT : 0));
248
+ assert (MyEventMachine);
249
+ MyEventMachine->Modify (this);
250
+ #endif
251
+ }
252
+ else {
253
+ #ifdef OS_UNIX
254
+ if ((errno != EINPROGRESS) && (errno != EWOULDBLOCK) && (errno != EINTR))
255
+ #endif
256
+ #ifdef OS_WIN32
257
+ if ((errno != WSAEINPROGRESS) && (errno != WSAEWOULDBLOCK))
258
+ #endif
259
+ Close();
260
+ }
261
+ }
262
+
263
+
264
+ /*************************
265
+ PipeDescriptor::Heartbeat
266
+ *************************/
267
+
268
+ void PipeDescriptor::Heartbeat()
269
+ {
270
+ // If an inactivity timeout is defined, then check for it.
271
+ if (InactivityTimeout && ((gCurrentLoopTime - LastIo) >= InactivityTimeout))
272
+ ScheduleClose (false);
273
+ //bCloseNow = true;
274
+ }
275
+
276
+
277
+ /*****************************
278
+ PipeDescriptor::SelectForRead
279
+ *****************************/
280
+
281
+ bool PipeDescriptor::SelectForRead()
282
+ {
283
+ /* Pipe descriptors, being local by definition, don't have
284
+ * a pending state, so this is simpler than for the
285
+ * ConnectionDescriptor object.
286
+ */
287
+ return true;
288
+ }
289
+
290
+ /******************************
291
+ PipeDescriptor::SelectForWrite
292
+ ******************************/
293
+
294
+ bool PipeDescriptor::SelectForWrite()
295
+ {
296
+ /* Pipe descriptors, being local by definition, don't have
297
+ * a pending state, so this is simpler than for the
298
+ * ConnectionDescriptor object.
299
+ */
300
+ return (GetOutboundDataSize() > 0);
301
+ }
302
+
303
+
304
+
305
+
306
+ /********************************
307
+ PipeDescriptor::SendOutboundData
308
+ ********************************/
309
+
310
+ int PipeDescriptor::SendOutboundData (const char *data, int length)
311
+ {
312
+ //if (bCloseNow || bCloseAfterWriting)
313
+ if (IsCloseScheduled())
314
+ return 0;
315
+
316
+ if (!data && (length > 0))
317
+ throw std::runtime_error ("bad outbound data");
318
+ char *buffer = (char *) malloc (length + 1);
319
+ if (!buffer)
320
+ throw std::runtime_error ("no allocation for outbound data");
321
+ memcpy (buffer, data, length);
322
+ buffer [length] = 0;
323
+ OutboundPages.push_back (OutboundPage (buffer, length));
324
+ OutboundDataSize += length;
325
+ #ifdef HAVE_EPOLL
326
+ EpollEvent.events = (EPOLLIN | EPOLLOUT);
327
+ assert (MyEventMachine);
328
+ MyEventMachine->Modify (this);
329
+ #endif
330
+ return length;
331
+ }
332
+
333
+ /********************************
334
+ PipeDescriptor::GetSubprocessPid
335
+ ********************************/
336
+
337
+ bool PipeDescriptor::GetSubprocessPid (pid_t *pid)
338
+ {
339
+ bool ok = false;
340
+ if (pid && (SubprocessPid > 0)) {
341
+ *pid = SubprocessPid;
342
+ ok = true;
343
+ }
344
+ return ok;
345
+ }
346
+
347
+
348
+ #endif // OS_UNIX
349
+