eventmachine-le 1.1.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/.yardopts +7 -0
- data/GNU +281 -0
- data/LICENSE +60 -0
- data/README.md +80 -0
- data/Rakefile +19 -0
- data/eventmachine-le.gemspec +42 -0
- data/ext/binder.cpp +124 -0
- data/ext/binder.h +46 -0
- data/ext/cmain.cpp +841 -0
- data/ext/ed.cpp +1995 -0
- data/ext/ed.h +424 -0
- data/ext/em.cpp +2377 -0
- data/ext/em.h +243 -0
- data/ext/eventmachine.h +126 -0
- data/ext/extconf.rb +166 -0
- data/ext/fastfilereader/extconf.rb +94 -0
- data/ext/fastfilereader/mapper.cpp +214 -0
- data/ext/fastfilereader/mapper.h +59 -0
- data/ext/fastfilereader/rubymain.cpp +127 -0
- data/ext/kb.cpp +79 -0
- data/ext/page.cpp +107 -0
- data/ext/page.h +51 -0
- data/ext/pipe.cpp +347 -0
- data/ext/project.h +155 -0
- data/ext/rubymain.cpp +1269 -0
- data/ext/ssl.cpp +468 -0
- data/ext/ssl.h +94 -0
- data/lib/em/buftok.rb +110 -0
- data/lib/em/callback.rb +58 -0
- data/lib/em/channel.rb +64 -0
- data/lib/em/completion.rb +304 -0
- data/lib/em/connection.rb +728 -0
- data/lib/em/deferrable.rb +210 -0
- data/lib/em/deferrable/pool.rb +2 -0
- data/lib/em/file_watch.rb +73 -0
- data/lib/em/future.rb +61 -0
- data/lib/em/iterator.rb +313 -0
- data/lib/em/messages.rb +66 -0
- data/lib/em/pool.rb +151 -0
- data/lib/em/process_watch.rb +45 -0
- data/lib/em/processes.rb +123 -0
- data/lib/em/protocols.rb +37 -0
- data/lib/em/protocols/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +279 -0
- data/lib/em/protocols/httpclient2.rb +600 -0
- data/lib/em/protocols/line_and_text.rb +125 -0
- data/lib/em/protocols/line_protocol.rb +29 -0
- data/lib/em/protocols/linetext2.rb +161 -0
- data/lib/em/protocols/memcache.rb +331 -0
- data/lib/em/protocols/object_protocol.rb +46 -0
- data/lib/em/protocols/postgres3.rb +246 -0
- data/lib/em/protocols/saslauth.rb +175 -0
- data/lib/em/protocols/smtpclient.rb +365 -0
- data/lib/em/protocols/smtpserver.rb +663 -0
- data/lib/em/protocols/socks4.rb +66 -0
- data/lib/em/protocols/stomp.rb +202 -0
- data/lib/em/protocols/tcptest.rb +54 -0
- data/lib/em/queue.rb +71 -0
- data/lib/em/resolver.rb +195 -0
- data/lib/em/spawnable.rb +84 -0
- data/lib/em/streamer.rb +118 -0
- data/lib/em/threaded_resource.rb +90 -0
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +106 -0
- data/lib/em/version.rb +3 -0
- data/lib/eventmachine-le.rb +10 -0
- data/lib/eventmachine.rb +1548 -0
- data/rakelib/cpp.rake_example +77 -0
- data/rakelib/package.rake +98 -0
- data/rakelib/test.rake +8 -0
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/em_test_helper.rb +143 -0
- data/tests/test_attach.rb +148 -0
- data/tests/test_basic.rb +294 -0
- data/tests/test_channel.rb +62 -0
- data/tests/test_completion.rb +177 -0
- data/tests/test_connection_count.rb +33 -0
- data/tests/test_defer.rb +18 -0
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_epoll.rb +134 -0
- data/tests/test_error_handler.rb +38 -0
- data/tests/test_exc.rb +28 -0
- data/tests/test_file_watch.rb +65 -0
- data/tests/test_futures.rb +170 -0
- data/tests/test_get_sock_opt.rb +37 -0
- data/tests/test_handler_check.rb +35 -0
- data/tests/test_hc.rb +155 -0
- data/tests/test_httpclient.rb +190 -0
- data/tests/test_httpclient2.rb +128 -0
- data/tests/test_inactivity_timeout.rb +54 -0
- data/tests/test_ipv4.rb +125 -0
- data/tests/test_ipv6.rb +131 -0
- data/tests/test_iterator.rb +110 -0
- data/tests/test_kb.rb +34 -0
- data/tests/test_line_protocol.rb +33 -0
- data/tests/test_ltp.rb +138 -0
- data/tests/test_ltp2.rb +288 -0
- data/tests/test_next_tick.rb +104 -0
- data/tests/test_object_protocol.rb +36 -0
- data/tests/test_pause.rb +78 -0
- data/tests/test_pending_connect_timeout.rb +52 -0
- data/tests/test_pool.rb +196 -0
- data/tests/test_process_watch.rb +48 -0
- data/tests/test_processes.rb +133 -0
- data/tests/test_proxy_connection.rb +168 -0
- data/tests/test_pure.rb +88 -0
- data/tests/test_queue.rb +50 -0
- data/tests/test_resolver.rb +55 -0
- data/tests/test_running.rb +14 -0
- data/tests/test_sasl.rb +47 -0
- data/tests/test_send_file.rb +217 -0
- data/tests/test_servers.rb +33 -0
- data/tests/test_set_sock_opt.rb +41 -0
- data/tests/test_shutdown_hooks.rb +23 -0
- data/tests/test_smtpclient.rb +55 -0
- data/tests/test_smtpserver.rb +120 -0
- data/tests/test_spawn.rb +293 -0
- data/tests/test_ssl_args.rb +78 -0
- data/tests/test_ssl_methods.rb +48 -0
- data/tests/test_ssl_verify.rb +82 -0
- data/tests/test_threaded_resource.rb +55 -0
- data/tests/test_tick_loop.rb +59 -0
- data/tests/test_timers.rb +180 -0
- data/tests/test_ud.rb +8 -0
- data/tests/test_udp46.rb +53 -0
- data/tests/test_unbind_reason.rb +48 -0
- metadata +390 -0
data/ext/em.h
ADDED
@@ -0,0 +1,243 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
|
3
|
+
$Id$
|
4
|
+
|
5
|
+
File: em.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
|
+
#ifndef __EventMachine__H_
|
21
|
+
#define __EventMachine__H_
|
22
|
+
|
23
|
+
#ifdef BUILD_FOR_RUBY
|
24
|
+
#include <ruby.h>
|
25
|
+
#define EmSelect rb_thread_select
|
26
|
+
|
27
|
+
#if defined(HAVE_RBTRAP)
|
28
|
+
#include <rubysig.h>
|
29
|
+
#elif defined(HAVE_RB_THREAD_CHECK_INTS)
|
30
|
+
extern "C" {
|
31
|
+
void rb_enable_interrupt(void);
|
32
|
+
void rb_disable_interrupt(void);
|
33
|
+
}
|
34
|
+
|
35
|
+
#define TRAP_BEG rb_enable_interrupt()
|
36
|
+
#define TRAP_END do { rb_disable_interrupt(); rb_thread_check_ints(); } while(0)
|
37
|
+
#else
|
38
|
+
#define TRAP_BEG
|
39
|
+
#define TRAP_END
|
40
|
+
#endif
|
41
|
+
|
42
|
+
// 1.9.0 compat
|
43
|
+
#ifndef RUBY_UBF_IO
|
44
|
+
#define RUBY_UBF_IO RB_UBF_DFL
|
45
|
+
#endif
|
46
|
+
#ifndef RSTRING_PTR
|
47
|
+
#define RSTRING_PTR(str) RSTRING(str)->ptr
|
48
|
+
#endif
|
49
|
+
#ifndef RSTRING_LEN
|
50
|
+
#define RSTRING_LEN(str) RSTRING(str)->len
|
51
|
+
#endif
|
52
|
+
#ifndef RSTRING_LENINT
|
53
|
+
#define RSTRING_LENINT(str) RSTRING_LEN(str)
|
54
|
+
#endif
|
55
|
+
#else
|
56
|
+
#define EmSelect select
|
57
|
+
#endif
|
58
|
+
|
59
|
+
class EventableDescriptor;
|
60
|
+
class InotifyDescriptor;
|
61
|
+
|
62
|
+
|
63
|
+
/********************
|
64
|
+
class EventMachine_t
|
65
|
+
********************/
|
66
|
+
|
67
|
+
class EventMachine_t
|
68
|
+
{
|
69
|
+
public:
|
70
|
+
/* Internal helper to convert strings to internet addresses.
|
71
|
+
* IPv6-aware.
|
72
|
+
* Not reentrant or threadsafe, optimized for speed.
|
73
|
+
*/
|
74
|
+
static struct sockaddr *name2address (const char *server, int port, int *family, int *bind_size);
|
75
|
+
|
76
|
+
public:
|
77
|
+
EventMachine_t (EMCallback);
|
78
|
+
virtual ~EventMachine_t();
|
79
|
+
|
80
|
+
void Run();
|
81
|
+
void ScheduleHalt();
|
82
|
+
void SignalLoopBreaker();
|
83
|
+
const unsigned long InstallOneshotTimer (int);
|
84
|
+
const unsigned long ConnectToServer (const char *, int, const char *, int);
|
85
|
+
const unsigned long ConnectToUnixServer (const char *);
|
86
|
+
|
87
|
+
const unsigned long CreateTcpServer (const char *, int);
|
88
|
+
const unsigned long OpenDatagramSocket (const char *, int);
|
89
|
+
const unsigned long CreateUnixDomainServer (const char*);
|
90
|
+
const unsigned long OpenKeyboard();
|
91
|
+
//const char *Popen (const char*, const char*);
|
92
|
+
const unsigned long Socketpair (char* const*);
|
93
|
+
|
94
|
+
void Add (EventableDescriptor*);
|
95
|
+
void Modify (EventableDescriptor*);
|
96
|
+
void Deregister (EventableDescriptor*);
|
97
|
+
|
98
|
+
const unsigned long AttachFD (int, bool);
|
99
|
+
int DetachFD (EventableDescriptor*);
|
100
|
+
const unsigned long AttachServerFD (int);
|
101
|
+
|
102
|
+
void ArmKqueueWriter (EventableDescriptor*);
|
103
|
+
void ArmKqueueReader (EventableDescriptor*);
|
104
|
+
|
105
|
+
void SetTimerQuantum (int);
|
106
|
+
static void SetuidString (const char*);
|
107
|
+
static int SetRlimitNofile (int);
|
108
|
+
|
109
|
+
pid_t SubprocessPid;
|
110
|
+
int SubprocessExitStatus;
|
111
|
+
|
112
|
+
int GetConnectionCount();
|
113
|
+
float GetHeartbeatInterval();
|
114
|
+
int SetHeartbeatInterval(float);
|
115
|
+
|
116
|
+
const unsigned long WatchFile (const char*);
|
117
|
+
void UnwatchFile (int);
|
118
|
+
void UnwatchFile (const unsigned long);
|
119
|
+
|
120
|
+
#ifdef HAVE_KQUEUE
|
121
|
+
void _HandleKqueueFileEvent (struct kevent*);
|
122
|
+
void _RegisterKqueueFileEvent(int);
|
123
|
+
#endif
|
124
|
+
|
125
|
+
const unsigned long WatchPid (int);
|
126
|
+
void UnwatchPid (int);
|
127
|
+
void UnwatchPid (const unsigned long);
|
128
|
+
|
129
|
+
#ifdef HAVE_KQUEUE
|
130
|
+
void _HandleKqueuePidEvent (struct kevent*);
|
131
|
+
#endif
|
132
|
+
|
133
|
+
uint64_t GetCurrentLoopTime() { return MyCurrentLoopTime; }
|
134
|
+
|
135
|
+
// Temporary:
|
136
|
+
void _UseEpoll();
|
137
|
+
void _UseKqueue();
|
138
|
+
|
139
|
+
bool UsingKqueue() { return bKqueue; }
|
140
|
+
bool UsingEpoll() { return bEpoll; }
|
141
|
+
|
142
|
+
void QueueHeartbeat(EventableDescriptor*);
|
143
|
+
void ClearHeartbeat(uint64_t, EventableDescriptor*);
|
144
|
+
|
145
|
+
uint64_t GetRealTime();
|
146
|
+
|
147
|
+
private:
|
148
|
+
bool _RunOnce();
|
149
|
+
void _RunTimers();
|
150
|
+
void _UpdateTime();
|
151
|
+
void _AddNewDescriptors();
|
152
|
+
void _ModifyDescriptors();
|
153
|
+
void _InitializeLoopBreaker();
|
154
|
+
void _CleanupSockets();
|
155
|
+
|
156
|
+
bool _RunSelectOnce();
|
157
|
+
bool _RunEpollOnce();
|
158
|
+
bool _RunKqueueOnce();
|
159
|
+
|
160
|
+
void _ModifyEpollEvent (EventableDescriptor*);
|
161
|
+
void _DispatchHeartbeats();
|
162
|
+
timeval _TimeTilNextEvent();
|
163
|
+
void _CleanBadDescriptors();
|
164
|
+
|
165
|
+
public:
|
166
|
+
void _ReadLoopBreaker();
|
167
|
+
void _ReadInotifyEvents();
|
168
|
+
int NumCloseScheduled;
|
169
|
+
|
170
|
+
private:
|
171
|
+
enum {
|
172
|
+
MaxEpollDescriptors = 64*1024,
|
173
|
+
MaxEvents = 4096
|
174
|
+
};
|
175
|
+
int HeartbeatInterval;
|
176
|
+
EMCallback EventCallback;
|
177
|
+
|
178
|
+
class Timer_t: public Bindable_t {
|
179
|
+
};
|
180
|
+
|
181
|
+
multimap<uint64_t, Timer_t> Timers;
|
182
|
+
multimap<uint64_t, EventableDescriptor*> Heartbeats;
|
183
|
+
map<int, Bindable_t*> Files;
|
184
|
+
map<int, Bindable_t*> Pids;
|
185
|
+
vector<EventableDescriptor*> Descriptors;
|
186
|
+
vector<EventableDescriptor*> NewDescriptors;
|
187
|
+
set<EventableDescriptor*> ModifiedDescriptors;
|
188
|
+
|
189
|
+
uint64_t NextHeartbeatTime;
|
190
|
+
|
191
|
+
int LoopBreakerReader;
|
192
|
+
int LoopBreakerWriter;
|
193
|
+
#ifdef OS_WIN32
|
194
|
+
struct sockaddr_in LoopBreakerTarget;
|
195
|
+
#endif
|
196
|
+
|
197
|
+
timeval Quantum;
|
198
|
+
|
199
|
+
uint64_t MyCurrentLoopTime;
|
200
|
+
|
201
|
+
#ifdef OS_WIN32
|
202
|
+
unsigned TickCountTickover;
|
203
|
+
unsigned LastTickCount;
|
204
|
+
#endif
|
205
|
+
|
206
|
+
private:
|
207
|
+
bool bTerminateSignalReceived;
|
208
|
+
|
209
|
+
bool bEpoll;
|
210
|
+
int epfd; // Epoll file-descriptor
|
211
|
+
#ifdef HAVE_EPOLL
|
212
|
+
struct epoll_event epoll_events [MaxEvents];
|
213
|
+
#endif
|
214
|
+
|
215
|
+
bool bKqueue;
|
216
|
+
int kqfd; // Kqueue file-descriptor
|
217
|
+
#ifdef HAVE_KQUEUE
|
218
|
+
struct kevent Karray [MaxEvents];
|
219
|
+
#endif
|
220
|
+
|
221
|
+
InotifyDescriptor *inotify; // pollable descriptor for our inotify instance
|
222
|
+
};
|
223
|
+
|
224
|
+
|
225
|
+
/*******************
|
226
|
+
struct SelectData_t
|
227
|
+
*******************/
|
228
|
+
|
229
|
+
struct SelectData_t
|
230
|
+
{
|
231
|
+
SelectData_t();
|
232
|
+
|
233
|
+
int _Select();
|
234
|
+
|
235
|
+
int maxsocket;
|
236
|
+
fd_set fdreads;
|
237
|
+
fd_set fdwrites;
|
238
|
+
fd_set fderrors;
|
239
|
+
timeval tv;
|
240
|
+
int nSockets;
|
241
|
+
};
|
242
|
+
|
243
|
+
#endif // __EventMachine__H_
|
data/ext/eventmachine.h
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
|
3
|
+
$Id$
|
4
|
+
|
5
|
+
File: eventmachine.h
|
6
|
+
Date: 15Apr06
|
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
|
+
#ifndef __EVMA_EventMachine__H_
|
21
|
+
#define __EVMA_EventMachine__H_
|
22
|
+
|
23
|
+
#if __cplusplus
|
24
|
+
extern "C" {
|
25
|
+
#endif
|
26
|
+
|
27
|
+
enum { // Event names
|
28
|
+
EM_TIMER_FIRED = 100,
|
29
|
+
EM_CONNECTION_READ = 101,
|
30
|
+
EM_CONNECTION_UNBOUND = 102,
|
31
|
+
EM_CONNECTION_ACCEPTED = 103,
|
32
|
+
EM_CONNECTION_COMPLETED = 104,
|
33
|
+
EM_LOOPBREAK_SIGNAL = 105,
|
34
|
+
EM_CONNECTION_NOTIFY_READABLE = 106,
|
35
|
+
EM_CONNECTION_NOTIFY_WRITABLE = 107,
|
36
|
+
EM_SSL_HANDSHAKE_COMPLETED = 108,
|
37
|
+
EM_SSL_VERIFY = 109,
|
38
|
+
EM_PROXY_TARGET_UNBOUND = 110,
|
39
|
+
EM_PROXY_COMPLETED = 111,
|
40
|
+
EM_CONNECTION_SENDERROR = 112
|
41
|
+
|
42
|
+
};
|
43
|
+
|
44
|
+
void evma_initialize_library (EMCallback);
|
45
|
+
void evma_run_machine();
|
46
|
+
void evma_release_library();
|
47
|
+
const unsigned long evma_install_oneshot_timer (int seconds);
|
48
|
+
const unsigned long evma_connect_to_server (const char *bind_addr, int bind_port, const char *server, int port);
|
49
|
+
const unsigned long evma_connect_to_unix_server (const char *server);
|
50
|
+
|
51
|
+
const unsigned long evma_attach_fd (int file_descriptor, int watch_mode);
|
52
|
+
int evma_detach_fd (const unsigned long binding);
|
53
|
+
const unsigned long evma_attach_server_fd (int file_descriptor);
|
54
|
+
int evma_get_file_descriptor (const unsigned long binding);
|
55
|
+
int evma_is_notify_readable (const unsigned long binding);
|
56
|
+
void evma_set_notify_readable (const unsigned long binding, int mode);
|
57
|
+
int evma_is_notify_writable (const unsigned long binding);
|
58
|
+
void evma_set_notify_writable (const unsigned long binding, int mode);
|
59
|
+
void evma_set_error_handling (const unsigned long binding, int mode);
|
60
|
+
|
61
|
+
int evma_pause(const unsigned long binding);
|
62
|
+
int evma_is_paused(const unsigned long binding);
|
63
|
+
int evma_resume(const unsigned long binding);
|
64
|
+
|
65
|
+
int evma_num_close_scheduled();
|
66
|
+
|
67
|
+
void evma_stop_tcp_server (const unsigned long signature);
|
68
|
+
const unsigned long evma_create_tcp_server (const char *address, int port);
|
69
|
+
const unsigned long evma_create_unix_domain_server (const char *filename);
|
70
|
+
const unsigned long evma_open_datagram_socket (const char *server, int port);
|
71
|
+
const unsigned long evma_open_keyboard();
|
72
|
+
void evma_set_tls_parms (const unsigned long binding, const char *privatekey_filename, const char *certchain_filenane, int verify_peer);
|
73
|
+
void evma_start_tls (const unsigned long binding);
|
74
|
+
|
75
|
+
#ifdef WITH_SSL
|
76
|
+
X509 *evma_get_peer_cert (const unsigned long binding);
|
77
|
+
void evma_accept_ssl_peer (const unsigned long binding);
|
78
|
+
#endif
|
79
|
+
|
80
|
+
int evma_get_peername (const unsigned long binding, struct sockaddr_storage*, socklen_t *len);
|
81
|
+
int evma_get_sockname (const unsigned long binding, struct sockaddr_storage*, socklen_t *len);
|
82
|
+
int evma_get_subprocess_pid (const unsigned long binding, pid_t*);
|
83
|
+
int evma_get_subprocess_status (const unsigned long binding, int*);
|
84
|
+
int evma_get_connection_count();
|
85
|
+
int evma_send_data_to_connection (const unsigned long binding, const char *data, int data_length);
|
86
|
+
int evma_send_datagram (const unsigned long binding, const char *data, int data_length, const char *address, int port);
|
87
|
+
float evma_get_comm_inactivity_timeout (const unsigned long binding);
|
88
|
+
int evma_set_comm_inactivity_timeout (const unsigned long binding, float value);
|
89
|
+
float evma_get_pending_connect_timeout (const unsigned long binding);
|
90
|
+
int evma_set_pending_connect_timeout (const unsigned long binding, float value);
|
91
|
+
int evma_get_outbound_data_size (const unsigned long binding);
|
92
|
+
int evma_send_file_data_to_connection (const unsigned long binding, const char *filename);
|
93
|
+
|
94
|
+
void evma_close_connection (const unsigned long binding, int after_writing);
|
95
|
+
int evma_report_connection_error_status (const unsigned long binding);
|
96
|
+
void evma_signal_loopbreak();
|
97
|
+
void evma_set_timer_quantum (int);
|
98
|
+
void evma_setuid_string (const char *username);
|
99
|
+
void evma_stop_machine();
|
100
|
+
float evma_get_heartbeat_interval();
|
101
|
+
int evma_set_heartbeat_interval(float);
|
102
|
+
|
103
|
+
const unsigned long evma_popen (char * const*cmd_strings);
|
104
|
+
|
105
|
+
const unsigned long evma_watch_filename (const char *fname);
|
106
|
+
void evma_unwatch_filename (const unsigned long);
|
107
|
+
|
108
|
+
const unsigned long evma_watch_pid (int);
|
109
|
+
void evma_unwatch_pid (const unsigned long);
|
110
|
+
|
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
|
+
|
114
|
+
int evma_set_rlimit_nofile (int n_files);
|
115
|
+
|
116
|
+
void evma_set_epoll (int use);
|
117
|
+
void evma_set_kqueue (int use);
|
118
|
+
|
119
|
+
uint64_t evma_get_current_loop_time();
|
120
|
+
#if __cplusplus
|
121
|
+
}
|
122
|
+
#endif
|
123
|
+
|
124
|
+
|
125
|
+
#endif // __EventMachine__H_
|
126
|
+
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'mkmf'
|
3
|
+
|
4
|
+
def check_libs libs = [], fatal = false
|
5
|
+
libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def check_heads heads = [], fatal = false
|
9
|
+
heads.all? { |head| have_header(head) || (abort("could not find header: #{head}") if fatal)}
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_define(name)
|
13
|
+
$defs.push("-D#{name}")
|
14
|
+
end
|
15
|
+
|
16
|
+
##
|
17
|
+
# OpenSSL:
|
18
|
+
|
19
|
+
# override append_library, so it actually appends (instead of prepending)
|
20
|
+
# this fixes issues with linking ssl, since libcrypto depends on symbols in libssl
|
21
|
+
def append_library(libs, lib)
|
22
|
+
libs + " " + format(LIBARG, lib)
|
23
|
+
end
|
24
|
+
|
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
|
+
}
|
30
|
+
|
31
|
+
dc_flags = ['ssl']
|
32
|
+
dc_flags += ["#{ENV['OPENSSL']}/include", ENV['OPENSSL']] if /linux/ =~ RUBY_PLATFORM and ENV['OPENSSL']
|
33
|
+
|
34
|
+
libs, heads = case RUBY_PLATFORM
|
35
|
+
when /mswin/ ; ssl_libs_heads_args[:mswin]
|
36
|
+
else ssl_libs_heads_args[:unix]
|
37
|
+
end
|
38
|
+
dir_config(*dc_flags)
|
39
|
+
check_libs(libs) and check_heads(heads)
|
40
|
+
end
|
41
|
+
|
42
|
+
if ENV['CROSS_COMPILING']
|
43
|
+
openssl_dir = File.expand_path("~/.rake-compiler/builds/openssl-1.0.0a/")
|
44
|
+
if File.exists?(openssl_dir)
|
45
|
+
FileUtils.mkdir_p Dir.pwd+"/openssl/"
|
46
|
+
FileUtils.cp Dir[openssl_dir+"/include/openssl/*.h"], Dir.pwd+"/openssl/", :verbose => true
|
47
|
+
FileUtils.cp Dir[openssl_dir+"/lib*.a"], Dir.pwd, :verbose => true
|
48
|
+
$INCFLAGS << " -I#{Dir.pwd}" # for the openssl headers
|
49
|
+
else
|
50
|
+
STDERR.puts
|
51
|
+
STDERR.puts "**************************************************************************************"
|
52
|
+
STDERR.puts "**** Cross-compiled OpenSSL not found"
|
53
|
+
STDERR.puts "**** Run: hg clone http://bitbucket.org/ged/ruby-pg && cd ruby-pg && rake openssl_libs"
|
54
|
+
STDERR.puts "**************************************************************************************"
|
55
|
+
STDERR.puts
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Try to use pkg_config first, fixes #73
|
60
|
+
if (!ENV['CROSS_COMPILING'] and pkg_config('openssl')) || manual_ssl_config
|
61
|
+
add_define "WITH_SSL"
|
62
|
+
else
|
63
|
+
add_define "WITHOUT_SSL"
|
64
|
+
end
|
65
|
+
|
66
|
+
add_define 'BUILD_FOR_RUBY'
|
67
|
+
add_define 'HAVE_RBTRAP' if have_var('rb_trap_immediate', ['ruby.h', 'rubysig.h'])
|
68
|
+
add_define "HAVE_TBR" if have_func('rb_thread_blocking_region')# and have_macro('RUBY_UBF_IO', 'ruby.h')
|
69
|
+
add_define "HAVE_INOTIFY" if inotify = have_func('inotify_init', 'sys/inotify.h')
|
70
|
+
add_define "HAVE_OLD_INOTIFY" if !inotify && have_macro('__NR_inotify_init', 'sys/syscall.h')
|
71
|
+
add_define 'HAVE_WRITEV' if have_func('writev', 'sys/uio.h')
|
72
|
+
|
73
|
+
have_func('rb_thread_check_ints')
|
74
|
+
have_func('rb_time_new')
|
75
|
+
|
76
|
+
# Minor platform details between *nix and Windows:
|
77
|
+
|
78
|
+
if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
|
79
|
+
GNU_CHAIN = ENV['CROSS_COMPILING'] or $1 == 'mingw'
|
80
|
+
OS_WIN32 = true
|
81
|
+
add_define "OS_WIN32"
|
82
|
+
else
|
83
|
+
GNU_CHAIN = true
|
84
|
+
OS_UNIX = true
|
85
|
+
add_define 'OS_UNIX'
|
86
|
+
|
87
|
+
add_define "HAVE_KQUEUE" if have_header("sys/event.h") and have_header("sys/queue.h")
|
88
|
+
end
|
89
|
+
|
90
|
+
# Main platform invariances:
|
91
|
+
|
92
|
+
case RUBY_PLATFORM
|
93
|
+
when /mswin32/, /mingw32/, /bccwin32/
|
94
|
+
check_heads(%w[windows.h winsock.h], true)
|
95
|
+
check_libs(%w[kernel32 rpcrt4 gdi32], true)
|
96
|
+
|
97
|
+
if GNU_CHAIN
|
98
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
|
99
|
+
else
|
100
|
+
$defs.push "-EHs"
|
101
|
+
$defs.push "-GR"
|
102
|
+
end
|
103
|
+
|
104
|
+
when /solaris/
|
105
|
+
add_define 'OS_SOLARIS8'
|
106
|
+
check_libs(%w[nsl socket], true)
|
107
|
+
|
108
|
+
if CONFIG['CC'] == 'cc' and `cc -flags 2>&1` =~ /Sun/ # detect SUNWspro compiler
|
109
|
+
# SUN CHAIN
|
110
|
+
add_define 'CC_SUNWspro'
|
111
|
+
$preload = ["\nCXX = CC"] # hack a CXX= line into the makefile
|
112
|
+
$CFLAGS = CONFIG['CFLAGS'] = "-KPIC"
|
113
|
+
CONFIG['CCDLFLAGS'] = "-KPIC"
|
114
|
+
CONFIG['LDSHARED'] = "$(CXX) -G -KPIC -lCstd"
|
115
|
+
else
|
116
|
+
# GNU CHAIN
|
117
|
+
# on Unix we need a g++ link, not gcc.
|
118
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared"
|
119
|
+
end
|
120
|
+
|
121
|
+
when /openbsd/
|
122
|
+
# OpenBSD branch contributed by Guillaume Sellier.
|
123
|
+
|
124
|
+
# on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
|
125
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++ -fPIC"
|
126
|
+
CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
|
127
|
+
|
128
|
+
when /darwin/
|
129
|
+
# on Unix we need a g++ link, not gcc.
|
130
|
+
# Ff line contributed by Daniel Harple.
|
131
|
+
CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
|
132
|
+
|
133
|
+
when /linux/
|
134
|
+
add_define 'HAVE_EPOLL' if have_func('epoll_create', 'sys/epoll.h')
|
135
|
+
|
136
|
+
# on Unix we need a g++ link, not gcc.
|
137
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared"
|
138
|
+
|
139
|
+
when /aix/
|
140
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared -Wl,-G -Wl,-brtl"
|
141
|
+
|
142
|
+
when /cygwin/
|
143
|
+
# For rubies built with Cygwin, CXX may be set to CC, which is just
|
144
|
+
# a wrapper for gcc.
|
145
|
+
# This will compile, but it will not link to the C++ std library.
|
146
|
+
# Explicitly set CXX to use g++.
|
147
|
+
CONFIG['CXX'] = "g++"
|
148
|
+
# on Unix we need a g++ link, not gcc.
|
149
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared"
|
150
|
+
|
151
|
+
else
|
152
|
+
# on Unix we need a g++ link, not gcc.
|
153
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared"
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
# solaris c++ compiler doesn't have make_pair()
|
158
|
+
TRY_LINK.sub!('$(CC)', '$(CXX)')
|
159
|
+
add_define 'HAVE_MAKE_PAIR' if try_link(<<SRC, '-lstdc++')
|
160
|
+
#include <utility>
|
161
|
+
using namespace std;
|
162
|
+
int main(){ pair<int,int> tuple = make_pair(1,2); }
|
163
|
+
SRC
|
164
|
+
TRY_LINK.sub!('$(CXX)', '$(CC)')
|
165
|
+
|
166
|
+
create_makefile "rubyeventmachine"
|