eventmachine 1.2.0.dev.2-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +105 -0
  3. data/GNU +281 -0
  4. data/LICENSE +60 -0
  5. data/README.md +108 -0
  6. data/docs/DocumentationGuidesIndex.md +27 -0
  7. data/docs/GettingStarted.md +521 -0
  8. data/docs/old/ChangeLog +211 -0
  9. data/docs/old/DEFERRABLES +246 -0
  10. data/docs/old/EPOLL +141 -0
  11. data/docs/old/INSTALL +13 -0
  12. data/docs/old/KEYBOARD +42 -0
  13. data/docs/old/LEGAL +25 -0
  14. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  15. data/docs/old/PURE_RUBY +75 -0
  16. data/docs/old/RELEASE_NOTES +94 -0
  17. data/docs/old/SMTP +4 -0
  18. data/docs/old/SPAWNED_PROCESSES +148 -0
  19. data/docs/old/TODO +8 -0
  20. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  21. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  22. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  23. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  24. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  25. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  26. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  27. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  28. data/examples/old/ex_channel.rb +43 -0
  29. data/examples/old/ex_queue.rb +2 -0
  30. data/examples/old/ex_tick_loop_array.rb +15 -0
  31. data/examples/old/ex_tick_loop_counter.rb +32 -0
  32. data/examples/old/helper.rb +2 -0
  33. data/ext/binder.cpp +124 -0
  34. data/ext/binder.h +46 -0
  35. data/ext/cmain.cpp +988 -0
  36. data/ext/ed.cpp +2111 -0
  37. data/ext/ed.h +442 -0
  38. data/ext/em.cpp +2379 -0
  39. data/ext/em.h +308 -0
  40. data/ext/eventmachine.h +143 -0
  41. data/ext/extconf.rb +270 -0
  42. data/ext/fastfilereader/extconf.rb +110 -0
  43. data/ext/fastfilereader/mapper.cpp +216 -0
  44. data/ext/fastfilereader/mapper.h +59 -0
  45. data/ext/fastfilereader/rubymain.cpp +127 -0
  46. data/ext/kb.cpp +79 -0
  47. data/ext/page.cpp +107 -0
  48. data/ext/page.h +51 -0
  49. data/ext/pipe.cpp +354 -0
  50. data/ext/project.h +176 -0
  51. data/ext/rubymain.cpp +1504 -0
  52. data/ext/ssl.cpp +615 -0
  53. data/ext/ssl.h +103 -0
  54. data/java/.classpath +8 -0
  55. data/java/.project +17 -0
  56. data/java/src/com/rubyeventmachine/EmReactor.java +591 -0
  57. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  58. data/java/src/com/rubyeventmachine/EventableChannel.java +72 -0
  59. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +201 -0
  60. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +415 -0
  61. data/lib/2.0/fastfilereaderext.so +0 -0
  62. data/lib/2.0/rubyeventmachine.so +0 -0
  63. data/lib/2.1/fastfilereaderext.so +0 -0
  64. data/lib/2.1/rubyeventmachine.so +0 -0
  65. data/lib/2.2/fastfilereaderext.so +0 -0
  66. data/lib/2.2/rubyeventmachine.so +0 -0
  67. data/lib/2.3/fastfilereaderext.so +0 -0
  68. data/lib/2.3/rubyeventmachine.so +0 -0
  69. data/lib/em/buftok.rb +59 -0
  70. data/lib/em/callback.rb +58 -0
  71. data/lib/em/channel.rb +69 -0
  72. data/lib/em/completion.rb +304 -0
  73. data/lib/em/connection.rb +770 -0
  74. data/lib/em/deferrable.rb +210 -0
  75. data/lib/em/deferrable/pool.rb +2 -0
  76. data/lib/em/file_watch.rb +73 -0
  77. data/lib/em/future.rb +61 -0
  78. data/lib/em/iterator.rb +252 -0
  79. data/lib/em/messages.rb +66 -0
  80. data/lib/em/pool.rb +151 -0
  81. data/lib/em/process_watch.rb +45 -0
  82. data/lib/em/processes.rb +123 -0
  83. data/lib/em/protocols.rb +37 -0
  84. data/lib/em/protocols/header_and_content.rb +138 -0
  85. data/lib/em/protocols/httpclient.rb +299 -0
  86. data/lib/em/protocols/httpclient2.rb +600 -0
  87. data/lib/em/protocols/line_and_text.rb +125 -0
  88. data/lib/em/protocols/line_protocol.rb +29 -0
  89. data/lib/em/protocols/linetext2.rb +166 -0
  90. data/lib/em/protocols/memcache.rb +331 -0
  91. data/lib/em/protocols/object_protocol.rb +46 -0
  92. data/lib/em/protocols/postgres3.rb +246 -0
  93. data/lib/em/protocols/saslauth.rb +175 -0
  94. data/lib/em/protocols/smtpclient.rb +394 -0
  95. data/lib/em/protocols/smtpserver.rb +666 -0
  96. data/lib/em/protocols/socks4.rb +66 -0
  97. data/lib/em/protocols/stomp.rb +205 -0
  98. data/lib/em/protocols/tcptest.rb +54 -0
  99. data/lib/em/pure_ruby.rb +1022 -0
  100. data/lib/em/queue.rb +80 -0
  101. data/lib/em/resolver.rb +232 -0
  102. data/lib/em/spawnable.rb +84 -0
  103. data/lib/em/streamer.rb +118 -0
  104. data/lib/em/threaded_resource.rb +90 -0
  105. data/lib/em/tick_loop.rb +85 -0
  106. data/lib/em/timers.rb +61 -0
  107. data/lib/em/version.rb +3 -0
  108. data/lib/eventmachine.rb +1584 -0
  109. data/lib/fastfilereaderext.rb +2 -0
  110. data/lib/jeventmachine.rb +301 -0
  111. data/lib/rubyeventmachine.rb +2 -0
  112. data/rakelib/package.rake +120 -0
  113. data/rakelib/test.rake +8 -0
  114. data/tests/client.crt +31 -0
  115. data/tests/client.key +51 -0
  116. data/tests/dhparam.pem +13 -0
  117. data/tests/em_test_helper.rb +151 -0
  118. data/tests/test_attach.rb +151 -0
  119. data/tests/test_basic.rb +283 -0
  120. data/tests/test_channel.rb +75 -0
  121. data/tests/test_completion.rb +178 -0
  122. data/tests/test_connection_count.rb +54 -0
  123. data/tests/test_connection_write.rb +35 -0
  124. data/tests/test_defer.rb +35 -0
  125. data/tests/test_deferrable.rb +35 -0
  126. data/tests/test_epoll.rb +142 -0
  127. data/tests/test_error_handler.rb +38 -0
  128. data/tests/test_exc.rb +28 -0
  129. data/tests/test_file_watch.rb +66 -0
  130. data/tests/test_fork.rb +75 -0
  131. data/tests/test_futures.rb +170 -0
  132. data/tests/test_get_sock_opt.rb +37 -0
  133. data/tests/test_handler_check.rb +35 -0
  134. data/tests/test_hc.rb +155 -0
  135. data/tests/test_httpclient.rb +233 -0
  136. data/tests/test_httpclient2.rb +128 -0
  137. data/tests/test_idle_connection.rb +25 -0
  138. data/tests/test_inactivity_timeout.rb +54 -0
  139. data/tests/test_ipv4.rb +125 -0
  140. data/tests/test_ipv6.rb +131 -0
  141. data/tests/test_iterator.rb +115 -0
  142. data/tests/test_kb.rb +28 -0
  143. data/tests/test_line_protocol.rb +33 -0
  144. data/tests/test_ltp.rb +138 -0
  145. data/tests/test_ltp2.rb +308 -0
  146. data/tests/test_many_fds.rb +22 -0
  147. data/tests/test_next_tick.rb +104 -0
  148. data/tests/test_object_protocol.rb +36 -0
  149. data/tests/test_pause.rb +107 -0
  150. data/tests/test_pending_connect_timeout.rb +52 -0
  151. data/tests/test_pool.rb +196 -0
  152. data/tests/test_process_watch.rb +50 -0
  153. data/tests/test_processes.rb +128 -0
  154. data/tests/test_proxy_connection.rb +180 -0
  155. data/tests/test_pure.rb +88 -0
  156. data/tests/test_queue.rb +64 -0
  157. data/tests/test_resolver.rb +104 -0
  158. data/tests/test_running.rb +14 -0
  159. data/tests/test_sasl.rb +47 -0
  160. data/tests/test_send_file.rb +217 -0
  161. data/tests/test_servers.rb +33 -0
  162. data/tests/test_set_sock_opt.rb +39 -0
  163. data/tests/test_shutdown_hooks.rb +23 -0
  164. data/tests/test_smtpclient.rb +75 -0
  165. data/tests/test_smtpserver.rb +57 -0
  166. data/tests/test_spawn.rb +293 -0
  167. data/tests/test_ssl_args.rb +78 -0
  168. data/tests/test_ssl_dhparam.rb +83 -0
  169. data/tests/test_ssl_ecdh_curve.rb +79 -0
  170. data/tests/test_ssl_extensions.rb +49 -0
  171. data/tests/test_ssl_methods.rb +65 -0
  172. data/tests/test_ssl_protocols.rb +246 -0
  173. data/tests/test_ssl_verify.rb +126 -0
  174. data/tests/test_stomp.rb +37 -0
  175. data/tests/test_system.rb +46 -0
  176. data/tests/test_threaded_resource.rb +61 -0
  177. data/tests/test_tick_loop.rb +59 -0
  178. data/tests/test_timers.rb +123 -0
  179. data/tests/test_ud.rb +8 -0
  180. data/tests/test_unbind_reason.rb +52 -0
  181. metadata +381 -0
