eventmachine 0.12.8-x86-mswin32-60 → 0.12.10-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/.gitignore +14 -13
  2. data/Rakefile +374 -264
  3. data/eventmachine.gemspec +4 -5
  4. data/ext/binder.cpp +125 -126
  5. data/ext/binder.h +46 -48
  6. data/ext/cmain.cpp +184 -42
  7. data/ext/cplusplus.cpp +202 -202
  8. data/ext/ed.cpp +242 -81
  9. data/ext/ed.h +39 -22
  10. data/ext/em.cpp +127 -108
  11. data/ext/em.h +27 -18
  12. data/ext/emwin.cpp +3 -3
  13. data/ext/eventmachine.h +49 -38
  14. data/ext/eventmachine_cpp.h +96 -96
  15. data/ext/extconf.rb +147 -132
  16. data/ext/fastfilereader/extconf.rb +82 -76
  17. data/ext/project.h +151 -140
  18. data/ext/rubymain.cpp +222 -103
  19. data/ext/ssl.cpp +460 -460
  20. data/ext/ssl.h +94 -94
  21. data/java/src/com/rubyeventmachine/EmReactor.java +570 -423
  22. data/java/src/com/rubyeventmachine/EventableChannel.java +69 -57
  23. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -171
  24. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -244
  25. data/java/src/com/rubyeventmachine/{Application.java → application/Application.java} +194 -200
  26. data/java/src/com/rubyeventmachine/{Connection.java → application/Connection.java} +74 -74
  27. data/java/src/com/rubyeventmachine/{ConnectionFactory.java → application/ConnectionFactory.java} +36 -36
  28. data/java/src/com/rubyeventmachine/{DefaultConnectionFactory.java → application/DefaultConnectionFactory.java} +46 -46
  29. data/java/src/com/rubyeventmachine/{PeriodicTimer.java → application/PeriodicTimer.java} +38 -38
  30. data/java/src/com/rubyeventmachine/{Timer.java → application/Timer.java} +54 -54
  31. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -108
  32. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -146
  33. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -53
  34. data/java/src/com/rubyeventmachine/tests/TestServers.java +75 -74
  35. data/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -89
  36. data/lib/em/connection.rb +71 -12
  37. data/lib/em/deferrable.rb +191 -186
  38. data/lib/em/protocols.rb +36 -35
  39. data/lib/em/protocols/httpclient2.rb +590 -582
  40. data/lib/em/protocols/line_and_text.rb +125 -126
  41. data/lib/em/protocols/linetext2.rb +161 -160
  42. data/lib/em/protocols/object_protocol.rb +45 -39
  43. data/lib/em/protocols/smtpclient.rb +357 -331
  44. data/lib/em/protocols/socks4.rb +66 -0
  45. data/lib/em/queue.rb +60 -60
  46. data/lib/em/timers.rb +56 -55
  47. data/lib/em/version.rb +1 -1
  48. data/lib/eventmachine.rb +125 -169
  49. data/lib/jeventmachine.rb +257 -142
  50. data/tasks/{cpp.rake → cpp.rake_example} +76 -76
  51. data/tests/test_attach.rb +125 -100
  52. data/tests/test_basic.rb +1 -2
  53. data/tests/test_connection_count.rb +34 -44
  54. data/tests/test_epoll.rb +0 -2
  55. data/tests/test_get_sock_opt.rb +30 -0
  56. data/tests/test_httpclient2.rb +3 -3
  57. data/tests/test_inactivity_timeout.rb +21 -1
  58. data/tests/test_ltp.rb +182 -188
  59. data/tests/test_next_tick.rb +0 -2
  60. data/tests/test_pause.rb +70 -0
  61. data/tests/test_pending_connect_timeout.rb +48 -0
  62. data/tests/test_ssl_args.rb +78 -67
  63. data/tests/test_timers.rb +162 -141
  64. metadata +13 -11
  65. data/tasks/project.rake +0 -79
  66. data/tasks/tests.rake +0 -193
data/ext/em.h CHANGED
@@ -34,8 +34,16 @@ See the file COPYING for complete licensing information.
34
34
  #include <ruby.h>
35
35
  #define EmSelect rb_thread_select
36
36
 
