eventmachine 0.12.2 → 0.12.4

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 (125) hide show
  1. data/Rakefile +191 -0
  2. data/{COPYING → docs/COPYING} +0 -0
  3. data/docs/ChangeLog +183 -0
  4. data/{DEFERRABLES → docs/DEFERRABLES} +1 -1
  5. data/{EPOLL → docs/EPOLL} +0 -0
  6. data/{GNU → docs/GNU} +0 -0
  7. data/docs/INSTALL +15 -0
  8. data/{KEYBOARD → docs/KEYBOARD} +0 -0
  9. data/{LEGAL → docs/LEGAL} +0 -0
  10. data/{LIGHTWEIGHT_CONCURRENCY → docs/LIGHTWEIGHT_CONCURRENCY} +1 -1
  11. data/{PURE_RUBY → docs/PURE_RUBY} +1 -1
  12. data/{README → docs/README} +1 -1
  13. data/{RELEASE_NOTES → docs/RELEASE_NOTES} +1 -1
  14. data/{SMTP → docs/SMTP} +1 -1
  15. data/{SPAWNED_PROCESSES → docs/SPAWNED_PROCESSES} +1 -1
  16. data/{TODO → docs/TODO} +1 -1
  17. data/ext/binder.cpp +1 -1
  18. data/ext/binder.h +1 -1
  19. data/ext/cmain.cpp +65 -74
  20. data/ext/cplusplus.cpp +1 -1
  21. data/ext/ed.cpp +41 -25
  22. data/ext/ed.h +10 -3
  23. data/ext/em.cpp +39 -12
  24. data/ext/em.h +13 -1
  25. data/ext/emwin.cpp +1 -1
  26. data/ext/emwin.h +1 -1
  27. data/ext/epoll.cpp +1 -1
  28. data/ext/epoll.h +1 -1
  29. data/ext/eventmachine.h +1 -1
  30. data/ext/eventmachine_cpp.h +1 -1
  31. data/ext/extconf.rb +86 -139
  32. data/ext/fastfilereader/extconf.rb +161 -0
  33. data/ext/fastfilereader/mapper.cpp +202 -0
  34. data/ext/fastfilereader/mapper.h +59 -0
  35. data/ext/fastfilereader/rubymain.cpp +127 -0
  36. data/ext/files.cpp +1 -1
  37. data/ext/files.h +1 -1
  38. data/ext/kb.cpp +1 -1
  39. data/ext/page.cpp +1 -1
  40. data/ext/page.h +1 -1
  41. data/ext/pipe.cpp +14 -7
  42. data/ext/project.h +1 -1
  43. data/ext/rubymain.cpp +56 -2
  44. data/ext/sigs.cpp +1 -1
  45. data/ext/sigs.h +1 -1
  46. data/ext/ssl.cpp +1 -1
  47. data/ext/ssl.h +1 -1
  48. data/java/src/com/rubyeventmachine/Application.java +196 -0
  49. data/java/src/com/rubyeventmachine/Connection.java +74 -0
  50. data/java/src/com/rubyeventmachine/ConnectionFactory.java +37 -0
  51. data/java/src/com/rubyeventmachine/DefaultConnectionFactory.java +46 -0
  52. data/java/src/com/rubyeventmachine/EmReactor.java +408 -0
  53. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  54. data/java/src/com/rubyeventmachine/EventableChannel.java +57 -0
  55. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +171 -0
  56. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +244 -0
  57. data/java/src/com/rubyeventmachine/PeriodicTimer.java +38 -0
  58. data/java/src/com/rubyeventmachine/Timer.java +54 -0
  59. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +108 -0
  60. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +124 -0
  61. data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  62. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  63. data/java/src/com/rubyeventmachine/tests/TestServers.java +74 -0
  64. data/java/src/com/rubyeventmachine/tests/TestTimers.java +89 -0
  65. data/lib/em/deferrable.rb +1 -1
  66. data/lib/em/eventable.rb +1 -1
  67. data/lib/em/future.rb +1 -1
  68. data/lib/em/messages.rb +1 -1
  69. data/lib/em/processes.rb +1 -1
  70. data/lib/em/spawnable.rb +1 -1
  71. data/lib/em/streamer.rb +1 -1
  72. data/lib/eventmachine.rb +138 -116
  73. data/lib/eventmachine_version.rb +2 -2
  74. data/lib/evma.rb +1 -1
  75. data/lib/evma/callback.rb +1 -1
  76. data/lib/evma/container.rb +1 -1
  77. data/lib/evma/factory.rb +1 -1
  78. data/lib/evma/protocol.rb +1 -1
  79. data/lib/evma/reactor.rb +1 -1
  80. data/lib/jeventmachine.rb +7 -2
  81. data/lib/pr_eventmachine.rb +2 -2
  82. data/lib/protocols/buftok.rb +1 -1
  83. data/lib/protocols/header_and_content.rb +1 -1
  84. data/lib/protocols/httpcli2.rb +16 -6
  85. data/lib/protocols/httpclient.rb +7 -1
  86. data/lib/protocols/line_and_text.rb +6 -2
  87. data/lib/protocols/linetext2.rb +12 -14
  88. data/lib/protocols/postgres.rb +1 -1
  89. data/lib/protocols/saslauth.rb +1 -1
  90. data/lib/protocols/smtpclient.rb +1 -1
  91. data/lib/protocols/smtpserver.rb +36 -23
  92. data/lib/protocols/stomp.rb +24 -1
  93. data/lib/protocols/tcptest.rb +1 -1
  94. data/tasks/cpp.rake +77 -0
  95. data/tasks/project.rake +78 -0
  96. data/tasks/tests.rake +192 -0
  97. data/tests/test_attach.rb +1 -1
  98. data/tests/test_basic.rb +65 -12
  99. data/tests/test_defer.rb +13 -29
  100. data/tests/test_epoll.rb +16 -21
  101. data/tests/test_errors.rb +1 -1
  102. data/tests/test_eventables.rb +4 -5
  103. data/tests/test_exc.rb +1 -1
  104. data/tests/test_futures.rb +1 -1
  105. data/tests/test_hc.rb +185 -236
  106. data/tests/test_httpclient.rb +1 -1
  107. data/tests/test_httpclient2.rb +28 -6
  108. data/tests/test_kb.rb +2 -2
  109. data/tests/test_ltp.rb +139 -141
  110. data/tests/test_ltp2.rb +1 -1
  111. data/tests/test_next_tick.rb +1 -1
  112. data/tests/test_processes.rb +1 -1
  113. data/tests/test_pure.rb +3 -2
  114. data/tests/test_running.rb +1 -1
  115. data/tests/test_sasl.rb +1 -1
  116. data/tests/test_send_file.rb +56 -51
  117. data/tests/test_servers.rb +26 -36
  118. data/tests/test_smtpclient.rb +46 -44
  119. data/tests/test_smtpserver.rb +1 -1
  120. data/tests/test_spawn.rb +1 -1
  121. data/tests/test_ssl_args.rb +68 -0
  122. data/tests/test_timers.rb +15 -9
  123. data/tests/test_ud.rb +1 -1
  124. data/tests/testem.rb +30 -4
  125. metadata +69 -34