@@ -0,0 +1,270 @@
1
+ require 'fileutils'
2
+ require 'mkmf'
3
+
4
+ # Eager check devs tools
5
+ have_devel? if respond_to?(:have_devel?)
6
+
7
+ def check_libs libs = [], fatal = false
8
+ libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
9
+ end
10
+
11
+ def check_heads heads = [], fatal = false
12
+ heads.all? { |head| have_header(head) || (abort("could not find header: #{head}") if fatal)}
13
+ end
14
+
15
+ def add_define(name)
16
+ $defs.push("-D#{name}")
17
+ end
18
+
19
+ ##
20
+ # OpenSSL:
21
+
22
+ # override append_library, so it actually appends (instead of prepending)
23
+ # this fixes issues with linking ssl, since libcrypto depends on symbols in libssl
24
+ def append_library(libs, lib)
25
+ libs + " " + format(LIBARG, lib)
26
+ end
27
+
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
33
+
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
53
+
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
69
+ end
70
+ end
71
+
72
+ if ENV['CROSS_COMPILING']
73
+ openssl_version = ENV.fetch("OPENSSL_VERSION", "1.0.2e")
74
+ openssl_dir = File.expand_path("~/.rake-compiler/builds/openssl-#{openssl_version}/")
75
+ if File.exist?(openssl_dir)
76
+ FileUtils.mkdir_p Dir.pwd+"/openssl/"
77
+ FileUtils.cp Dir[openssl_dir+"/include/openssl/*.h"], Dir.pwd+"/openssl/", :verbose => true
78
+ FileUtils.cp Dir[openssl_dir+"/lib*.a"], Dir.pwd, :verbose => true
79
+ $INCFLAGS << " -I#{Dir.pwd}" # for the openssl headers
80
+ add_define "WITH_SSL"
81
+ else
82
+ STDERR.puts
83
+ STDERR.puts "**************************************************************************************"
84
+ STDERR.puts "**** Cross-compiled OpenSSL not found"
85
+ STDERR.puts "**** Run: hg clone http://bitbucket.org/ged/ruby-pg && cd ruby-pg && rake openssl_libs"
86
+ STDERR.puts "**************************************************************************************"
87
+ STDERR.puts
88
+ end
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'
103
+ end
104
+
105
+ add_define 'BUILD_FOR_RUBY'
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')
114
+ have_func('rb_wait_for_single_fd')
115
+ have_func('rb_enable_interrupt')
116
+ have_func('rb_time_new')
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
+
127
+ # Minor platform details between *nix and Windows:
128
+
129
+ if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
130
+ GNU_CHAIN = ENV['CROSS_COMPILING'] || $1 == 'mingw'
131
+ OS_WIN32 = true
132
+ add_define "OS_WIN32"
133
+ else
134
+ GNU_CHAIN = true
135
+ OS_UNIX = true
136
+ add_define 'OS_UNIX'
137
+
138
+ add_define "HAVE_KQUEUE" if have_header("sys/event.h") && have_header("sys/queue.h")
139
+ end
140
+
141
+ # Adjust number of file descriptors (FD) on Windows
142
+
143
+ if RbConfig::CONFIG["host_os"] =~ /mingw/
144
+ found = RbConfig::CONFIG.values_at("CFLAGS", "CPPFLAGS").
145
+ any? { |v| v.include?("FD_SETSIZE") }
146
+
147
+ add_define "FD_SETSIZE=32767" unless found
148
+ end
149
+
150
+ # Main platform invariances:
151
+
152
+ case RUBY_PLATFORM
153
+ when /mswin32/, /mingw32/, /bccwin32/
154
+ check_heads(%w[windows.h winsock.h], true)
155
+ check_libs(%w[kernel32 rpcrt4 gdi32], true)
156
+
157
+ if GNU_CHAIN
158
+ CONFIG['LDSHAREDXX'] = "$(CXX) -shared -static-libgcc -static-libstdc++"
159
+ else
160
+ $defs.push "-EHs"
161
+ $defs.push "-GR"
162
+ end
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
+
168
+ when /solaris/
169
+ add_define 'OS_SOLARIS8'
170
+ check_libs(%w[nsl socket], true)
171
+
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
+ )
180
+ # SUN CHAIN
181
+ add_define 'CC_SUNWspro'
182
+ $preload = ["\nCXX = CC"] # hack a CXX= line into the makefile
183
+ $CFLAGS = CONFIG['CFLAGS'] = "-KPIC"
184
+ CONFIG['CCDLFLAGS'] = "-KPIC"
185
+ CONFIG['LDSHARED'] = "$(CXX) -G -KPIC -lCstd"
186
+ CONFIG['LDSHAREDXX'] = "$(CXX) -G -KPIC -lCstd"
187
+ else
188
+ # GNU CHAIN
189
+ # on Unix we need a g++ link, not gcc.
190
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
191
+ end
192
+
193
+ when /openbsd/
194
+ # OpenBSD branch contributed by Guillaume Sellier.
195
+
196
+ # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
197
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++ -fPIC"
198
+ CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
199
+
200
+ when /darwin/
201
+ add_define 'OS_DARWIN'
202
+
203
+ # on Unix we need a g++ link, not gcc.
204
+ # Ff line contributed by Daniel Harple.
205
+ CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
206
+
207
+ when /linux/
208
+ add_define 'HAVE_EPOLL' if have_func('epoll_create', 'sys/epoll.h')
209
+
210
+ # on Unix we need a g++ link, not gcc.
211
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
212
+
213
+ when /aix/
214
+ CONFIG['LDSHARED'] = "$(CXX) -shared -Wl,-G -Wl,-brtl"
215
+
216
+ when /cygwin/
217
+ # For rubies built with Cygwin, CXX may be set to CC, which is just
218
+ # a wrapper for gcc.
219
+ # This will compile, but it will not link to the C++ std library.
220
+ # Explicitly set CXX to use g++.
221
+ CONFIG['CXX'] = "g++"
222
+ # on Unix we need a g++ link, not gcc.
223
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
224
+
225
+ else
226
+ # on Unix we need a g++ link, not gcc.
227
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
228
+ end
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
238
+
239
+ # Hack so that try_link will test with a C++ compiler instead of a C compiler
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()
263
+ add_define 'HAVE_MAKE_PAIR' if try_link(<<SRC, '-lstdc++')
264
+ #include <utility>
265
+ using namespace std;
266
+ int main(){ pair<const int,int> tuple = make_pair(1,2); }
267
+ SRC
268
+ TRY_LINK.sub!('$(CXX)', '$(CC)')
269
+
270
+ create_makefile "rubyeventmachine"
@@ -0,0 +1,110 @@
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
+ # Eager check devs tools
16
+ have_devel? if respond_to?(:have_devel?)
17
+
18
+ add_define 'BUILD_FOR_RUBY'
19
+
20
+ # Minor platform details between *nix and Windows:
21
+
22
+ if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
23
+ GNU_CHAIN = ENV['CROSS_COMPILING'] || $1 == 'mingw'
24
+ OS_WIN32 = true
25
+ add_define "OS_WIN32"
26
+ else
27
+ GNU_CHAIN = true
28
+ OS_UNIX = true
29
+ add_define 'OS_UNIX'
30
+ end
31
+
32
+ # Adjust number of file descriptors (FD) on Windows
33
+
34
+ if RbConfig::CONFIG["host_os"] =~ /mingw/
35
+ found = RbConfig::CONFIG.values_at("CFLAGS", "CPPFLAGS").
36
+ any? { |v| v.include?("FD_SETSIZE") }
37
+
38
+ add_define "FD_SETSIZE=32767" unless found
39
+ end
40
+
41
+ # Main platform invariances:
42
+
43
+ case RUBY_PLATFORM
44
+ when /mswin32/, /mingw32/, /bccwin32/
45
+ check_heads(%w[windows.h winsock.h], true)
46
+ check_libs(%w[kernel32 rpcrt4 gdi32], true)
47
+
48
+ if GNU_CHAIN
49
+ CONFIG['LDSHAREDXX'] = "$(CXX) -shared -static-libgcc -static-libstdc++"
50
+ else
51
+ $defs.push "-EHs"
52
+ $defs.push "-GR"
53
+ end
54
+
55
+ when /solaris/
56
+ add_define 'OS_SOLARIS8'
57
+ check_libs(%w[nsl socket], true)
58
+
59
+ if CONFIG['CC'] == 'cc' && (
60
+ `cc -flags 2>&1` =~ /Sun/ || # detect SUNWspro compiler
61
+ `cc -V 2>&1` =~ /Sun/ # detect Solaris Studio compiler
62
+ )
63
+ # SUN CHAIN
64
+ add_define 'CC_SUNWspro'
65
+ $preload = ["\nCXX = CC"] # hack a CXX= line into the makefile
66
+ $CFLAGS = CONFIG['CFLAGS'] = "-KPIC"
67
+ CONFIG['CCDLFLAGS'] = "-KPIC"
68
+ CONFIG['LDSHARED'] = "$(CXX) -G -KPIC -lCstd"
69
+ CONFIG['LDSHAREDXX'] = "$(CXX) -G -KPIC -lCstd"
70
+ else
71
+ # GNU CHAIN
72
+ # on Unix we need a g++ link, not gcc.
73
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
74
+ end
75
+
76
+ when /openbsd/
77
+ # OpenBSD branch contributed by Guillaume Sellier.
78
+
79
+ # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
80
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++ -fPIC"
81
+ CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
82
+
83
+ when /darwin/
84
+ # on Unix we need a g++ link, not gcc.
85
+ # Ff line contributed by Daniel Harple.
86
+ CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
87
+
88
+ when /linux/
89
+ # on Unix we need a g++ link, not gcc.
90
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
91
+
92
+ when /aix/
93
+ # on Unix we need a g++ link, not gcc.
94
+ CONFIG['LDSHARED'] = "$(CXX) -shared -Wl,-G"
95
+
96
+ when /cygwin/
97
+ # For rubies built with Cygwin, CXX may be set to CC, which is just
98
+ # a wrapper for gcc.
99
+ # This will compile, but it will not link to the C++ std library.
100
+ # Explicitly set CXX to use g++.
101
+ CONFIG['CXX'] = "g++"
102
+ # on Unix we need a g++ link, not gcc.
103
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
104
+
105
+ else
106
+ # on Unix we need a g++ link, not gcc.
107
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
108
+ end
109
+
110
+ create_makefile "fastfilereaderext"
@@ -0,0 +1,216 @@
1
+ /*****************************************************************************
2
+
3
+ $Id: mapper.cpp 4527 2007-07-04 10:21:34Z francis $
4
+
5
+ File: mapper.cpp
6
+ Date: 02Jul07
7
+
8
+ Copyright (C) 2007 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: garbagecat10
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
+ //////////////////////////////////////////////////////////////////////
22
+ // UNIX implementation
23
+ //////////////////////////////////////////////////////////////////////
24
+
25
+
26
+ #ifdef OS_UNIX
27
+
28
+ #include <sys/types.h>
29
+ #include <sys/stat.h>
30
+ #include <sys/mman.h>
31
+ #include <fcntl.h>
32
+ #include <errno.h>
33
+
34
+ #include <iostream>
35
+ #include "unistd.h"
36
+ #include <string>
37
+ #include <cstring>
38
+ #include <stdexcept>
39
+ using namespace std;
40
+
41
+ #include "mapper.h"
42
+
43
+ /******************
44
+ Mapper_t::Mapper_t
45
+ ******************/
46
+
47
+ Mapper_t::Mapper_t (const string &filename)
48
+ {
49
+ /* We ASSUME we can open the file.
50
+ * (More precisely, we assume someone else checked before we got here.)
51
+ */
52
+
53
+ Fd = open (filename.c_str(), O_RDONLY);
54
+ if (Fd < 0)
55
+ throw runtime_error (strerror (errno));
56
+
57
+ struct stat st;
58
+ if (fstat (Fd, &st))
59
+ throw runtime_error (strerror (errno));
60
+ FileSize = st.st_size;
61
+
62
+ #ifdef OS_WIN32
63
+ MapPoint = (char*) mmap (0, FileSize, PROT_READ, MAP_SHARED, Fd, 0);
64
+ #else
65
+ MapPoint = (const char*) mmap (0, FileSize, PROT_READ, MAP_SHARED, Fd, 0);
66
+ #endif
67
+ if (MapPoint == MAP_FAILED)
68
+ throw runtime_error (strerror (errno));
69
+ }
70
+
71
+
72
+ /*******************
73
+ Mapper_t::~Mapper_t
74
+ *******************/
75
+
76
+ Mapper_t::~Mapper_t()
77
+ {
78
+ Close();
79
+ }
80
+
81
+
82
+ /***************
83
+ Mapper_t::Close
84
+ ***************/
85
+
86
+ void Mapper_t::Close()
87
+ {
88
+ // Can be called multiple times.
89
+ // Calls to GetChunk are invalid after a call to Close.
90
+ if (MapPoint) {
91
+ #ifdef CC_SUNWspro
92
+ // TODO: The void * cast works fine on Solaris 11, but
93
+ // I don't know at what point that changed from older Solaris.
94
+ munmap ((char*)MapPoint, FileSize);
95
+ #else
96
+ munmap ((void*)MapPoint, FileSize);
97
+ #endif
98
+ MapPoint = NULL;
99
+ }
100
+ if (Fd >= 0) {
101
+ close (Fd);
102
+ Fd = -1;
103
+ }
104
+ }
105
+
106
+ /******************
107
+ Mapper_t::GetChunk
108
+ ******************/
109
+
110
+ const char *Mapper_t::GetChunk (unsigned start)
111
+ {
112
+ return MapPoint + start;
113
+ }
114
+
115
+
116
+
117
+ #endif // OS_UNIX
118
+
119
+
120
+ //////////////////////////////////////////////////////////////////////
121
+ // WINDOWS implementation
122
+ //////////////////////////////////////////////////////////////////////
123
+
124
+ #ifdef OS_WIN32
125
+
126
+ #include <windows.h>
127
+
128
+ #include <iostream>
129
+ #include <string>
130
+ #include <stdexcept>
131
+ using namespace std;
132
+
133
+ #include "mapper.h"
134
+
135
+ /******************
136
+ Mapper_t::Mapper_t
137
+ ******************/
138
+
139
+ Mapper_t::Mapper_t (const string &filename)
140
+ {
141
+ /* We ASSUME we can open the file.
142
+ * (More precisely, we assume someone else checked before we got here.)
143
+ */
144
+
145
+ hFile = INVALID_HANDLE_VALUE;
146
+ hMapping = NULL;
147
+ MapPoint = NULL;
148
+ FileSize = 0;
149
+
150
+ hFile = CreateFile (filename.c_str(), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
151
+
152
+ if (hFile == INVALID_HANDLE_VALUE)
153
+ throw runtime_error ("File not found");
154
+
155
+ BY_HANDLE_FILE_INFORMATION i;
156
+ if (GetFileInformationByHandle (hFile, &i))
157
+ FileSize = i.nFileSizeLow;
158
+
159
+ hMapping = CreateFileMapping (hFile, NULL, PAGE_READWRITE, 0, 0, NULL);
160
+ if (!hMapping)
161
+ throw runtime_error ("File not mapped");
162
+
163
+ #ifdef OS_WIN32
164
+ MapPoint = (char*) MapViewOfFile (hMapping, FILE_MAP_WRITE, 0, 0, 0);
165
+ #else
166
+ MapPoint = (const char*) MapViewOfFile (hMapping, FILE_MAP_WRITE, 0, 0, 0);
167
+ #endif
168
+ if (!MapPoint)
169
+ throw runtime_error ("Mappoint not read");
170
+ }
171
+
172
+
173
+ /*******************
174
+ Mapper_t::~Mapper_t
175
+ *******************/
176
+
177
+ Mapper_t::~Mapper_t()
178
+ {
179
+ Close();
180
+ }
181
+
182
+ /***************
183
+ Mapper_t::Close
184
+ ***************/
185
+
186
+ void Mapper_t::Close()
187
+ {
188
+ // Can be called multiple times.
189
+ // Calls to GetChunk are invalid after a call to Close.
190
+ if (MapPoint) {
191
+ UnmapViewOfFile (MapPoint);
192
+ MapPoint = NULL;
193
+ }
194
+ if (hMapping != NULL) {
195
+ CloseHandle (hMapping);
196
+ hMapping = NULL;
197
+ }
198
+ if (hFile != INVALID_HANDLE_VALUE) {
199
+ CloseHandle (hFile);
200
+ hFile = INVALID_HANDLE_VALUE;
201
+ }
202
+ }
203
+
204
+
205
+ /******************
206
+ Mapper_t::GetChunk
207
+ ******************/
208
+
209
+ const char *Mapper_t::GetChunk (unsigned start)
210
+ {
211
+ return MapPoint + start;
212
+ }
213
+
214
+
215
+
216
+ #endif // OS_WINDOWS