eventmachine 1.0.3-x86-mingw32 → 1.2.0.dev.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +84 -1
  3. data/README.md +6 -7
  4. data/ext/binder.cpp +10 -10
  5. data/ext/binder.h +5 -5
  6. data/ext/cmain.cpp +173 -61
  7. data/ext/ed.cpp +262 -127
  8. data/ext/ed.h +50 -30
  9. data/ext/em.cpp +491 -445
  10. data/ext/em.h +101 -36
  11. data/ext/eventmachine.h +67 -51
  12. data/ext/extconf.rb +124 -31
  13. data/ext/fastfilereader/extconf.rb +9 -2
  14. data/ext/fastfilereader/mapper.cpp +3 -1
  15. data/ext/fastfilereader/rubymain.cpp +7 -7
  16. data/ext/kb.cpp +1 -1
  17. data/ext/pipe.cpp +11 -4
  18. data/ext/project.h +26 -6
  19. data/ext/rubymain.cpp +408 -201
  20. data/ext/ssl.cpp +167 -20
  21. data/ext/ssl.h +11 -2
  22. data/java/src/com/rubyeventmachine/EmReactor.java +16 -0
  23. data/java/src/com/rubyeventmachine/EventableChannel.java +2 -0
  24. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +6 -0
  25. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +55 -10
  26. data/lib/1.9/fastfilereaderext.so +0 -0
  27. data/lib/1.9/rubyeventmachine.so +0 -0
  28. data/lib/2.0/fastfilereaderext.so +0 -0
  29. data/lib/2.0/rubyeventmachine.so +0 -0
  30. data/lib/2.1/fastfilereaderext.so +0 -0
  31. data/lib/2.1/rubyeventmachine.so +0 -0
  32. data/lib/2.2/fastfilereaderext.so +0 -0
  33. data/lib/2.2/rubyeventmachine.so +0 -0
  34. data/lib/2.3/fastfilereaderext.so +0 -0
  35. data/lib/2.3/rubyeventmachine.so +0 -0
  36. data/lib/em/buftok.rb +34 -85
  37. data/lib/em/channel.rb +5 -0
  38. data/lib/em/completion.rb +2 -2
  39. data/lib/em/connection.rb +62 -4
  40. data/lib/em/iterator.rb +30 -48
  41. data/lib/em/pool.rb +1 -1
  42. data/lib/em/protocols/httpclient.rb +31 -11
  43. data/lib/em/protocols/line_and_text.rb +4 -4
  44. data/lib/em/protocols/linetext2.rb +44 -39
  45. data/lib/em/protocols/smtpclient.rb +60 -31
  46. data/lib/em/protocols/smtpserver.rb +32 -9
  47. data/lib/em/pure_ruby.rb +8 -3
  48. data/lib/em/queue.rb +16 -7
  49. data/lib/em/resolver.rb +64 -24
  50. data/lib/em/threaded_resource.rb +2 -2
  51. data/lib/em/tick_loop.rb +19 -19
  52. data/lib/em/version.rb +1 -1
  53. data/lib/eventmachine.rb +96 -49
  54. data/lib/jeventmachine.rb +17 -0
  55. data/rakelib/package.rake +31 -4
  56. data/tests/dhparam.pem +13 -0
  57. data/tests/em_test_helper.rb +87 -0
  58. data/tests/test_attach.rb +25 -0
  59. data/tests/test_basic.rb +27 -38
  60. data/tests/test_channel.rb +14 -1
  61. data/tests/test_completion.rb +1 -0
  62. data/tests/test_connection_count.rb +22 -1
  63. data/tests/test_connection_write.rb +35 -0
  64. data/tests/test_defer.rb +17 -0
  65. data/tests/test_epoll.rb +26 -14
  66. data/tests/test_file_watch.rb +1 -0
  67. data/tests/test_fork.rb +75 -0
  68. data/tests/test_httpclient.rb +43 -0
  69. data/tests/test_idle_connection.rb +6 -4
  70. data/tests/test_ipv4.rb +125 -0
  71. data/tests/test_ipv6.rb +131 -0
  72. data/tests/test_iterator.rb +115 -0
  73. data/tests/test_kb.rb +19 -25
  74. data/tests/test_ltp2.rb +20 -0
  75. data/tests/test_many_fds.rb +22 -0
  76. data/tests/test_pause.rb +29 -0
  77. data/tests/test_pool.rb +2 -0
  78. data/tests/test_process_watch.rb +2 -0
  79. data/tests/test_processes.rb +7 -7
  80. data/tests/test_queue.rb +14 -0
  81. data/tests/test_resolver.rb +56 -7
  82. data/tests/test_set_sock_opt.rb +2 -0
  83. data/tests/test_smtpclient.rb +20 -0
  84. data/tests/test_ssl_args.rb +2 -2
  85. data/tests/test_ssl_dhparam.rb +83 -0
  86. data/tests/test_ssl_ecdh_curve.rb +79 -0
  87. data/tests/test_ssl_extensions.rb +49 -0
  88. data/tests/test_ssl_methods.rb +22 -5
  89. data/tests/test_ssl_protocols.rb +246 -0
  90. data/tests/test_ssl_verify.rb +103 -59
  91. data/tests/test_system.rb +4 -0
  92. data/tests/test_threaded_resource.rb +8 -0
  93. data/tests/test_unbind_reason.rb +5 -1
  94. metadata +173 -107
  95. data/.gitignore +0 -21
  96. data/.travis.yml +0 -12
  97. data/.yardopts +0 -7
  98. data/Gemfile +0 -2
  99. data/Rakefile +0 -20
  100. data/eventmachine.gemspec +0 -36
  101. data/rakelib/cpp.rake_example +0 -77
