sidekick-client 0.2.1 → 0.2.2

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.
Files changed (162) hide show
  1. data/VERSION +1 -1
  2. data/lib/sidekick/client/sidekick_client.rb +0 -3
  3. data/lib/sidekick/shared/sidekick_queue_publisher.rb +1 -1
  4. data/sidekick-client.gemspec +1 -158
  5. metadata +1 -158
  6. data/lib/ext/eventmachine-0.12.10/.gitignore +0 -14
  7. data/lib/ext/eventmachine-0.12.10/README +0 -82
  8. data/lib/ext/eventmachine-0.12.10/Rakefile +0 -374
  9. data/lib/ext/eventmachine-0.12.10/docs/COPYING +0 -60
  10. data/lib/ext/eventmachine-0.12.10/docs/ChangeLog +0 -211
  11. data/lib/ext/eventmachine-0.12.10/docs/DEFERRABLES +0 -133
  12. data/lib/ext/eventmachine-0.12.10/docs/EPOLL +0 -141
  13. data/lib/ext/eventmachine-0.12.10/docs/GNU +0 -281
  14. data/lib/ext/eventmachine-0.12.10/docs/INSTALL +0 -13
  15. data/lib/ext/eventmachine-0.12.10/docs/KEYBOARD +0 -38
  16. data/lib/ext/eventmachine-0.12.10/docs/LEGAL +0 -25
  17. data/lib/ext/eventmachine-0.12.10/docs/LIGHTWEIGHT_CONCURRENCY +0 -70
  18. data/lib/ext/eventmachine-0.12.10/docs/PURE_RUBY +0 -75
  19. data/lib/ext/eventmachine-0.12.10/docs/RELEASE_NOTES +0 -94
  20. data/lib/ext/eventmachine-0.12.10/docs/SMTP +0 -2
  21. data/lib/ext/eventmachine-0.12.10/docs/SPAWNED_PROCESSES +0 -89
  22. data/lib/ext/eventmachine-0.12.10/docs/TODO +0 -8
  23. data/lib/ext/eventmachine-0.12.10/eventmachine.gemspec +0 -40
  24. data/lib/ext/eventmachine-0.12.10/examples/ex_channel.rb +0 -43
  25. data/lib/ext/eventmachine-0.12.10/examples/ex_queue.rb +0 -2
  26. data/lib/ext/eventmachine-0.12.10/examples/helper.rb +0 -2
  27. data/lib/ext/eventmachine-0.12.10/ext/binder.cpp +0 -125
  28. data/lib/ext/eventmachine-0.12.10/ext/binder.h +0 -46
  29. data/lib/ext/eventmachine-0.12.10/ext/cmain.cpp +0 -827
  30. data/lib/ext/eventmachine-0.12.10/ext/cplusplus.cpp +0 -202
  31. data/lib/ext/eventmachine-0.12.10/ext/ed.cpp +0 -1893
  32. data/lib/ext/eventmachine-0.12.10/ext/ed.h +0 -424
  33. data/lib/ext/eventmachine-0.12.10/ext/em.cpp +0 -2282
  34. data/lib/ext/eventmachine-0.12.10/ext/em.h +0 -232
  35. data/lib/ext/eventmachine-0.12.10/ext/emwin.cpp +0 -300
  36. data/lib/ext/eventmachine-0.12.10/ext/emwin.h +0 -94
  37. data/lib/ext/eventmachine-0.12.10/ext/epoll.cpp +0 -26
  38. data/lib/ext/eventmachine-0.12.10/ext/epoll.h +0 -25
  39. data/lib/ext/eventmachine-0.12.10/ext/eventmachine.h +0 -122
  40. data/lib/ext/eventmachine-0.12.10/ext/eventmachine_cpp.h +0 -96
  41. data/lib/ext/eventmachine-0.12.10/ext/extconf.rb +0 -148
  42. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/extconf.rb +0 -83
  43. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.cpp +0 -214
  44. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.h +0 -59
  45. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/rubymain.cpp +0 -127
  46. data/lib/ext/eventmachine-0.12.10/ext/files.cpp +0 -94
  47. data/lib/ext/eventmachine-0.12.10/ext/files.h +0 -65
  48. data/lib/ext/eventmachine-0.12.10/ext/kb.cpp +0 -81
  49. data/lib/ext/eventmachine-0.12.10/ext/page.cpp +0 -107
  50. data/lib/ext/eventmachine-0.12.10/ext/page.h +0 -51
  51. data/lib/ext/eventmachine-0.12.10/ext/pipe.cpp +0 -349
  52. data/lib/ext/eventmachine-0.12.10/ext/project.h +0 -151
  53. data/lib/ext/eventmachine-0.12.10/ext/rubymain.cpp +0 -1166
  54. data/lib/ext/eventmachine-0.12.10/ext/sigs.cpp +0 -89
  55. data/lib/ext/eventmachine-0.12.10/ext/sigs.h +0 -32
  56. data/lib/ext/eventmachine-0.12.10/ext/ssl.cpp +0 -460
  57. data/lib/ext/eventmachine-0.12.10/ext/ssl.h +0 -94
  58. data/lib/ext/eventmachine-0.12.10/java/.classpath +0 -8
  59. data/lib/ext/eventmachine-0.12.10/java/.project +0 -17
  60. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactor.java +0 -570
  61. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactorException.java +0 -40
  62. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableChannel.java +0 -69
  63. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableDatagramChannel.java +0 -189
  64. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableSocketChannel.java +0 -364
  65. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Application.java +0 -194
  66. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Connection.java +0 -74
  67. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
  68. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
  69. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
  70. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Timer.java +0 -54
  71. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
  72. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
  73. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
  74. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
  75. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
  76. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
  77. data/lib/ext/eventmachine-0.12.10/lib/em/buftok.rb +0 -138
  78. data/lib/ext/eventmachine-0.12.10/lib/em/callback.rb +0 -26
  79. data/lib/ext/eventmachine-0.12.10/lib/em/channel.rb +0 -57
  80. data/lib/ext/eventmachine-0.12.10/lib/em/connection.rb +0 -564
  81. data/lib/ext/eventmachine-0.12.10/lib/em/deferrable.rb +0 -192
  82. data/lib/ext/eventmachine-0.12.10/lib/em/file_watch.rb +0 -54
  83. data/lib/ext/eventmachine-0.12.10/lib/em/future.rb +0 -61
  84. data/lib/ext/eventmachine-0.12.10/lib/em/messages.rb +0 -66
  85. data/lib/ext/eventmachine-0.12.10/lib/em/process_watch.rb +0 -44
  86. data/lib/ext/eventmachine-0.12.10/lib/em/processes.rb +0 -119
  87. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/header_and_content.rb +0 -138
  88. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient.rb +0 -263
  89. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient2.rb +0 -590
  90. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/line_and_text.rb +0 -125
  91. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/linetext2.rb +0 -161
  92. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/memcache.rb +0 -323
  93. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/object_protocol.rb +0 -45
  94. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/postgres3.rb +0 -247
  95. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/saslauth.rb +0 -175
  96. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpclient.rb +0 -357
  97. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpserver.rb +0 -547
  98. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/socks4.rb +0 -66
  99. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/stomp.rb +0 -200
  100. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/tcptest.rb +0 -53
  101. data/lib/ext/eventmachine-0.12.10/lib/em/protocols.rb +0 -36
  102. data/lib/ext/eventmachine-0.12.10/lib/em/queue.rb +0 -61
  103. data/lib/ext/eventmachine-0.12.10/lib/em/spawnable.rb +0 -85
  104. data/lib/ext/eventmachine-0.12.10/lib/em/streamer.rb +0 -130
  105. data/lib/ext/eventmachine-0.12.10/lib/em/timers.rb +0 -56
  106. data/lib/ext/eventmachine-0.12.10/lib/em/version.rb +0 -3
  107. data/lib/ext/eventmachine-0.12.10/lib/eventmachine.rb +0 -1592
  108. data/lib/ext/eventmachine-0.12.10/lib/evma/callback.rb +0 -32
  109. data/lib/ext/eventmachine-0.12.10/lib/evma/container.rb +0 -75
  110. data/lib/ext/eventmachine-0.12.10/lib/evma/factory.rb +0 -77
  111. data/lib/ext/eventmachine-0.12.10/lib/evma/protocol.rb +0 -87
  112. data/lib/ext/eventmachine-0.12.10/lib/evma/reactor.rb +0 -48
  113. data/lib/ext/eventmachine-0.12.10/lib/evma.rb +0 -32
  114. data/lib/ext/eventmachine-0.12.10/lib/jeventmachine.rb +0 -257
  115. data/lib/ext/eventmachine-0.12.10/lib/pr_eventmachine.rb +0 -1022
  116. data/lib/ext/eventmachine-0.12.10/setup.rb +0 -1585
  117. data/lib/ext/eventmachine-0.12.10/tasks/cpp.rake_example +0 -77
  118. data/lib/ext/eventmachine-0.12.10/tests/client.crt +0 -31
  119. data/lib/ext/eventmachine-0.12.10/tests/client.key +0 -51
  120. data/lib/ext/eventmachine-0.12.10/tests/test_attach.rb +0 -126
  121. data/lib/ext/eventmachine-0.12.10/tests/test_basic.rb +0 -284
  122. data/lib/ext/eventmachine-0.12.10/tests/test_channel.rb +0 -63
  123. data/lib/ext/eventmachine-0.12.10/tests/test_connection_count.rb +0 -35
  124. data/lib/ext/eventmachine-0.12.10/tests/test_defer.rb +0 -47
  125. data/lib/ext/eventmachine-0.12.10/tests/test_epoll.rb +0 -160
  126. data/lib/ext/eventmachine-0.12.10/tests/test_error_handler.rb +0 -35
  127. data/lib/ext/eventmachine-0.12.10/tests/test_errors.rb +0 -82
  128. data/lib/ext/eventmachine-0.12.10/tests/test_exc.rb +0 -55
  129. data/lib/ext/eventmachine-0.12.10/tests/test_file_watch.rb +0 -49
  130. data/lib/ext/eventmachine-0.12.10/tests/test_futures.rb +0 -198
  131. data/lib/ext/eventmachine-0.12.10/tests/test_get_sock_opt.rb +0 -30
  132. data/lib/ext/eventmachine-0.12.10/tests/test_handler_check.rb +0 -37
  133. data/lib/ext/eventmachine-0.12.10/tests/test_hc.rb +0 -218
  134. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb +0 -218
  135. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb +0 -153
  136. data/lib/ext/eventmachine-0.12.10/tests/test_inactivity_timeout.rb +0 -50
  137. data/lib/ext/eventmachine-0.12.10/tests/test_kb.rb +0 -60
  138. data/lib/ext/eventmachine-0.12.10/tests/test_ltp.rb +0 -182
  139. data/lib/ext/eventmachine-0.12.10/tests/test_ltp2.rb +0 -317
  140. data/lib/ext/eventmachine-0.12.10/tests/test_next_tick.rb +0 -133
  141. data/lib/ext/eventmachine-0.12.10/tests/test_object_protocol.rb +0 -37
  142. data/lib/ext/eventmachine-0.12.10/tests/test_pause.rb +0 -70
  143. data/lib/ext/eventmachine-0.12.10/tests/test_pending_connect_timeout.rb +0 -48
  144. data/lib/ext/eventmachine-0.12.10/tests/test_process_watch.rb +0 -48
  145. data/lib/ext/eventmachine-0.12.10/tests/test_processes.rb +0 -128
  146. data/lib/ext/eventmachine-0.12.10/tests/test_proxy_connection.rb +0 -92
  147. data/lib/ext/eventmachine-0.12.10/tests/test_pure.rb +0 -125
  148. data/lib/ext/eventmachine-0.12.10/tests/test_queue.rb +0 -44
  149. data/lib/ext/eventmachine-0.12.10/tests/test_running.rb +0 -42
  150. data/lib/ext/eventmachine-0.12.10/tests/test_sasl.rb +0 -72
  151. data/lib/ext/eventmachine-0.12.10/tests/test_send_file.rb +0 -242
  152. data/lib/ext/eventmachine-0.12.10/tests/test_servers.rb +0 -76
  153. data/lib/ext/eventmachine-0.12.10/tests/test_smtpclient.rb +0 -83
  154. data/lib/ext/eventmachine-0.12.10/tests/test_smtpserver.rb +0 -85
  155. data/lib/ext/eventmachine-0.12.10/tests/test_spawn.rb +0 -322
  156. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_args.rb +0 -79
  157. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_methods.rb +0 -50
  158. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_verify.rb +0 -82
  159. data/lib/ext/eventmachine-0.12.10/tests/test_timers.rb +0 -162
  160. data/lib/ext/eventmachine-0.12.10/tests/test_ud.rb +0 -36
  161. data/lib/ext/eventmachine-0.12.10/tests/testem.rb +0 -31
  162. data/lib/ext/eventmachine-0.12.10/web/whatis +0 -7