37
- #ifdef HAVE_RBTRAP
37
+ #if defined(HAVE_RBTRAP)
38
38
  #include <rubysig.h>
39
+ #elif defined(HAVE_RB_THREAD_CHECK_INTS)
40
+ extern "C" {
41
+ void rb_enable_interrupt(void);
42
+ void rb_disable_interrupt(void);
43
+ }
44
+
45
+ #define TRAP_BEG rb_enable_interrupt()
46
+ #define TRAP_END do { rb_disable_interrupt(); rb_thread_check_ints(); } while(0)
39
47
  #else
40
48
  #define TRAP_BEG
41
49
  #define TRAP_END
@@ -74,28 +82,28 @@ class EventMachine_t
74
82
  static void SetMaxTimerCount (int);
75
83
 
76
84
  public:
77
- EventMachine_t (void(*event_callback)(const char*, int, const char*, int));
85
+ EventMachine_t (void(*event_callback)(const unsigned long, int, const char*, const unsigned long));
78
86
  virtual ~EventMachine_t();
79
87
 
80
88
  void Run();
81
89
  void ScheduleHalt();
82
90
  void SignalLoopBreaker();
83
- const char *InstallOneshotTimer (int);
84
- const char *ConnectToServer (const char *, int, const char *, int);
85
- const char *ConnectToUnixServer (const char *);
86
-
87
- const char *CreateTcpServer (const char *, int);
88
- const char *OpenDatagramSocket (const char *, int);
89
- const char *CreateUnixDomainServer (const char*);
90
- const char *_OpenFileForWriting (const char*);
91
- const char *OpenKeyboard();
91
+ const unsigned long InstallOneshotTimer (int);
92
+ const unsigned long ConnectToServer (const char *, int, const char *, int);
93
+ const unsigned long ConnectToUnixServer (const char *);
94
+
95
+ const unsigned long CreateTcpServer (const char *, int);
96
+ const unsigned long OpenDatagramSocket (const char *, int);
97
+ const unsigned long CreateUnixDomainServer (const char*);
98
+ const unsigned long _OpenFileForWriting (const char*);
99
+ const unsigned long OpenKeyboard();
92
100
  //const char *Popen (const char*, const char*);
93
- const char *Socketpair (char* const*);
101
+ const unsigned long Socketpair (char* const*);
94
102
 
95
103
  void Add (EventableDescriptor*);
96
104
  void Modify (EventableDescriptor*);
97
105
 
98
- const char *AttachFD (int, bool, bool);
106
+ const unsigned long AttachFD (int, bool);
99
107
  int DetachFD (EventableDescriptor*);
100
108
 
101
109
  void ArmKqueueWriter (EventableDescriptor*);
@@ -112,18 +120,18 @@ class EventMachine_t
112
120
  float GetHeartbeatInterval();
113
121
  int SetHeartbeatInterval(float);
114
122
 
115
- const char *WatchFile (const char*);
123
+ const unsigned long WatchFile (const char*);
116
124
  void UnwatchFile (int);
117
- void UnwatchFile (const char*);
125
+ void UnwatchFile (const unsigned long);
118
126
 
119
127
  #ifdef HAVE_KQUEUE
120
128
  void _HandleKqueueFileEvent (struct kevent*);
121
129
  void _RegisterKqueueFileEvent(int);
122
130
  #endif
123
131
 
124
- const char *WatchPid (int);
132
+ const unsigned long WatchPid (int);
125
133
  void UnwatchPid (int);
126
- void UnwatchPid (const char *);
134
+ void UnwatchPid (const unsigned long);
127
135
 
128
136
  #ifdef HAVE_KQUEUE
129
137
  void _HandleKqueuePidEvent (struct kevent*);
@@ -160,7 +168,7 @@ class EventMachine_t
160
168
  MaxEvents = 4096
161
169
  };
162
170
  int HeartbeatInterval;
163
- void (*EventCallback)(const char*, int, const char*, int);
171
+ void (*EventCallback)(const unsigned long, int, const char*, const unsigned long);
164
172
 
165
173
  class Timer_t: public Bindable_t {
166
174
  };
@@ -212,6 +220,7 @@ struct SelectData_t
212
220
  int maxsocket;