@@ -1,4 +1,4 @@
1
- $Id: TODO 668 2008-01-04 23:00:34Z blackhedd $
1
+ $Id$
2
2
 
3
3
  TODO List:
4
4
 
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: binder.cpp 668 2008-01-04 23:00:34Z blackhedd $
3
+ $Id$
4
4
 
5
5
  File: binder.cpp
6
6
  Date: 07Apr06
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: binder.h 668 2008-01-04 23:00:34Z blackhedd $
3
+ $Id$
4
4
 
5
5
  File: binder.h
6
6
  Date: 07Apr06
@@ -1,9 +1,9 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: cmain.cpp 785 2008-09-15 09:46:23Z francis $
3
+ $Id$
4
4
 
5
- File: cmain.cpp
6
- Date: 06Apr06
5
+ File: cmain.cpp
6
+ Date: 06Apr06
7
7
 
8
8
  Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9
9
  Gmail: blackhedd
@@ -24,6 +24,19 @@ static EventMachine_t *EventMachine;
24
24
  static int bUseEpoll = 0;
25
25
  static int bUseKqueue = 0;
26
26
 
27
+ extern "C" void ensure_eventmachine (const char *caller = "unknown caller")
28
+ {
29
+ if (!EventMachine) {
30
+ const int err_size = 128;
31
+ char err_string[err_size];
32
+ snprintf (err_string, err_size, "eventmachine not initialized: %s", caller);
33
+ #ifdef BUILD_FOR_RUBY
34
+ rb_raise(rb_eRuntimeError, err_string);
35
+ #else
36
+ throw std::runtime_error (err_string);
37
+ #endif
38
+ }
39
+ }
27
40
 