@@ -1,349 +0,0 @@
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
-
@@ -1,151 +0,0 @@
1
- /*****************************************************************************
2
-
3
- $Id$
4
-
5
- File: project.h
6
- Date: 06Apr06
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 __Project__H_
22
- #define __Project__H_
23
-
24
-
25
- #ifdef OS_WIN32
26
- #pragma warning(disable:4786)
27
- #endif
28
-
29
- #include <iostream>
30
- #include <map>
31
- #include <set>
32
- #include <vector>
33
- #include <deque>
34
- #include <string>
35
- #include <sstream>
36
- #include <stdexcept>
37
-
38
-
39
- #ifdef OS_UNIX
40
- #include <signal.h>
41
- #include <netdb.h>
42
- #include <time.h>
43
- #include <sys/time.h>
44
- #include <sys/types.h>
45
- #include <sys/stat.h>
46
- #include <sys/socket.h>
47
- #include <sys/un.h>
48
- #include <sys/resource.h>
49
- #include <sys/wait.h>
50
- #include <assert.h>
51
- #include <unistd.h>
52
- #include <fcntl.h>
53
- #include <errno.h>
54
- #include <netinet/in.h>
55
- #include <netinet/tcp.h>
56
- #include <arpa/inet.h>
57
- #include <pwd.h>
58
- typedef int SOCKET;
59
- #define closesocket close
60
- #define INVALID_SOCKET -1
61
- #define SOCKET_ERROR -1
62
- #ifdef OS_SOLARIS8
63
- #include <strings.h>
64
- #include <sys/un.h>
65
- #ifndef AF_LOCAL
66
- #define AF_LOCAL AF_UNIX
67
- #endif
68
- // INADDR_NONE is undefined on Solaris < 8. Thanks to Brett Eisenberg and Tim Pease.
69
- #ifndef INADDR_NONE
70
- #define INADDR_NONE ((unsigned long)-1)
71
- #endif
72
- #endif /* OS_SOLARIS8 */
73
-
74
- #ifdef _AIX
75
- #include <strings.h>
76
- #ifndef AF_LOCAL
77
- #define AF_LOCAL AF_UNIX
78
- #endif
79
- #endif /* _AIX */
80
-
81
- #endif /* OS_UNIX */
82
-
83
- #ifdef OS_WIN32
84
- // 21Sep09: windows limits select() to 64 sockets by default, we increase it to 1024 here (before including winsock2.h)
85
- #define FD_SETSIZE 1024
86
-
87
- #define WIN32_LEAN_AND_MEAN
88
- #include <windows.h>
89
- #include <winsock2.h>
90
- #include <ws2tcpip.h>
91
- #include <rpc.h>
92
- #include <fcntl.h>
93
- #include <assert.h>
94
-
95
- typedef int socklen_t;
96
- typedef int pid_t;
97
- #endif
98
-
99
-
100
- using namespace std;
101
-
102
- #ifdef WITH_SSL
103
- #include <openssl/ssl.h>
104
- #include <openssl/err.h>
105
- #endif
106
-
107
- #ifdef HAVE_EPOLL
108
- #include <sys/epoll.h>
109
- #endif
110
-
111
- #ifdef HAVE_KQUEUE
112
- #include <sys/event.h>
113
- #include <sys/queue.h>
114
- #endif
115
-
116
- #ifdef HAVE_INOTIFY
117
- #include <sys/inotify.h>
118
- #endif
119
-
120
- #ifdef HAVE_OLD_INOTIFY
121
- #include <sys/syscall.h>
122
- #include <linux/inotify.h>
123
- static inline int inotify_init (void) { return syscall (__NR_inotify_init); }
124
- static inline int inotify_add_watch (int fd, const char *name, __u32 mask) { return syscall (__NR_inotify_add_watch, fd, name, mask); }
125
- static inline int inotify_rm_watch (int fd, __u32 wd) { return syscall (__NR_inotify_rm_watch, fd, wd); }
126
- #define HAVE_INOTIFY 1
127
- #endif
128
-
129
- #ifdef HAVE_INOTIFY
130
- #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
131
- #endif
132
-
133
- #ifdef HAVE_WRITEV
134
- #include <sys/uio.h>
135
- #endif
136
-
137
- #include "binder.h"
138
- #include "em.h"
139
- #include "epoll.h"
140
- #include "sigs.h"
141
- #include "ed.h"
142
- #include "files.h"
143
- #include "page.h"
144
- #include "ssl.h"
145
- #include "eventmachine.h"
146
- #include "eventmachine_cpp.h"
147
-
148
-
149
-
150
-
151
- #endif // __Project__H_