213
221
  fd_set fdreads;
214
222
  fd_set fdwrites;
223
+ fd_set fderrors;
215
224
  timeval tv;
216
225
  int nSockets;
217
226
  };
@@ -138,7 +138,7 @@ bool EventMachine_t::_RunTimers()
138
138
  if (i->first > gCurrentLoopTime)
139
139
  break;
140
140
  if (EventCallback)
141
- (*EventCallback) ("", EM_TIMER_FIRED, i->second.GetBinding().c_str(), i->second.GetBinding().length());
141
+ (*EventCallback) (NULL, EM_TIMER_FIRED, NULL, i->second.GetBinding());
142
142
  Timers.erase (i);
143
143
  }
144
144
  return true;
@@ -158,7 +158,7 @@ const char *EventMachine_t::InstallOneshotTimer (int seconds)
158
158
 
159
159
  Timer_t t;
160
160
  Timers.insert (make_pair (time(NULL) + seconds, t));
161
- return t.GetBinding().c_str();
161
+ return t.GetBinding();
162
162
  }
163
163
 
164
164
 
@@ -230,7 +230,7 @@ const char *EventMachine_t::CreateTcpServer (const char *server, int port)
230
230
  if (!ad)
231
231
  throw std::runtime_error ("unable to allocate acceptor");
232
232
  Add (ad);
233
- output_binding = ad->GetBinding().c_str();
233
+ output_binding = ad->GetBinding();
234
234
 
235
235
  CreateIoCompletionPort ((HANDLE)sd_accept, Iocp, NULL, 0);
236
236
  SOCKET sd = socket (AF_INET, SOCK_STREAM, 0);
@@ -39,43 +39,54 @@ extern "C" {
39
39
 
40
40
  };
41
41
 
42
- void evma_initialize_library (void(*)(const char*, int, const char*, int));
42
+ void evma_initialize_library (void(*)(const unsigned long, int, const char*, const unsigned long));
43
43
  void evma_run_machine();
44
44
  void evma_release_library();
45
- const char *evma_install_oneshot_timer (int seconds);
46
- const char *evma_connect_to_server (const char *bind_addr, int bind_port, const char *server, int port);
47
- const char *evma_connect_to_unix_server (const char *server);
48
-
49
- const char *evma_attach_fd (int file_descriptor, int read_mode, int write_mode);
50
- int evma_detach_fd (const char *binding);
51
-
52
- void evma_stop_tcp_server (const char *signature);
53
- const char *evma_create_tcp_server (const char *address, int port);
54
- const char *evma_create_unix_domain_server (const char *filename);
55
- const char *evma_open_datagram_socket (const char *server, int port);
56
- const char *evma_open_keyboard();
57
- void evma_set_tls_parms (const char *binding, const char *privatekey_filename, const char *certchain_filenane, int verify_peer);
58
- void evma_start_tls (const char *binding);
45
+ const unsigned long evma_install_oneshot_timer (int seconds);
46
+ const unsigned long evma_connect_to_server (const char *bind_addr, int bind_port, const char *server, int port);
47
+ const unsigned long evma_connect_to_unix_server (const char *server);
48
+
49
+ const unsigned long evma_attach_fd (int file_descriptor, int watch_mode);
50
+ int evma_detach_fd (const unsigned long binding);
51
+ int evma_get_file_descriptor (const unsigned long binding);
52
+ int evma_is_notify_readable (const unsigned long binding);
53
+ void evma_set_notify_readable (const unsigned long binding, int mode);
54
+ int evma_is_notify_writable (const unsigned long binding);
55
+ void evma_set_notify_writable (const unsigned long binding, int mode);
56
+
57
+ int evma_pause(const unsigned long binding);
58
+ int evma_is_paused(const unsigned long binding);
59
+ int evma_resume(const unsigned long binding);
60
+
61
+ void evma_stop_tcp_server (const unsigned long signature);
62
+ const unsigned long evma_create_tcp_server (const char *address, int port);
63
+ const unsigned long evma_create_unix_domain_server (const char *filename);
64
+ const unsigned long evma_open_datagram_socket (const char *server, int port);
65
+ const unsigned long evma_open_keyboard();
66
+ void evma_set_tls_parms (const unsigned long binding, const char *privatekey_filename, const char *certchain_filenane, int verify_peer);
67
+ void evma_start_tls (const unsigned long binding);
59
68
 