28
41
  /***********************
29
42
  evma_initialize_library
@@ -35,7 +48,11 @@ extern "C" void evma_initialize_library (void(*cb)(const char*, int, const char*
35
48
  // we're just being linked into.
36
49
  //InstallSignalHandlers();
37
50
  if (EventMachine)
38
- throw std::runtime_error ("already initialized");
51
+ #ifdef BUILD_FOR_RUBY
52
+ rb_raise(rb_eRuntimeError, "eventmachine already initialized: evma_initialize_library");
53
+ #else
54
+ throw std::runtime_error ("eventmachine already initialized: evma_initialize_library");
55
+ #endif
39
56
  EventMachine = new EventMachine_t (cb);
40
57
  if (bUseEpoll)
41
58
  EventMachine->_UseEpoll();
@@ -50,8 +67,7 @@ evma_release_library
50
67
 
51
68
  extern "C" void evma_release_library()
52
69
  {
53
- if (!EventMachine)
54
- throw std::runtime_error ("not initialized");
70
+ ensure_eventmachine("evma_release_library");
55
71
  delete EventMachine;
56
72
  EventMachine = NULL;
57
73
  }
@@ -63,8 +79,7 @@ evma_run_machine
63
79
 
64
80
  extern "C" void evma_run_machine()
65
81
  {
66
- if (!EventMachine)
67
- throw std::runtime_error ("not initialized");
82
+ ensure_eventmachine("evma_run_machine");
68
83
  EventMachine->Run();
69
84
  }
70
85
 
@@ -75,8 +90,7 @@ evma_install_oneshot_timer
75
90
 
76
91
  extern "C" const char *evma_install_oneshot_timer (int seconds)
77
92
  {
78
- if (!EventMachine)
79
- throw std::runtime_error ("not initialized");
93
+ ensure_eventmachine("evma_install_oneshot_timer");
80
94
  return EventMachine->InstallOneshotTimer (seconds);
81
95
  }
82
96
 
@@ -87,8 +101,7 @@ evma_connect_to_server
87
101
 
88
102
  extern "C" const char *evma_connect_to_server (const char *server, int port)
89
103
  {
90
- if (!EventMachine)
91
- throw std::runtime_error ("not initialized");
104
+ ensure_eventmachine("evma_connect_to_server");
92
105
  return EventMachine->ConnectToServer (server, port);
93
106
  }
94
107
 
@@ -98,8 +111,7 @@ evma_connect_to_unix_server
98
111
 
99
112
  extern "C" const char *evma_connect_to_unix_server (const char *server)
100
113
  {
101
- if (!EventMachine)
102
- throw std::runtime_error ("not initialized");
114
+ ensure_eventmachine("evma_connect_to_unix_server");
103
115
  return EventMachine->ConnectToUnixServer (server);
104
116
  }
105
117
 
@@ -109,8 +121,7 @@ evma_attach_fd
109
121
 
110
122
  extern "C" const char *evma_attach_fd (int file_descriptor, int notify_readable, int notify_writable)
111
123
  {
112
- if (!EventMachine)
113
- throw std::runtime_error ("not initialized");
124
+ ensure_eventmachine("evma_attach_fd");
114
125
  return EventMachine->AttachFD (file_descriptor, (notify_readable ? true : false), (notify_writable ? true : false));
115
126
  }
116
127
 
@@ -120,14 +131,16 @@ evma_detach_fd
120
131
 
121
132
  extern "C" int evma_detach_fd (const char *binding)
122
133
  {
123
- if (!EventMachine)
124
- throw std::runtime_error ("not initialized");
125
-
134
+ ensure_eventmachine("evma_dettach_fd");
126
135
  EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
127
136
  if (ed)
128
137
  return EventMachine->DetachFD (ed);
129
138
  else
130
- throw std::runtime_error ("invalid binding to detach");
139
+ #ifdef BUILD_FOR_RUBY
140
+ rb_raise(rb_eRuntimeError, "invalid binding to detach");
141
+ #else
142
+ throw std::runtime_error ("invalid binding to detach");
143
+ #endif
131
144
  }
132
145
 
133
146
  /**********************
@@ -136,8 +149,7 @@ evma_create_tcp_server
136
149
 
137
150
  extern "C" const char *evma_create_tcp_server (const char *address, int port)
138
151
  {
139
- if (!EventMachine)
140
- throw std::runtime_error ("not initialized");
152
+ ensure_eventmachine("evma_create_tcp_server");
141
153
  return EventMachine->CreateTcpServer (address, port);
142
154
  }
143
155
 
@@ -147,8 +159,7 @@ evma_create_unix_domain_server
147
159
 
148
160
  extern "C" const char *evma_create_unix_domain_server (const char *filename)
149
161
  {
150
- if (!EventMachine)
151
- throw std::runtime_error ("not initialized");
162
+ ensure_eventmachine("evma_create_unix_domain_server");
152
163
  return EventMachine->CreateUnixDomainServer (filename);
153
164
  }
154
165
 
@@ -158,8 +169,7 @@ evma_open_datagram_socket
158
169
 
159
170
  extern "C" const char *evma_open_datagram_socket (const char *address, int port)
160
171
  {
161
- if (!EventMachine)
162
- throw std::runtime_error ("not initialized");
172
+ ensure_eventmachine("evma_open_datagram_socket");
163
173
  return EventMachine->OpenDatagramSocket (address, port);
164
174
  }
165
175
 
@@ -169,8 +179,7 @@ evma_open_keyboard
169
179
 
170
180
  extern "C" const char *evma_open_keyboard()
171
181
  {
172
- if (!EventMachine)
173
- throw std::runtime_error ("not initialized");
182
+ ensure_eventmachine("evma_open_keyboard");
174
183
  return EventMachine->OpenKeyboard();
175
184
  }
176
185
 
@@ -182,8 +191,7 @@ evma_send_data_to_connection
182
191
 
183
192
  extern "C" int evma_send_data_to_connection (const char *binding, const char *data, int data_length)
184
193
  {
185
- if (!EventMachine)
186
- throw std::runtime_error ("not initialized");
194
+ ensure_eventmachine("evma_send_data_to_connection");
187
195
  return ConnectionDescriptor::SendDataToConnection (binding, data, data_length);
188
196
  }
189
197
 
@@ -193,8 +201,7 @@ evma_send_datagram
193
201
 
194
202
  extern "C" int evma_send_datagram (const char *binding, const char *data, int data_length, const char *address, int port)
195
203
  {
196
- if (!EventMachine)
197
- throw std::runtime_error ("not initialized");
204
+ ensure_eventmachine("evma_send_datagram");
198
205
  return DatagramDescriptor::SendDatagram (binding, data, data_length, address, port);
199
206
  }
200
207
 
@@ -205,8 +212,7 @@ evma_close_connection
205
212
 
206
213
  extern "C" void evma_close_connection (const char *binding, int after_writing)
207
214
  {
208
- if (!EventMachine)
209
- throw std::runtime_error ("not initialized");
215
+ ensure_eventmachine("evma_close_connection");
210
216
  ConnectionDescriptor::CloseConnection (binding, (after_writing ? true : false));
211
217
  }
212
218
 
@@ -216,8 +222,7 @@ evma_report_connection_error_status
216
222
 
217
223
  extern "C" int evma_report_connection_error_status (const char *binding)
218
224
  {
219
- if (!EventMachine)
220
- throw std::runtime_error ("not initialized");
225
+ ensure_eventmachine("evma_report_connection_error_status");
221
226
  return ConnectionDescriptor::ReportErrorStatus (binding);
222
227
  }
223
228
 
@@ -227,8 +232,7 @@ evma_stop_tcp_server
227
232
 
228
233
  extern "C" void evma_stop_tcp_server (const char *binding)
229
234
  {
230
- if (!EventMachine)
231
- throw std::runtime_error ("not initialized");
235
+ ensure_eventmachine("evma_stop_tcp_server");
232
236
  AcceptorDescriptor::StopAcceptor (binding);
233
237
  }
234
238
 
@@ -239,8 +243,7 @@ evma_stop_machine
239
243
 
240
244
  extern "C" void evma_stop_machine()
241
245
  {
242
- if (!EventMachine)
243
- throw std::runtime_error ("not initialized");
246
+ ensure_eventmachine("evma_stop_machine");
244
247
  EventMachine->ScheduleHalt();
245
248
  }
246
249
 
@@ -251,8 +254,7 @@ evma_start_tls
251
254
 
252
255
  extern "C" void evma_start_tls (const char *binding)
253
256
  {
254
- if (!EventMachine)
255
- throw std::runtime_error ("not initialized");
257
+ ensure_eventmachine("evma_start_tls");
256
258
  EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
257
259
  if (ed)
258
260
  ed->StartTls();
@@ -264,8 +266,7 @@ evma_set_tls_parms
264
266
 
265
267
  extern "C" void evma_set_tls_parms (const char *binding, const char *privatekey_filename, const char *certchain_filename)
266
268
  {
267
- if (!EventMachine)
268
- throw std::runtime_error ("not initialized");
269
+ ensure_eventmachine("evma_set_tls_parms");
269
270
  EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
270
271
  if (ed)
271
272
  ed->SetTlsParms (privatekey_filename, certchain_filename);
@@ -278,8 +279,7 @@ evma_get_peername
278
279
 
279
280
  extern "C" int evma_get_peername (const char *binding, struct sockaddr *sa)
280
281
  {
281
- if (!EventMachine)
282
- throw std::runtime_error ("not initialized");
282
+ ensure_eventmachine("evma_get_peername");
283
283
  EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
284
284
  if (ed) {
285
285
  return ed->GetPeername (sa) ? 1 : 0;
@@ -294,8 +294,7 @@ evma_get_sockname
294
294
 
295
295
  extern "C" int evma_get_sockname (const char *binding, struct sockaddr *sa)
296
296
  {
297
- if (!EventMachine)
298
- throw std::runtime_error ("not initialized");
297
+ ensure_eventmachine("evma_get_sockname");
299
298
  EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
300
299
  if (ed) {
301
300
  return ed->GetSockname (sa) ? 1 : 0;
@@ -310,8 +309,7 @@ evma_get_subprocess_pid
310
309
 
311
310
  extern "C" int evma_get_subprocess_pid (const char *binding, pid_t *pid)
312
311
  {
313
- if (!EventMachine)
314
- throw std::runtime_error ("not initialized");
312
+ ensure_eventmachine("evma_get_subprocess_pid");
315
313
  EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
316
314
  if (ed) {
317
315
  return ed->GetSubprocessPid (pid) ? 1 : 0;
@@ -326,8 +324,7 @@ evma_get_subprocess_status
326
324
 
327
325
  extern "C" int evma_get_subprocess_status (const char *binding, int *status)
328
326
  {
329
- if (!EventMachine)
330
- throw std::runtime_error ("not initialized");
327
+ ensure_eventmachine("evma_get_subprocess_status");
331
328
  if (status) {
332
329
  *status = EventMachine->SubprocessExitStatus;
333
330
  return 1;
@@ -343,8 +340,7 @@ evma_signal_loopbreak
343
340
 
344
341
  extern "C" void evma_signal_loopbreak()
345
342
  {
346
- if (!EventMachine)
347
- throw std::runtime_error ("not initialized");
343
+ ensure_eventmachine("evma_signal_loopbreak");
348
344
  EventMachine->SignalLoopBreaker();
349
345
  }
350
346
 
@@ -356,8 +352,7 @@ evma__write_file
356
352
 
357
353
  extern "C" const char *evma__write_file (const char *filename)
358
354
  {
359
- if (!EventMachine)
360
- throw std::runtime_error ("not initialized");
355
+ ensure_eventmachine("evma__write_file");
361
356
  return EventMachine->_OpenFileForWriting (filename);
362
357
  }
363
358
 
@@ -368,8 +363,7 @@ evma_get_comm_inactivity_timeout
368
363
 
369
364
  extern "C" int evma_get_comm_inactivity_timeout (const char *binding, int *value)
370
365
  {
371
- if (!EventMachine)
372
- throw std::runtime_error ("not initialized");
366
+ ensure_eventmachine("evma_get_comm_inactivity_timeout");
373
367
  EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
374
368
  if (ed) {
375
369
  return ed->GetCommInactivityTimeout (value);
@@ -384,8 +378,7 @@ evma_set_comm_inactivity_timeout
384
378
 
385
379
  extern "C" int evma_set_comm_inactivity_timeout (const char *binding, int *value)
386
380
  {
387
- if (!EventMachine)
388
- throw std::runtime_error ("not initialized");
381
+ ensure_eventmachine("evma_set_comm_inactivity_timeout");
389
382
  EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
390
383
  if (ed) {
391
384
  return ed->SetCommInactivityTimeout (value);
@@ -401,8 +394,7 @@ evma_set_timer_quantum
401
394
 
402
395
  extern "C" void evma_set_timer_quantum (int interval)
403
396
  {
404
- if (!EventMachine)
405
- throw std::runtime_error ("not initialized");
397
+ ensure_eventmachine("evma_set_timer_quantum");
406
398
  EventMachine->SetTimerQuantum (interval);
407
399
  }
408
400
 
@@ -413,8 +405,13 @@ evma_set_max_timer_count
413
405
  extern "C" void evma_set_max_timer_count (int ct)
414
406
  {
415
407
  // This may only be called if the reactor is not running.
408
+
416
409
  if (EventMachine)
417
- throw std::runtime_error ("already initialized");
410
+ #ifdef BUILD_FOR_RUBY
411
+ rb_raise(rb_eRuntimeError, "eventmachine already initialized: evma_set_max_timer_count");
412
+ #else
413
+ throw std::runtime_error ("eventmachine already initialized: evma_set_max_timer_count");
414
+ #endif
418
415
  EventMachine_t::SetMaxTimerCount (ct);
419
416
  }
420
417
 
@@ -424,8 +421,8 @@ evma_setuid_string
424
421
 
425
422
  extern "C" void evma_setuid_string (const char *username)
426
423
  {
427
- // We do NOT need to be running an EM instance because this method is static.
428
- EventMachine_t::SetuidString (username);
424
+ // We do NOT need to be running an EM instance because this method is static.
425
+ EventMachine_t::SetuidString (username);
429
426
  }
430
427
 
431
428
 
@@ -435,8 +432,7 @@ evma_popen
435
432
 
436
433
  extern "C" const char *evma_popen (char * const*cmd_strings)
437
434
  {
438
- if (!EventMachine)
439
- throw std::runtime_error ("not initialized");
435
+ ensure_eventmachine("evma_popen");
440
436
  return EventMachine->Socketpair (cmd_strings);
441
437
  }
442
438
 
@@ -447,8 +443,7 @@ evma_get_outbound_data_size
447
443
 
448
444
  extern "C" int evma_get_outbound_data_size (const char *binding)
449
445
  {
450
- if (!EventMachine)
451
- throw std::runtime_error ("not initialized");
446
+ ensure_eventmachine("evma_get_outbound_data_size");
452
447
  EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
453
448
  return ed ? ed->GetOutboundDataSize() : 0;
454
449
  }
@@ -509,8 +504,7 @@ extern "C" int evma_send_file_data_to_connection (const char *binding, const cha
509
504
  char data[32*1024];
510
505
  int r;
511
506
 
512
- if (!EventMachine)
513
- throw std::runtime_error("not initialized");
507
+ ensure_eventmachine("evma_send_file_data_to_connection");
514
508
 
515
509
  int Fd = open (filename, O_RDONLY);
516
510
 
@@ -548,6 +542,3 @@ extern "C" int evma_send_file_data_to_connection (const char *binding, const cha
548
542
  return 0;
549
543
  }
550
544
 
551
-
552
-
553
-
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: cplusplus.cpp 668 2008-01-04 23:00:34Z blackhedd $
3
+ $Id$
4
4
 
5
5
  File: cplusplus.cpp
6
6
  Date: 27Jul07
data/ext/ed.cpp CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: ed.cpp 785 2008-09-15 09:46:23Z francis $
3
+ $Id$
4
4
 
5
5
  File: ed.cpp
6
6
  Date: 06Apr06
@@ -189,9 +189,7 @@ ConnectionDescriptor::ConnectionDescriptor (int sd, EventMachine_t *em):
189
189
  #ifdef HAVE_EPOLL
190
190
  EpollEvent.events = EPOLLOUT;
191
191
  #endif
192
- #ifdef HAVE_KQUEUE
193
- MyEventMachine->ArmKqueueWriter (this);
194
- #endif
192
+ // 22Jan09: Moved ArmKqueueWriter into SetConnectPending() to fix assertion failure in _WriteOutboundData()
195
193
  }
196
194
 
197
195
 
@@ -263,6 +261,17 @@ int ConnectionDescriptor::ReportErrorStatus (const char *binding)
263
261
  return -1;
264
262
  }
265
263
 
264
+ /***************************************
265
+ ConnectionDescriptor::SetConnectPending
266
+ ****************************************/
267
+
268
+ void ConnectionDescriptor::SetConnectPending(bool f)
269
+ {
270
+ bConnectPending = f;
271
+ #ifdef HAVE_KQUEUE
272
+ MyEventMachine->ArmKqueueWriter (this);
273
+ #endif
274
+ }
266
275
 