data/ext/em.h CHANGED
@@ -22,13 +22,22 @@ See the file COPYING for complete licensing information.
22
22
 
23
23
  #ifdef BUILD_FOR_RUBY
24
24
  #include <ruby.h>
25
- #define EmSelect rb_thread_select
25
+ #ifdef HAVE_RB_THREAD_FD_SELECT
26
+ #define EmSelect rb_thread_fd_select
27
+ #else
28
+ // ruby 1.9.1 and below
29
+ #define EmSelect rb_thread_select
30
+ #endif
31
+
32
+ #ifdef HAVE_RB_THREAD_CALL_WITHOUT_GVL
33
+ #include <ruby/thread.h>
34
+ #endif
26
35
 
27
36
  #ifdef HAVE_RB_WAIT_FOR_SINGLE_FD
28
37
  #include <ruby/io.h>
29
38
  #endif
30
39
 
31
- #if defined(HAVE_RBTRAP)
40
+ #if defined(HAVE_RB_TRAP_IMMEDIATE)
32
41
  #include <rubysig.h>
33
42
  #elif defined(HAVE_RB_ENABLE_INTERRUPT)
34
43
  extern "C" {
@@ -60,8 +69,55 @@ See the file COPYING for complete licensing information.
60
69
  #define EmSelect select
61
70
  #endif
62
71
 
72
+ #if !defined(HAVE_TYPE_RB_FDSET_T)
73
+ #define fd_check(n) (((n) < FD_SETSIZE) ? 1 : 0*fprintf(stderr, "fd %d too large for select\n", (n)))
74
+ // These definitions are cribbed from include/ruby/intern.h in Ruby 1.9.3,
75
+ // with this change: any macros that read or write the nth element of an
76
+ // fdset first call fd_check to make sure n is in bounds.
77
+ typedef fd_set rb_fdset_t;
78
+ #define rb_fd_zero(f) FD_ZERO(f)
79
+ #define rb_fd_set(n, f) do { if (fd_check(n)) FD_SET((n), (f)); } while(0)
80
+ #define rb_fd_clr(n, f) do { if (fd_check(n)) FD_CLR((n), (f)); } while(0)
81
+ #define rb_fd_isset(n, f) (fd_check(n) ? FD_ISSET((n), (f)) : 0)
82
+ #define rb_fd_copy(d, s, n) (*(d) = *(s))
83
+ #define rb_fd_dup(d, s) (*(d) = *(s))
84
+ #define rb_fd_resize(n, f) ((void)(f))
85
+ #define rb_fd_ptr(f) (f)
86
+ #define rb_fd_init(f) FD_ZERO(f)
87
+ #define rb_fd_init_copy(d, s) (*(d) = *(s))
88
+ #define rb_fd_term(f) ((void)(f))
89
+ #define rb_fd_max(f) FD_SETSIZE
90
+ #define rb_fd_select(n, rfds, wfds, efds, timeout) \
91
+ select(fd_check((n)-1) ? (n) : FD_SETSIZE, (rfds), (wfds), (efds), (timeout))
92
+ #define rb_thread_fd_select(n, rfds, wfds, efds, timeout) \
93
+ rb_thread_select(fd_check((n)-1) ? (n) : FD_SETSIZE, (rfds), (wfds), (efds), (timeout))
94
+ #endif
95
+
96
+
97
+ // This Solaris fix is adapted from eval_intern.h in Ruby 1.9.3:
98
+ // Solaris sys/select.h switches select to select_large_fdset to support larger
99
+ // file descriptors if FD_SETSIZE is larger than 1024 on 32bit environment.
100
+ // But Ruby doesn't change FD_SETSIZE because fd_set is allocated dynamically.
101
+ // So following definition is required to use select_large_fdset.
102
+ #ifdef HAVE_SELECT_LARGE_FDSET
103
+ #define select(n, r, w, e, t) select_large_fdset((n), (r), (w), (e), (t))
104
+ extern "C" {
105
+ int select_large_fdset(int, fd_set *, fd_set *, fd_set *, struct timeval *);
106
+ }
107
+ #endif
108
+
63
109
  class EventableDescriptor;
64
110
  class InotifyDescriptor;
111
+ struct SelectData_t;
112
+
113
+ /*************
114
+ enum Poller_t
115
+ *************/
116
+ enum Poller_t {
117
+ Poller_Default, // typically Select
118
+ Poller_Epoll,
119
+ Poller_Kqueue
120
+ };
65
121
 
66
122
 
67
123
  /********************
@@ -74,29 +130,35 @@ class EventMachine_t
74
130
  static int GetMaxTimerCount();
75
131
  static void SetMaxTimerCount (int);
76
132
 
133
+ static int GetSimultaneousAcceptCount();
134
+ static void SetSimultaneousAcceptCount (int);
135
+
77
136
  public:
78
- EventMachine_t (EMCallback);
137
+ EventMachine_t (EMCallback, Poller_t);
79
138
  virtual ~EventMachine_t();
80
139
 
140
+ bool RunOnce();
81
141
  void Run();
82
142
  void ScheduleHalt();
143
+ bool Stopping();
83
144
  void SignalLoopBreaker();
84
- const unsigned long InstallOneshotTimer (int);
85
- const unsigned long ConnectToServer (const char *, int, const char *, int);
86
- const unsigned long ConnectToUnixServer (const char *);
87
-
88
- const unsigned long CreateTcpServer (const char *, int);
89
- const unsigned long OpenDatagramSocket (const char *, int);
90
- const unsigned long CreateUnixDomainServer (const char*);
91
- const unsigned long OpenKeyboard();
145
+ const uintptr_t InstallOneshotTimer (int);
146
+ const uintptr_t ConnectToServer (const char *, int, const char *, int);
147
+ const uintptr_t ConnectToUnixServer (const char *);
148
+
149
+ const uintptr_t CreateTcpServer (const char *, int);
150
+ const uintptr_t OpenDatagramSocket (const char *, int);
151
+ const uintptr_t CreateUnixDomainServer (const char*);
152
+ const uintptr_t AttachSD (SOCKET);
153
+ const uintptr_t OpenKeyboard();
92
154
  //const char *Popen (const char*, const char*);
93
- const unsigned long Socketpair (char* const*);
155
+ const uintptr_t Socketpair (char* const*);
94
156
 
95
157
  void Add (EventableDescriptor*);
96
158
  void Modify (EventableDescriptor*);
97
159
  void Deregister (EventableDescriptor*);
98
160
 
99
- const unsigned long AttachFD (int, bool);
161
+ const uintptr_t AttachFD (SOCKET, bool);
100
162
  int DetachFD (EventableDescriptor*);
101
163
 
102
164
  void ArmKqueueWriter (EventableDescriptor*);
@@ -113,18 +175,18 @@ class EventMachine_t
113
175
  float GetHeartbeatInterval();
114
176
  int SetHeartbeatInterval(float);
115
177
 
116
- const unsigned long WatchFile (const char*);
178
+ const uintptr_t WatchFile (const char*);
117
179
  void UnwatchFile (int);
118
- void UnwatchFile (const unsigned long);
180
+ void UnwatchFile (const uintptr_t);
119
181
 
120
182
  #ifdef HAVE_KQUEUE
121
183
  void _HandleKqueueFileEvent (struct kevent*);
122
184
  void _RegisterKqueueFileEvent(int);
123
185
  #endif
124
186
 
125
- const unsigned long WatchPid (int);
187
+ const uintptr_t WatchPid (int);
126
188
  void UnwatchPid (int);
127
- void UnwatchPid (const unsigned long);
189
+ void UnwatchPid (const uintptr_t);
128
190
 
129
191
  #ifdef HAVE_KQUEUE
130
192
  void _HandleKqueuePidEvent (struct kevent*);
@@ -132,20 +194,16 @@ class EventMachine_t
132
194
 
133
195
  uint64_t GetCurrentLoopTime() { return MyCurrentLoopTime; }
134
196
 
135
- // Temporary:
136
- void _UseEpoll();
137
- void _UseKqueue();
138
-
139
- bool UsingKqueue() { return bKqueue; }
140
- bool UsingEpoll() { return bEpoll; }
141
-
142
197
  void QueueHeartbeat(EventableDescriptor*);
143
198
  void ClearHeartbeat(uint64_t, EventableDescriptor*);
144
199
 
145
200
  uint64_t GetRealTime();
146
201
 
202
+ Poller_t GetPoller() { return Poller; }
203
+
204
+ static bool name2address (const char *server, int port, struct sockaddr *addr, size_t *addr_len);
205
+
147
206
  private:
148
- void _RunOnce();
149
207
  void _RunTimers();
150
208
  void _UpdateTime();
151
209
  void _AddNewDescriptors();
@@ -165,7 +223,7 @@ class EventMachine_t
165
223
  public:
166
224
  void _ReadLoopBreaker();
167
225
  void _ReadInotifyEvents();
168
- int NumCloseScheduled;
226
+ int NumCloseScheduled;
169
227
 
170
228
  private:
171
229
  enum {
@@ -186,10 +244,8 @@ class EventMachine_t
186
244
  vector<EventableDescriptor*> NewDescriptors;
187
245
  set<EventableDescriptor*> ModifiedDescriptors;
188
246
 
189
- uint64_t NextHeartbeatTime;
190
-
191
- int LoopBreakerReader;
192
- int LoopBreakerWriter;
247
+ SOCKET LoopBreakerReader;
248
+ SOCKET LoopBreakerWriter;
193
249
  #ifdef OS_WIN32
194
250
  struct sockaddr_in LoopBreakerTarget;
195
251
  #endif
@@ -203,22 +259,29 @@ class EventMachine_t
203
259
  unsigned LastTickCount;
204
260
  #endif
205
261
 
262
+ #ifdef OS_DARWIN
263
+ mach_timebase_info_data_t mach_timebase;
264
+ #endif
265
+
206
266
  private:
207
267
  bool bTerminateSignalReceived;
268
+ SelectData_t *SelectData;
269
+
270
+ Poller_t Poller;
208
271
 
209
- bool bEpoll;
210
272
  int epfd; // Epoll file-descriptor
211
273
  #ifdef HAVE_EPOLL
212
274
  struct epoll_event epoll_events [MaxEvents];
213
275
  #endif
214
276
 
215
- bool bKqueue;
216
277
  int kqfd; // Kqueue file-descriptor
217
278
  #ifdef HAVE_KQUEUE
218
279
  struct kevent Karray [MaxEvents];
219
280
  #endif
220
281
 
282
+ #ifdef HAVE_INOTIFY
221
283
  InotifyDescriptor *inotify; // pollable descriptor for our inotify instance
284
+ #endif
222
285
  };
223
286
 
224
287
 
@@ -229,13 +292,15 @@ struct SelectData_t
229
292
  struct SelectData_t
230
293
  {
231
294
  SelectData_t();
295
+ ~SelectData_t();
232
296
 
233
297
  int _Select();
298
+ void _Clear();
234
299
 
235
- int maxsocket;
236
- fd_set fdreads;
237
- fd_set fdwrites;
238
- fd_set fderrors;
300
+ SOCKET maxsocket;
301
+ rb_fdset_t fdreads;
302
+ rb_fdset_t fdwrites;
303
+ rb_fdset_t fderrors;
239
304
  timeval tv;
240
305
  int nSockets;
241
306
  };
@@ -37,80 +37,96 @@ extern "C" {
37
37
  EM_SSL_VERIFY = 109,
38
38
  EM_PROXY_TARGET_UNBOUND = 110,
39
39
  EM_PROXY_COMPLETED = 111
40
+ };
40
41
 
42
+ enum { // SSL/TLS Protocols
43
+ EM_PROTO_SSLv2 = 2,
44
+ EM_PROTO_SSLv3 = 4,
45
+ EM_PROTO_TLSv1 = 8,
46
+ EM_PROTO_TLSv1_1 = 16,
47
+ EM_PROTO_TLSv1_2 = 32
41
48
  };
42
49
 
43
50
  void evma_initialize_library (EMCallback);
51
+ bool evma_run_machine_once();
44
52
  void evma_run_machine();
45
53
  void evma_release_library();
46
- const unsigned long evma_install_oneshot_timer (int seconds);
47
- const unsigned long evma_connect_to_server (const char *bind_addr, int bind_port, const char *server, int port);
48
- const unsigned long evma_connect_to_unix_server (const char *server);
49
-
50
- const unsigned long evma_attach_fd (int file_descriptor, int watch_mode);
51
- int evma_detach_fd (const unsigned long binding);
52
- int evma_get_file_descriptor (const unsigned long binding);
53
- int evma_is_notify_readable (const unsigned long binding);
54
- void evma_set_notify_readable (const unsigned long binding, int mode);
55
- int evma_is_notify_writable (const unsigned long binding);
56
- void evma_set_notify_writable (const unsigned long binding, int mode);
57
-
58
- int evma_pause(const unsigned long binding);
59
- int evma_is_paused(const unsigned long binding);
60
- int evma_resume(const unsigned long binding);
61
-
62
- int evma_num_close_scheduled();
63
-
64
- void evma_stop_tcp_server (const unsigned long signature);
65
- const unsigned long evma_create_tcp_server (const char *address, int port);
66
- const unsigned long evma_create_unix_domain_server (const char *filename);
67
- const unsigned long evma_open_datagram_socket (const char *server, int port);
68
- const unsigned long evma_open_keyboard();
69
- void evma_set_tls_parms (const unsigned long binding, const char *privatekey_filename, const char *certchain_filenane, int verify_peer);
70
- void evma_start_tls (const unsigned long binding);
54
+ const uintptr_t evma_install_oneshot_timer (int seconds);
55
+ const uintptr_t evma_connect_to_server (const char *bind_addr, int bind_port, const char *server, int port);
56
+ const uintptr_t evma_connect_to_unix_server (const char *server);
57
+
58
+ const uintptr_t evma_attach_fd (int file_descriptor, int watch_mode);
59
+ int evma_detach_fd (const uintptr_t binding);
60
+ int evma_get_file_descriptor (const uintptr_t binding);
61
+ int evma_is_notify_readable (const uintptr_t binding);
62
+ void evma_set_notify_readable (const uintptr_t binding, int mode);
63
+ int evma_is_notify_writable (const uintptr_t binding);
64
+ void evma_set_notify_writable (const uintptr_t binding, int mode);
65
+
66
+ int evma_pause(const uintptr_t binding);
67
+ int evma_is_paused(const uintptr_t binding);
68
+ int evma_resume(const uintptr_t binding);
69
+
70
+ int evma_num_close_scheduled();
71
+
72
+ void evma_stop_tcp_server (const uintptr_t binding);
73
+ const uintptr_t evma_create_tcp_server (const char *address, int port);
74
+ const uintptr_t evma_create_unix_domain_server (const char *filename);
75
+ const uintptr_t evma_attach_sd (int sd);
76
+ const uintptr_t evma_open_datagram_socket (const char *server, int port);
77
+ const uintptr_t evma_open_keyboard();
78
+ void evma_set_tls_parms (const uintptr_t binding, const char *privatekey_filename, const char *certchain_filenane, int verify_peer, int fail_if_no_peer_cert, const char *sni_hostname, const char *cipherlist, const char *ecdh_curve, const char *dhparam, int protocols);
79
+ void evma_start_tls (const uintptr_t binding);
71
80
 
72
81
  #ifdef WITH_SSL
73
- X509 *evma_get_peer_cert (const unsigned long binding);
74
- void evma_accept_ssl_peer (const unsigned long binding);
82
+ X509 *evma_get_peer_cert (const uintptr_t binding);
83
+ int evma_get_cipher_bits (const uintptr_t binding);
84
+ const char *evma_get_cipher_name (const uintptr_t binding);
85
+ const char *evma_get_cipher_protocol (const uintptr_t binding);
86
+ const char *evma_get_sni_hostname (const uintptr_t binding);
87
+ void evma_accept_ssl_peer (const uintptr_t binding);
75
88
  #endif
76
89
 
77
- int evma_get_peername (const unsigned long binding, struct sockaddr*, socklen_t*);
78
- int evma_get_sockname (const unsigned long binding, struct sockaddr*, socklen_t*);
79
- int evma_get_subprocess_pid (const unsigned long binding, pid_t*);
80
- int evma_get_subprocess_status (const unsigned long binding, int*);
90
+ int evma_get_peername (const uintptr_t binding, struct sockaddr*, socklen_t*);
91
+ int evma_get_sockname (const uintptr_t binding, struct sockaddr*, socklen_t*);
92
+ int evma_get_subprocess_pid (const uintptr_t binding, pid_t*);
93
+ int evma_get_subprocess_status (const uintptr_t binding, int*);
81
94
  int evma_get_connection_count();
82
- int evma_send_data_to_connection (const unsigned long binding, const char *data, int data_length);
83
- int evma_send_datagram (const unsigned long binding, const char *data, int data_length, const char *address, int port);
84
- float evma_get_comm_inactivity_timeout (const unsigned long binding);
85
- int evma_set_comm_inactivity_timeout (const unsigned long binding, float value);
86
- float evma_get_pending_connect_timeout (const unsigned long binding);
87
- int evma_set_pending_connect_timeout (const unsigned long binding, float value);
88
- int evma_get_outbound_data_size (const unsigned long binding);
89
- uint64_t evma_get_last_activity_time (const unsigned long);
90
- int evma_send_file_data_to_connection (const unsigned long binding, const char *filename);
91
-
92
- void evma_close_connection (const unsigned long binding, int after_writing);
93
- int evma_report_connection_error_status (const unsigned long binding);
95
+ int evma_send_data_to_connection (const uintptr_t binding, const char *data, int data_length);
96
+ int evma_send_datagram (const uintptr_t binding, const char *data, int data_length, const char *address, int port);
97
+ float evma_get_comm_inactivity_timeout (const uintptr_t binding);
98
+ int evma_set_comm_inactivity_timeout (const uintptr_t binding, float value);
99
+ float evma_get_pending_connect_timeout (const uintptr_t binding);
100
+ int evma_set_pending_connect_timeout (const uintptr_t binding, float value);
101
+ int evma_get_outbound_data_size (const uintptr_t binding);
102
+ uint64_t evma_get_last_activity_time (const uintptr_t binding);
103
+ int evma_send_file_data_to_connection (const uintptr_t binding, const char *filename);
104
+
105
+ void evma_close_connection (const uintptr_t binding, int after_writing);
106
+ int evma_report_connection_error_status (const uintptr_t binding);
94
107
  void evma_signal_loopbreak();
95
108
  void evma_set_timer_quantum (int);
96
109
  int evma_get_max_timer_count();
97
110
  void evma_set_max_timer_count (int);
111
+ int evma_get_simultaneous_accept_count();
112
+ void evma_set_simultaneous_accept_count (int);
98
113
  void evma_setuid_string (const char *username);
99
114
  void evma_stop_machine();
115
+ bool evma_stopping();
100
116
  float evma_get_heartbeat_interval();
101
117
  int evma_set_heartbeat_interval(float);
102
118
 
103
- const unsigned long evma_popen (char * const*cmd_strings);
119
+ const uintptr_t evma_popen (char * const*cmd_strings);
104
120
 
105
- const unsigned long evma_watch_filename (const char *fname);
106
- void evma_unwatch_filename (const unsigned long);
121
+ const uintptr_t evma_watch_filename (const char *fname);
122
+ void evma_unwatch_filename (const uintptr_t binding);
107
123
 
108
- const unsigned long evma_watch_pid (int);
109
- void evma_unwatch_pid (const unsigned long);
124
+ const uintptr_t evma_watch_pid (int);
125
+ void evma_unwatch_pid (const uintptr_t binding);
110
126
 
111
- void evma_start_proxy(const unsigned long, const unsigned long, const unsigned long, const unsigned long);
112
- void evma_stop_proxy(const unsigned long);
113
- unsigned long evma_proxied_bytes(const unsigned long);
127
+ void evma_start_proxy(const uintptr_t from, const uintptr_t to, const unsigned long bufsize, const unsigned long length);
128
+ void evma_stop_proxy(const uintptr_t from);
129
+ unsigned long evma_proxied_bytes(const uintptr_t from);
114
130
 
115
131
  int evma_set_rlimit_nofile (int n_files);
116
132
 
@@ -1,6 +1,9 @@
1
1
  require 'fileutils'
2
2
  require 'mkmf'
3
3
 
4
+ # Eager check devs tools
5
+ have_devel? if respond_to?(:have_devel?)
6
+
4
7
  def check_libs libs = [], fatal = false
5
8
  libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
6
9
  end
@@ -22,31 +25,59 @@ def append_library(libs, lib)
22
25
  libs + " " + format(LIBARG, lib)
23
26
  end
24
27
 
25
- def manual_ssl_config
26
- ssl_libs_heads_args = {
27
- :unix => [%w[ssl crypto], %w[openssl/ssl.h openssl/err.h]],
28
- :mswin => [%w[ssleay32 eay32], %w[openssl/ssl.h openssl/err.h]],
29
- }
28
+ SSL_HEADS = %w(openssl/ssl.h openssl/err.h)
29
+ SSL_LIBS = case RUBY_PLATFORM
30
+ when /mswin|mingw|bccwin/ ; %w(ssleay32 libeay32)
31
+ else ; %w(crypto ssl)
32
+ end
30
33
 
31
- dc_flags = ['ssl']
32
- dc_flags += ["#{ENV['OPENSSL']}/include", ENV['OPENSSL']] if /linux/ =~ RUBY_PLATFORM and ENV['OPENSSL']
34
+ def dir_config_wrapper(pretty_name, name, idefault=nil, ldefault=nil)
35
+ inc, lib = dir_config(name, idefault, ldefault)
36
+ if inc && lib
37
+ # TODO: Remove when 2.0.0 is the minimum supported version
38
+ # Ruby versions not incorporating the mkmf fix at
39
+ # https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/39717
40
+ # do not properly search for lib directories, and must be corrected
41
+ unless lib && lib[-3, 3] == 'lib'
42
+ @libdir_basename = 'lib'
43
+ inc, lib = dir_config(name, idefault, ldefault)
44
+ end
45
+ unless idefault && ldefault
46
+ abort "-----\nCannot find #{pretty_name} include path #{inc}\n-----" unless inc && inc.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) }
47
+ abort "-----\nCannot find #{pretty_name} library path #{lib}\n-----" unless lib && lib.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) }
48
+ warn "-----\nUsing #{pretty_name} in path #{File.dirname inc}\n-----"
49
+ end
50
+ true
51
+ end
52
+ end
33
53
 
34
- libs, heads = case RUBY_PLATFORM
35
- when /mswin/ ; ssl_libs_heads_args[:mswin]
36
- else ssl_libs_heads_args[:unix]
54
+ def dir_config_search(pretty_name, name, paths, &b)
55
+ paths.each do |p|
56
+ if dir_config_wrapper('OpenSSL', 'ssl', p + '/include', p + '/lib') && yield
57
+ warn "-----\nFound #{pretty_name} in path #{p}\n-----"
58
+ return true
59
+ end
60
+ end
61
+ false
62
+ end
63
+
64
+ def pkg_config_wrapper(pretty_name, name)
65
+ cflags, ldflags, libs = pkg_config(name)
66
+ unless [cflags, ldflags, libs].any?(&:nil?) || [cflags, ldflags, libs].any?(&:empty?)
67
+ warn "-----\nUsing #{pretty_name} from pkg-config #{cflags} && #{ldflags} && #{libs}\n-----"
68
+ true
37
69
  end
38
- dir_config(*dc_flags)
39
- check_libs(libs) and check_heads(heads)
40
70
  end
41
71
 
42
72
  if ENV['CROSS_COMPILING']
43
- openssl_version = ENV.fetch("OPENSSL_VERSION", "1.0.0j")
73
+ openssl_version = ENV.fetch("OPENSSL_VERSION", "1.0.2e")
44
74
  openssl_dir = File.expand_path("~/.rake-compiler/builds/openssl-#{openssl_version}/")
45
- if File.exists?(openssl_dir)
75
+ if File.exist?(openssl_dir)
46
76
  FileUtils.mkdir_p Dir.pwd+"/openssl/"
47
77
  FileUtils.cp Dir[openssl_dir+"/include/openssl/*.h"], Dir.pwd+"/openssl/", :verbose => true
48
78
  FileUtils.cp Dir[openssl_dir+"/lib*.a"], Dir.pwd, :verbose => true
49
79
  $INCFLAGS << " -I#{Dir.pwd}" # for the openssl headers
80
+ add_define "WITH_SSL"
50
81
  else
51
82
  STDERR.puts
52
83
  STDERR.puts "**************************************************************************************"
@@ -55,26 +86,44 @@ if ENV['CROSS_COMPILING']
55
86
  STDERR.puts "**************************************************************************************"
56
87
  STDERR.puts
57
88
  end
58
- end
59
-
60
- # Try to use pkg_config first, fixes #73
61
- if (!ENV['CROSS_COMPILING'] and pkg_config('openssl')) || manual_ssl_config
62
- add_define "WITH_SSL"
63
- else
64
- add_define "WITHOUT_SSL"
89
+ elsif dir_config_wrapper('OpenSSL', 'ssl')
90
+ # If the user has provided a --with-ssl-dir argument, we must respect it or fail.
91
+ add_define 'WITH_SSL' if check_libs(SSL_LIBS) && check_heads(SSL_HEADS)
92
+ elsif pkg_config_wrapper('OpenSSL', 'openssl')
93
+ # If we can detect OpenSSL by pkg-config, use it as the next-best option
94
+ add_define 'WITH_SSL' if check_libs(SSL_LIBS) && check_heads(SSL_HEADS)
95
+ elsif check_libs(SSL_LIBS) && check_heads(SSL_HEADS)
96
+ # If we don't even need any options to find a usable OpenSSL, go with it
97
+ add_define 'WITH_SSL'
98
+ elsif dir_config_search('OpenSSL', 'ssl', ['/usr/local', '/opt/local', '/usr/local/opt/openssl']) do
99
+ check_libs(SSL_LIBS) && check_heads(SSL_HEADS)
100
+ end
101
+ # Finally, look for OpenSSL in alternate locations including MacPorts and HomeBrew
102
+ add_define 'WITH_SSL'
65
103
  end
66
104
 
67
105
  add_define 'BUILD_FOR_RUBY'
68
- add_define 'HAVE_RBTRAP' if have_var('rb_trap_immediate', ['ruby.h', 'rubysig.h'])
69
- add_define "HAVE_TBR" if have_func('rb_thread_blocking_region')# and have_macro('RUBY_UBF_IO', 'ruby.h')
70
- add_define "HAVE_INOTIFY" if inotify = have_func('inotify_init', 'sys/inotify.h')
71
- add_define "HAVE_OLD_INOTIFY" if !inotify && have_macro('__NR_inotify_init', 'sys/syscall.h')
72
- add_define 'HAVE_WRITEV' if have_func('writev', 'sys/uio.h')
73
106
 
107
+ # Ruby features:
108
+
109
+ have_var('rb_trap_immediate', ['ruby.h', 'rubysig.h'])
110
+ have_func('rb_thread_blocking_region')
111
+ have_func('rb_thread_call_without_gvl', 'ruby/thread.h')
112
+ have_func('rb_thread_fd_select')
113
+ have_type('rb_fdset_t', 'ruby/intern.h')
74
114
  have_func('rb_wait_for_single_fd')
75
115
  have_func('rb_enable_interrupt')
76
116
  have_func('rb_time_new')
77
117
 
118
+ # System features:
119
+
120
+ add_define('HAVE_INOTIFY') if inotify = have_func('inotify_init', 'sys/inotify.h')
121
+ add_define('HAVE_OLD_INOTIFY') if !inotify && have_macro('__NR_inotify_init', 'sys/syscall.h')
122
+ have_func('writev', 'sys/uio.h')
123
+ have_func('pipe2', 'unistd.h')
124
+ have_func('accept4', 'sys/socket.h')
125
+ have_const('SOCK_CLOEXEC', 'sys/socket.h')
126
+
78
127
  # Minor platform details between *nix and Windows:
79
128
 
80
129
  if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
@@ -86,7 +135,7 @@ else
86
135
  OS_UNIX = true
87
136
  add_define 'OS_UNIX'
88
137
 
89
- add_define "HAVE_KQUEUE" if have_header("sys/event.h") and have_header("sys/queue.h")
138
+ add_define "HAVE_KQUEUE" if have_header("sys/event.h") && have_header("sys/queue.h")
90
139
  end
91
140
 
92
141
  # Adjust number of file descriptors (FD) on Windows
@@ -106,23 +155,35 @@ when /mswin32/, /mingw32/, /bccwin32/
106
155
  check_libs(%w[kernel32 rpcrt4 gdi32], true)
107
156
 
108
157
  if GNU_CHAIN
109
- CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
158
+ CONFIG['LDSHAREDXX'] = "$(CXX) -shared -static-libgcc -static-libstdc++"
110
159
  else
111
160
  $defs.push "-EHs"
112
161
  $defs.push "-GR"
113
162
  end
114
163
 
164
+ # Newer versions of Ruby already define _WIN32_WINNT, which is needed
165
+ # to get access to newer POSIX networking functions (e.g. getaddrinfo)
166
+ add_define '_WIN32_WINNT=0x0501' unless have_func('getaddrinfo')
167
+
115
168
  when /solaris/
116
169
  add_define 'OS_SOLARIS8'
117
170
  check_libs(%w[nsl socket], true)
118
171
 
119
- if CONFIG['CC'] == 'cc' and `cc -flags 2>&1` =~ /Sun/ # detect SUNWspro compiler
172
+ # If Ruby was compiled for 32-bits, then select() can only handle 1024 fds
173
+ # There is an alternate function, select_large_fdset, that supports more.
174
+ have_func('select_large_fdset', 'sys/select.h')
175
+
176
+ if CONFIG['CC'] == 'cc' && (
177
+ `cc -flags 2>&1` =~ /Sun/ || # detect SUNWspro compiler
178
+ `cc -V 2>&1` =~ /Sun/ # detect Solaris Studio compiler
179
+ )
120
180
  # SUN CHAIN
121
181
  add_define 'CC_SUNWspro'
122
182
  $preload = ["\nCXX = CC"] # hack a CXX= line into the makefile
123
183
  $CFLAGS = CONFIG['CFLAGS'] = "-KPIC"
124
184
  CONFIG['CCDLFLAGS'] = "-KPIC"
125
185
  CONFIG['LDSHARED'] = "$(CXX) -G -KPIC -lCstd"
186
+ CONFIG['LDSHAREDXX'] = "$(CXX) -G -KPIC -lCstd"
126
187
  else
127
188
  # GNU CHAIN
128
189
  # on Unix we need a g++ link, not gcc.
@@ -137,6 +198,8 @@ when /openbsd/
137
198
  CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
138
199
 
139
200
  when /darwin/
201
+ add_define 'OS_DARWIN'
202
+
140
203
  # on Unix we need a g++ link, not gcc.
141
204
  # Ff line contributed by Daniel Harple.
142
205
  CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
@@ -164,13 +227,43 @@ else
164
227
  CONFIG['LDSHARED'] = "$(CXX) -shared"
165
228
  end
166
229
 
230
+ # Platform-specific time functions
231
+ if have_func('clock_gettime')
232
+ # clock_gettime is POSIX, but the monotonic clocks are not
233
+ have_const('CLOCK_MONOTONIC_RAW', 'time.h') # Linux
234
+ have_const('CLOCK_MONOTONIC', 'time.h') # Linux, Solaris, BSDs
235
+ else
236
+ have_func('gethrtime') # Older Solaris and HP-UX
237
+ end
167
238
 
168
- # solaris c++ compiler doesn't have make_pair()
239
+ # Hack so that try_link will test with a C++ compiler instead of a C compiler
169
240
  TRY_LINK.sub!('$(CC)', '$(CXX)')
241
+
242
+ # This is our wishlist. We use whichever flags work on the host.
243
+ # In the future, add -Werror to make sure all warnings are resolved.
244
+ # deprecated-declarations are used in OS X OpenSSL
245
+ # ignored-qualifiers are used by the Bindings (would-be void *)
246
+ # unused-result because GCC 4.6 no longer silences (void) ignore_this(function)
247
+ # address because on Windows, rb_fd_select checks if &fds is non-NULL, which it cannot be
248
+ %w(
249
+ -Wall
250
+ -Wextra
251
+ -Wno-deprecated-declarations
252
+ -Wno-ignored-qualifiers
253
+ -Wno-unused-result
254
+ -Wno-address
255
+ ).select do |flag|
256
+ try_link('int main() {return 0;}', flag)
257
+ end.each do |flag|
258
+ CONFIG['CXXFLAGS'] << ' ' << flag
259
+ end
260
+ puts "CXXFLAGS=#{CONFIG['CXXFLAGS']}"
261
+
262
+ # Solaris C++ compiler doesn't have make_pair()
170
263
  add_define 'HAVE_MAKE_PAIR' if try_link(<<SRC, '-lstdc++')
171
264
  #include <utility>
172
265
  using namespace std;
173
- int main(){ pair<int,int> tuple = make_pair(1,2); }
266
+ int main(){ pair<const int,int> tuple = make_pair(1,2); }
174
267
  SRC
175
268
  TRY_LINK.sub!('$(CXX)', '$(CC)')
176
269