60
69
  #ifdef WITH_SSL
61
- X509 *evma_get_peer_cert (const char *binding);
62
- void evma_accept_ssl_peer (const char *binding);
70
+ X509 *evma_get_peer_cert (const unsigned long binding);
71
+ void evma_accept_ssl_peer (const unsigned long binding);
63
72
  #endif
64
73
 
65
- int evma_get_peername (const char *binding, struct sockaddr*);
66
- int evma_get_sockname (const char *binding, struct sockaddr*);
67
- int evma_get_subprocess_pid (const char *binding, pid_t*);
68
- int evma_get_subprocess_status (const char *binding, int*);
74
+ int evma_get_peername (const unsigned long binding, struct sockaddr*);
75
+ int evma_get_sockname (const unsigned long binding, struct sockaddr*);
76
+ int evma_get_subprocess_pid (const unsigned long binding, pid_t*);
77
+ int evma_get_subprocess_status (const unsigned long binding, int*);
69
78
  int evma_get_connection_count();
70
- int evma_send_data_to_connection (const char *binding, const char *data, int data_length);
71
- int evma_send_datagram (const char *binding, const char *data, int data_length, const char *address, int port);
72
- float evma_get_comm_inactivity_timeout (const char *binding);
73
- int evma_set_comm_inactivity_timeout (const char *binding, float value);
74
- int evma_get_outbound_data_size (const char *binding);
75
- int evma_send_file_data_to_connection (const char *binding, const char *filename);
76
-
77
- void evma_close_connection (const char *binding, int after_writing);
78
- int evma_report_connection_error_status (const char *binding);
79
+ int evma_send_data_to_connection (const unsigned long binding, const char *data, int data_length);
80
+ int evma_send_datagram (const unsigned long binding, const char *data, int data_length, const char *address, int port);
81
+ float evma_get_comm_inactivity_timeout (const unsigned long binding);
82
+ int evma_set_comm_inactivity_timeout (const unsigned long binding, float value);
83
+ float evma_get_pending_connect_timeout (const unsigned long binding);
84
+ int evma_set_pending_connect_timeout (const unsigned long binding, float value);
85
+ int evma_get_outbound_data_size (const unsigned long binding);
86
+ int evma_send_file_data_to_connection (const unsigned long binding, const char *filename);
87
+
88
+ void evma_close_connection (const unsigned long binding, int after_writing);
89
+ int evma_report_connection_error_status (const unsigned long binding);
79
90
  void evma_signal_loopbreak();
80
91
  void evma_set_timer_quantum (int);
81
92
  int evma_get_max_timer_count();