267
276
 
268
277
  /**************************************
@@ -624,29 +633,36 @@ void ConnectionDescriptor::_WriteOutboundData()
624
633
  assert (GetSocket() != INVALID_SOCKET);
625
634
  int bytes_written = send (GetSocket(), output_buffer, nbytes, 0);
626
635
 
627
- if (bytes_written > 0) {
628
- OutboundDataSize -= bytes_written;
629
- if ((size_t)bytes_written < nbytes) {
630
- int len = nbytes - bytes_written;
631
- char *buffer = (char*) malloc (len + 1);
632
- if (!buffer)
633
- throw std::runtime_error ("bad alloc throwing back data");
634
- memcpy (buffer, output_buffer + bytes_written, len);
635
- buffer [len] = 0;
636
- OutboundPages.push_front (OutboundPage (buffer, len));
637
- }
636
+ bool err = false;
637
+ if (bytes_written < 0) {
638
+ err = true;
639
+ bytes_written = 0;
640
+ }
638
641
 
639
- #ifdef HAVE_EPOLL
640
- EpollEvent.events = (EPOLLIN | (SelectForWrite() ? EPOLLOUT : 0));
641
- assert (MyEventMachine);
642
- MyEventMachine->Modify (this);
643
- #endif
644
- #ifdef HAVE_KQUEUE
645
- if (SelectForWrite())
646
- MyEventMachine->ArmKqueueWriter (this);
647
- #endif
642
+ assert (bytes_written >= 0);
643
+ OutboundDataSize -= bytes_written;
644
+ if ((size_t)bytes_written < nbytes) {
645
+ int len = nbytes - bytes_written;
646
+ char *buffer = (char*) malloc (len + 1);
647
+ if (!buffer)
648
+ throw std::runtime_error ("bad alloc throwing back data");
649
+ memcpy (buffer, output_buffer + bytes_written, len);
650
+ buffer [len] = 0;
651
+ OutboundPages.push_front (OutboundPage (buffer, len));
648
652
  }
649
- else {
653
+
654
+ #ifdef HAVE_EPOLL
655
+ EpollEvent.events = (EPOLLIN | (SelectForWrite() ? EPOLLOUT : 0));
656
+ assert (MyEventMachine);
657
+ MyEventMachine->Modify (this);
658
+ #endif
659
+ #ifdef HAVE_KQUEUE
660
+ if (SelectForWrite())
661
+ MyEventMachine->ArmKqueueWriter (this);
662
+ #endif
663
+
664
+
665
+ if (err) {
650
666
  #ifdef OS_UNIX
651
667
  if ((errno != EINPROGRESS) && (errno != EWOULDBLOCK) && (errno != EINTR))
652
668
  #endif