@@ -85,17 +96,17 @@ extern "C" {
85
96
  float evma_get_heartbeat_interval();
86
97
  int evma_set_heartbeat_interval(float);
87
98
 
88
- const char *evma__write_file (const char *filename);
89
- const char *evma_popen (char * const*cmd_strings);
99
+ const unsigned long evma__write_file (const char *filename);
100
+ const unsigned long evma_popen (char * const*cmd_strings);
90
101
 
91
- const char *evma_watch_filename (const char *fname);
92
- void evma_unwatch_filename (const char *sig);
102
+ const unsigned long evma_watch_filename (const char *fname);
103
+ void evma_unwatch_filename (const unsigned long);
93
104
 
94
- const char *evma_watch_pid (int);
95
- void evma_unwatch_pid (const char *sig);
105
+ const unsigned long evma_watch_pid (int);
106
+ void evma_unwatch_pid (const unsigned long);
96
107
 
97
- void evma_start_proxy(const char*, const char*);
98
- void evma_stop_proxy(const char*);
108
+ void evma_start_proxy(const unsigned long, const unsigned long, const unsigned long);
109
+ void evma_stop_proxy(const unsigned long);
99
110
 
100
111
  int evma_set_rlimit_nofile (int n_files);
101
112
 
@@ -1,96 +1,96 @@
1
- /*****************************************************************************
2
-
3
- $Id$
4
-
5
- File: eventmachine_cpp.h
6
- Date: 27Jul07
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 __EVMA_EventmachineCpp__H_
22
- #define __EVMA_EventmachineCpp__H_
23
-
24
-
25
- // This material is only for directly integrating EM into C++ programs.
26
-
27
- namespace EM {
28
-
29
- void Callback (const char *sig, int event, const char *data, int length);
30
- void Run (void(*)(void));
31
- void AddTimer (int, void(*)());
32
- void StopReactor();
33
-
34
- /***************
35
- class Eventable
36
- ***************/
37
-
38
- class Eventable {
39
- public:
40
- Eventable() {}
41
- virtual ~Eventable() {}
42
-
43
- std::string Signature;
44
-
45
- // Called by the framework
46
- virtual void ReceiveData (const char *data, int length) {}
47
- virtual void ConnectionCompleted() {}
48
- virtual void Accept (const char*) {}
49
- virtual void Unbind() {}
50
- virtual void PostInit() {}
51
- virtual void SslHandshakeCompleted() {}
52
-
53
- void StopReactor() {EM::StopReactor();}
54
- };
55
-
56
- /****************
57
- class Connection
58
- ****************/
59
-
60
- class Connection: public Eventable {
61
- public:
62
- Connection() {}
63
- virtual ~Connection() {}
64
-
65
- virtual void Connect (const char*, int);
66
- virtual void BindConnect (const char *, int, const char*, int);
67
-
68
- void SendData (const char *data);
69
- void SendData (const char *data, int length);
70
- void Close (bool afterWriting);
71
- };
72
-
73
-
74
- /**************
75
- class Acceptor
76
- **************/
77
-
78
- class Acceptor: public Eventable {
79
- public:
80
- Acceptor() {PostInit();}
81
- virtual ~Acceptor() {}
82
-
83
- void Start (const char*, int);
84
- void Accept (const char*);
85
-
86
- virtual Connection *MakeConnection() {return new Connection();}
87
- };
88
-
89
-
90
- };
91
-
92
-
93
-
94
-
95
-
96
- #endif // __EVMA_EventmachineCpp__H_
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: eventmachine_cpp.h
6
+ Date: 27Jul07
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 __EVMA_EventmachineCpp__H_
22
+ #define __EVMA_EventmachineCpp__H_
23
+
24
+
25
+ // This material is only for directly integrating EM into C++ programs.
26
+
27
+ namespace EM {
28
+
29
+ void Callback (const unsigned long sig, int event, const char *data, const unsigned long length);
30
+ void Run (void(*)(void));
31
+ void AddTimer (int, void(*)());
32
+ void StopReactor();
33
+
34
+ /***************
35
+ class Eventable
36
+ ***************/
37
+
38
+ class Eventable {
39
+ public:
40
+ Eventable() {}
41
+ virtual ~Eventable() {}
42
+
43
+ unsigned long Signature;
44
+
45
+ // Called by the framework
46
+ virtual void ReceiveData (const char *data, int length) {}
47
+ virtual void ConnectionCompleted() {}
48
+ virtual void Accept (const unsigned long) {}
49
+ virtual void Unbind() {}
50
+ virtual void PostInit() {}
51
+ virtual void SslHandshakeCompleted() {}
52
+
53
+ void StopReactor() {EM::StopReactor();}
54
+ };
55
+
56
+ /****************
57
+ class Connection
58
+ ****************/
59
+
60
+ class Connection: public Eventable {
61
+ public:
62
+ Connection() {}
63
+ virtual ~Connection() {}
64
+
65
+ virtual void Connect (const char*, int);
66
+ virtual void BindConnect (const char *, int, const char*, int);
67
+
68
+ void SendData (const char *data);
69
+ void SendData (const char *data, int length);
70
+ void Close (bool afterWriting);
71
+ };
72
+
73
+
74
+ /**************
75
+ class Acceptor
76
+ **************/
77
+
78
+ class Acceptor: public Eventable {
79
+ public:
80
+ Acceptor() {PostInit();}
81
+ virtual ~Acceptor() {}
82
+
83
+ void Start (const char*, int);
84
+ void Accept (const unsigned long);
85
+
86
+ virtual Connection *MakeConnection() {return new Connection();}
87
+ };
88
+
89
+
90
+ };
91
+
92
+
93
+
94
+
95
+
96
+ #endif // __EVMA_EventmachineCpp__H_
@@ -1,133 +1,148 @@
1
- require 'mkmf'
2
-
3
- def check_libs libs = [], fatal = false
4
- libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
5
- end
6
-
7
- def check_heads heads = [], fatal = false
8
- heads.all? { |head| have_header(head) || (abort("could not find header: #{head}") if fatal)}
9
- end
10
-
11
- def add_define(name)
12
- $defs.push("-D#{name}")
13
- end
14
-
15
- add_define 'BUILD_FOR_RUBY'
16
- add_define 'HAVE_RBTRAP' if have_var('rb_trap_immediate', ['ruby.h', 'rubysig.h'])
17
- add_define "HAVE_TBR" if have_func('rb_thread_blocking_region')# and have_macro('RUBY_UBF_IO', 'ruby.h')
18
- add_define "HAVE_INOTIFY" if inotify = have_func('inotify_init', 'sys/inotify.h')
19
- add_define "HAVE_OLD_INOTIFY" if !inotify && have_macro('__NR_inotify_init', 'sys/syscall.h')
20
- add_define 'HAVE_WRITEV' if have_func('writev', 'sys/uio.h')
21
-
22
- # Minor platform details between *nix and Windows:
23
-
24
- if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
25
- GNU_CHAIN = $1 == 'mingw'
26
- OS_WIN32 = true
27
- add_define "OS_WIN32"
28
- else
29
- GNU_CHAIN = true
30
- OS_UNIX = true
31
- add_define 'OS_UNIX'
32
-
33
- add_define "HAVE_KQUEUE" if have_header("sys/event.h") and have_header("sys/queue.h")
34
- end
35
-
36
- # Main platform invariances:
37
-
38
- case RUBY_PLATFORM
39
- when /mswin32/, /mingw32/, /bccwin32/
40
- check_heads(%w[windows.h winsock.h], true)
41
- check_libs(%w[kernel32 rpcrt4 gdi32], true)
42
-
43
- if GNU_CHAIN
44
- CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
45
- else
46
- $defs.push "-EHs"
47
- $defs.push "-GR"
48
- end
49
-
50
- when /solaris/
51
- check_libs(%w[nsl socket], true)
52
-
53
- add_define 'OS_SOLARIS8'
54
-
55
- # Patch by Tim Pease, fixes SUNWspro compile problems.
56
- if CONFIG['CC'] == 'cc'
57
- # SUN CHAIN
58
- $CFLAGS = CONFIG['CFLAGS'] = "-KPIC -G"
59
- CONFIG['CCDLFLAGS'] = "-KPIC"
60
- else
61
- # GNU CHAIN
62
- # on Unix we need a g++ link, not gcc.
63
- CONFIG['LDSHARED'] = "$(CXX) -shared"
64
- end
65
-
66
- when /openbsd/
67
- # OpenBSD branch contributed by Guillaume Sellier.
68
-
69
- # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
70
- CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
71
-
72
- when /darwin/
73
-
74
- # on Unix we need a g++ link, not gcc.
75
- # Ff line contributed by Daniel Harple.
76
- CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
77
-
78
- when /linux/
79
-
80
- # Original epoll test is inadequate because 2.4 kernels have the header
81
- # but not the code.
82
- # add_define 'HAVE_EPOLL' if have_header('sys/epoll.h')
83
- if have_header('sys/epoll.h')
84
- File.open("hasEpollTest.c", "w") {|f|
85
- f.puts "#include <sys/epoll.h>"
86
- f.puts "int main() { epoll_create(1024); return 0;}"
87
- }
88
- (e = system( "gcc hasEpollTest.c -o hasEpollTest " )) and (e = $?.to_i)
89
- `rm -f hasEpollTest.c hasEpollTest`
90
- add_define 'HAVE_EPOLL' if e == 0
91
- end
92
-
93
- # on Unix we need a g++ link, not gcc.
94
- CONFIG['LDSHARED'] = "$(CXX) -shared"
95
- else
96
- # on Unix we need a g++ link, not gcc.
97
- CONFIG['LDSHARED'] = "$(CXX) -shared"
98
- end
99
-
100
- # OpenSSL:
101
-
102
- def manual_ssl_config
103
- ssl_libs_heads_args = {
104
- :unix => [%w[ssl crypto], %w[openssl/ssl.h openssl/err.h]],
105
- :darwin => [%w[ssl crypto C], %w[openssl/ssl.h openssl/err.h]],
106
- # openbsd and linux:
107
- :crypto_hack => [%w[crypto ssl crypto], %w[openssl/ssl.h openssl/err.h]],
108
- :mswin => [%w[ssleay32 libeay32], %w[openssl/ssl.h openssl/err.h]],
109
- }
110
-
111
- dc_flags = ['ssl']
112
- dc_flags += ["#{ENV['OPENSSL']}/include", ENV['OPENSSL']] if /linux/ =~ RUBY_PLATFORM
113
-
114
- libs, heads = case RUBY_PLATFORM
115
- when /mswin/ ; ssl_libs_heads_args[:mswin]
116
- when /mingw/ ; ssl_libs_heads_args[:unix]
117
- when /darwin/ ; ssl_libs_heads_args[:darwin]
118
- when /openbsd/ ; ssl_libs_heads_args[:crypto_hack]
119
- when /linux/ ; ssl_libs_heads_args[:crypto_hack]
120
- else ssl_libs_heads_args[:unix]
121
- end
122
- dir_config(*dc_flags)
123
- check_libs(libs) and check_heads(heads)
124
- end
125
-
126
- # Try to use pkg_config first, fixes #73
127
- if pkg_config('openssl') || manual_ssl_config
128
- add_define "WITH_SSL"
129
- else
130
- add_define "WITHOUT_SSL"
131
- end
132
-
1
+ require 'mkmf'
2
+
3
+ def check_libs libs = [], fatal = false
4
+ libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
5
+ end
6
+
7
+ def check_heads heads = [], fatal = false
8
+ heads.all? { |head| have_header(head) || (abort("could not find header: #{head}") if fatal)}
9
+ end
10
+
11
+ def add_define(name)
12
+ $defs.push("-D#{name}")
13
+ end
14
+
15
+ add_define 'BUILD_FOR_RUBY'
16
+ add_define 'HAVE_RBTRAP' if have_var('rb_trap_immediate', ['ruby.h', 'rubysig.h'])
17
+ add_define "HAVE_TBR" if have_func('rb_thread_blocking_region')# and have_macro('RUBY_UBF_IO', 'ruby.h')
18
+ add_define "HAVE_INOTIFY" if inotify = have_func('inotify_init', 'sys/inotify.h')
19
+ add_define "HAVE_OLD_INOTIFY" if !inotify && have_macro('__NR_inotify_init', 'sys/syscall.h')
20
+ add_define 'HAVE_WRITEV' if have_func('writev', 'sys/uio.h')
21
+ have_func('rb_thread_check_ints')
22
+ have_func('rb_time_new')
23
+
24
+ # Minor platform details between *nix and Windows:
25
+
26
+ if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
27
+ GNU_CHAIN = $1 == 'mingw'
28
+ OS_WIN32 = true
29
+ add_define "OS_WIN32"
30
+ else
31
+ GNU_CHAIN = true
32
+ OS_UNIX = true
33
+ add_define 'OS_UNIX'
34
+
35
+ add_define "HAVE_KQUEUE" if have_header("sys/event.h") and have_header("sys/queue.h")
36
+ end
37
+
38
+ # Main platform invariances:
39
+
40
+ case RUBY_PLATFORM
41
+ when /mswin32/, /mingw32/, /bccwin32/
42
+ check_heads(%w[windows.h winsock.h], true)
43
+ check_libs(%w[kernel32 rpcrt4 gdi32], true)
44
+
45
+ if GNU_CHAIN
46
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
47
+ else
48
+ $defs.push "-EHs"
49
+ $defs.push "-GR"
50
+ end
51
+
52
+ when /solaris/
53
+ add_define 'OS_SOLARIS8'
54
+ check_libs(%w[nsl socket], true)
55
+
56
+ # Patch by Tim Pease, fixes SUNWspro compile problems.
57
+ if CONFIG['CC'] == 'cc'
58
+ # SUN CHAIN
59
+ $CFLAGS = CONFIG['CFLAGS'] = "-KPIC -G"
60
+ CONFIG['CCDLFLAGS'] = "-KPIC"
61
+ else
62
+ # GNU CHAIN
63
+ # on Unix we need a g++ link, not gcc.
64
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
65
+ end
66
+
67
+ when /openbsd/
68
+ # OpenBSD branch contributed by Guillaume Sellier.
69
+
70
+ # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
71
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++ -fPIC"
72
+ CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
73
+
74
+ when /darwin/
75
+ # on Unix we need a g++ link, not gcc.
76
+ # Ff line contributed by Daniel Harple.
77
+ CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
78
+
79
+ when /linux/
80
+ add_define 'HAVE_EPOLL' if have_func('epoll_create', 'sys/epoll.h')
81
+
82
+ # Original epoll test is inadequate because 2.4 kernels have the header
83
+ # but not the code.
84
+ # add_define 'HAVE_EPOLL' if have_header('sys/epoll.h')
85
+ # if have_header('sys/epoll.h')
86
+ # File.open("hasEpollTest.c", "w") {|f|
87
+ # f.puts "#include <sys/epoll.h>"
88
+ # f.puts "int main() { epoll_create(1024); return 0;}"
89
+ # }
90
+ # (e = system( "gcc hasEpollTest.c -o hasEpollTest " )) and (e = $?.to_i)
91
+ # `rm -f hasEpollTest.c hasEpollTest`
92
+ # add_define 'HAVE_EPOLL' if e == 0
93
+ # end
94
+
95
+ # on Unix we need a g++ link, not gcc.
96
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
97
+
98
+ when /aix/
99
+ CONFIG['LDSHARED'] = "$(CXX) -shared -Wl,-G -Wl,-brtl"
100
+
101
+ else
102
+ # on Unix we need a g++ link, not gcc.
103
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
104
+ end
105
+
106
+ # OpenSSL:
107
+
108
+ def manual_ssl_config
109
+ ssl_libs_heads_args = {
110
+ :unix => [%w[ssl crypto], %w[openssl/ssl.h openssl/err.h]],
111
+ :darwin => [%w[ssl crypto C], %w[openssl/ssl.h openssl/err.h]],
112
+ # openbsd and linux:
113
+ :crypto_hack => [%w[crypto ssl crypto], %w[openssl/ssl.h openssl/err.h]],
114
+ :mswin => [%w[ssleay32 libeay32], %w[openssl/ssl.h openssl/err.h]],
115
+ }
116
+
117
+ dc_flags = ['ssl']
118
+ dc_flags += ["#{ENV['OPENSSL']}/include", ENV['OPENSSL']] if /linux/ =~ RUBY_PLATFORM
119
+
120
+ libs, heads = case RUBY_PLATFORM
121
+ when /mswin/ ; ssl_libs_heads_args[:mswin]
122
+ when /mingw/ ; ssl_libs_heads_args[:unix]
123
+ when /darwin/ ; ssl_libs_heads_args[:darwin]
124
+ when /openbsd/ ; ssl_libs_heads_args[:crypto_hack]
125
+ when /linux/ ; ssl_libs_heads_args[:crypto_hack]
126
+ else ssl_libs_heads_args[:unix]
127
+ end
128
+ dir_config(*dc_flags)
129
+ check_libs(libs) and check_heads(heads)
130
+ end
131
+
132
+ # Try to use pkg_config first, fixes #73
133
+ if pkg_config('openssl') || manual_ssl_config
134
+ add_define "WITH_SSL"
135
+ else
136
+ add_define "WITHOUT_SSL"
137
+ end
138
+
139
+ # solaris c++ compiler doesn't have make_pair()
140
+ TRY_LINK.sub!('$(CC)', '$(CXX)')
141
+ add_define 'HAVE_MAKE_PAIR' if try_link(<<SRC, '-lstdc++')
142
+ #include <utility>
143
+ using namespace std;
144
+ int main(){ pair<int,int> tuple = make_pair(1,2); }
145
+ SRC
146
+ TRY_LINK.sub!('$(CXX)', '$(CC)')
147
+
133
148
  create_makefile "rubyeventmachine"