eventmachine 0.12.2 → 0.12.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. data/Rakefile +191 -0
  2. data/{COPYING → docs/COPYING} +0 -0
  3. data/docs/ChangeLog +183 -0
  4. data/{DEFERRABLES → docs/DEFERRABLES} +1 -1
  5. data/{EPOLL → docs/EPOLL} +0 -0
  6. data/{GNU → docs/GNU} +0 -0
  7. data/docs/INSTALL +15 -0
  8. data/{KEYBOARD → docs/KEYBOARD} +0 -0
  9. data/{LEGAL → docs/LEGAL} +0 -0
  10. data/{LIGHTWEIGHT_CONCURRENCY → docs/LIGHTWEIGHT_CONCURRENCY} +1 -1
  11. data/{PURE_RUBY → docs/PURE_RUBY} +1 -1
  12. data/{README → docs/README} +1 -1
  13. data/{RELEASE_NOTES → docs/RELEASE_NOTES} +1 -1
  14. data/{SMTP → docs/SMTP} +1 -1
  15. data/{SPAWNED_PROCESSES → docs/SPAWNED_PROCESSES} +1 -1
  16. data/{TODO → docs/TODO} +1 -1
  17. data/ext/binder.cpp +1 -1
  18. data/ext/binder.h +1 -1
  19. data/ext/cmain.cpp +65 -74
  20. data/ext/cplusplus.cpp +1 -1
  21. data/ext/ed.cpp +41 -25
  22. data/ext/ed.h +10 -3
  23. data/ext/em.cpp +39 -12
  24. data/ext/em.h +13 -1
  25. data/ext/emwin.cpp +1 -1
  26. data/ext/emwin.h +1 -1
  27. data/ext/epoll.cpp +1 -1
  28. data/ext/epoll.h +1 -1
  29. data/ext/eventmachine.h +1 -1
  30. data/ext/eventmachine_cpp.h +1 -1
  31. data/ext/extconf.rb +86 -139
  32. data/ext/fastfilereader/extconf.rb +161 -0
  33. data/ext/fastfilereader/mapper.cpp +202 -0
  34. data/ext/fastfilereader/mapper.h +59 -0
  35. data/ext/fastfilereader/rubymain.cpp +127 -0
  36. data/ext/files.cpp +1 -1
  37. data/ext/files.h +1 -1
  38. data/ext/kb.cpp +1 -1
  39. data/ext/page.cpp +1 -1
  40. data/ext/page.h +1 -1
  41. data/ext/pipe.cpp +14 -7
  42. data/ext/project.h +1 -1
  43. data/ext/rubymain.cpp +56 -2
  44. data/ext/sigs.cpp +1 -1
  45. data/ext/sigs.h +1 -1
  46. data/ext/ssl.cpp +1 -1
  47. data/ext/ssl.h +1 -1
  48. data/java/src/com/rubyeventmachine/Application.java +196 -0
  49. data/java/src/com/rubyeventmachine/Connection.java +74 -0
  50. data/java/src/com/rubyeventmachine/ConnectionFactory.java +37 -0
  51. data/java/src/com/rubyeventmachine/DefaultConnectionFactory.java +46 -0
  52. data/java/src/com/rubyeventmachine/EmReactor.java +408 -0
  53. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  54. data/java/src/com/rubyeventmachine/EventableChannel.java +57 -0
  55. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +171 -0
  56. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +244 -0
  57. data/java/src/com/rubyeventmachine/PeriodicTimer.java +38 -0
  58. data/java/src/com/rubyeventmachine/Timer.java +54 -0
  59. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +108 -0
  60. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +124 -0
  61. data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  62. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  63. data/java/src/com/rubyeventmachine/tests/TestServers.java +74 -0
  64. data/java/src/com/rubyeventmachine/tests/TestTimers.java +89 -0
  65. data/lib/em/deferrable.rb +1 -1
  66. data/lib/em/eventable.rb +1 -1
  67. data/lib/em/future.rb +1 -1
  68. data/lib/em/messages.rb +1 -1
  69. data/lib/em/processes.rb +1 -1
  70. data/lib/em/spawnable.rb +1 -1
  71. data/lib/em/streamer.rb +1 -1
  72. data/lib/eventmachine.rb +138 -116
  73. data/lib/eventmachine_version.rb +2 -2
  74. data/lib/evma.rb +1 -1
  75. data/lib/evma/callback.rb +1 -1
  76. data/lib/evma/container.rb +1 -1
  77. data/lib/evma/factory.rb +1 -1
  78. data/lib/evma/protocol.rb +1 -1
  79. data/lib/evma/reactor.rb +1 -1
  80. data/lib/jeventmachine.rb +7 -2
  81. data/lib/pr_eventmachine.rb +2 -2
  82. data/lib/protocols/buftok.rb +1 -1
  83. data/lib/protocols/header_and_content.rb +1 -1
  84. data/lib/protocols/httpcli2.rb +16 -6
  85. data/lib/protocols/httpclient.rb +7 -1
  86. data/lib/protocols/line_and_text.rb +6 -2
  87. data/lib/protocols/linetext2.rb +12 -14
  88. data/lib/protocols/postgres.rb +1 -1
  89. data/lib/protocols/saslauth.rb +1 -1
  90. data/lib/protocols/smtpclient.rb +1 -1
  91. data/lib/protocols/smtpserver.rb +36 -23
  92. data/lib/protocols/stomp.rb +24 -1
  93. data/lib/protocols/tcptest.rb +1 -1
  94. data/tasks/cpp.rake +77 -0
  95. data/tasks/project.rake +78 -0
  96. data/tasks/tests.rake +192 -0
  97. data/tests/test_attach.rb +1 -1
  98. data/tests/test_basic.rb +65 -12
  99. data/tests/test_defer.rb +13 -29
  100. data/tests/test_epoll.rb +16 -21
  101. data/tests/test_errors.rb +1 -1
  102. data/tests/test_eventables.rb +4 -5
  103. data/tests/test_exc.rb +1 -1
  104. data/tests/test_futures.rb +1 -1
  105. data/tests/test_hc.rb +185 -236
  106. data/tests/test_httpclient.rb +1 -1
  107. data/tests/test_httpclient2.rb +28 -6
  108. data/tests/test_kb.rb +2 -2
  109. data/tests/test_ltp.rb +139 -141
  110. data/tests/test_ltp2.rb +1 -1
  111. data/tests/test_next_tick.rb +1 -1
  112. data/tests/test_processes.rb +1 -1
  113. data/tests/test_pure.rb +3 -2
  114. data/tests/test_running.rb +1 -1
  115. data/tests/test_sasl.rb +1 -1
  116. data/tests/test_send_file.rb +56 -51
  117. data/tests/test_servers.rb +26 -36
  118. data/tests/test_smtpclient.rb +46 -44
  119. data/tests/test_smtpserver.rb +1 -1
  120. data/tests/test_spawn.rb +1 -1
  121. data/tests/test_ssl_args.rb +68 -0
  122. data/tests/test_timers.rb +15 -9
  123. data/tests/test_ud.rb +1 -1
  124. data/tests/testem.rb +30 -4
  125. metadata +69 -34
@@ -1,4 +1,4 @@
1
- # $Id: eventmachine_version.rb 785 2008-09-15 09:46:23Z francis $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -25,7 +25,7 @@
25
25
 
26
26
  module EventMachine
27
27
 
28
- VERSION = "0.12.2"
28
+ VERSION = "0.12.4"
29
29
 
30
30
  end
31
31
 
@@ -1,4 +1,4 @@
1
- # $Id: evma.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -1,4 +1,4 @@
1
- # $Id: callback.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -1,4 +1,4 @@
1
- # $Id: container.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -1,4 +1,4 @@
1
- # $Id: factory.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -1,4 +1,4 @@
1
- # $Id: protocol.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -1,4 +1,4 @@
1
- # $Id: reactor.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -1,4 +1,4 @@
1
- # $Id: jeventmachine.rb 771 2008-08-28 00:45:23Z francis $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -28,7 +28,7 @@
28
28
  # For C++ EventMachines, the analogous functionality is found in ext/rubymain.cpp,
29
29
  # which is a garden-variety Ruby-extension glue module.
30
30
 
31
-
31
+ require 'java'
32
32
  require 'em_reactor'
33
33
 
34
34
  module EventMachine
@@ -49,6 +49,11 @@ module EventMachine
49
49
  EventMachine::event_callback a1, a2, s
50
50
  end
51
51
  end
52
+ class Connection < com.rubyeventmachine.Connection
53
+ def associate_callback_target sig
54
+ # No-op for the time being.
55
+ end
56
+ end
52
57
  def self.initialize_event_machine
53
58
  @em = JEM.new
54
59
  end
@@ -1,4 +1,4 @@
1
- # $Id: pr_eventmachine.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -578,7 +578,7 @@ module EventMachine
578
578
  end
579
579
 
580
580
  if w < data.length
581
- $outbound_q.unshift data[w..-1]
581
+ @outbound_q.unshift data[w..-1]
582
582
  break
583
583
  end
584
584
  rescue Errno::EAGAIN
@@ -124,4 +124,4 @@ class BufferedTokenizer
124
124
  def empty?
125
125
  @input.empty?
126
126
  end
127
- end
127
+ end
@@ -1,4 +1,4 @@
1
- # $Id: header_and_content.rb 782 2008-09-13 20:02:17Z francis $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -1,4 +1,4 @@
1
- # $Id: httpcli2.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -28,7 +28,17 @@
28
28
  module EventMachine
29
29
  module Protocols
30
30
 
31
-
31
+ # = Example
32
+ #
33
+ #
34
+ # EM.run{
35
+ # include EM::Protocols
36
+ # conn = HttpClient2.connect 'google.com', 80
37
+ #
38
+ # req = conn.get('/')
39
+ # req.callback{
40
+ # p(req.content)
41
+ # }
32
42
  class HttpClient2 < Connection
33
43
  include LineText2
34
44
 
@@ -119,12 +129,12 @@ module Protocols
119
129
  if chunksize > 0
120
130
  @conn.set_text_mode(ln.to_i(16))
121
131
  else
122
- @content = @content.join
132
+ @content = @content ? @content.join : ''
123
133
  @chunk_trailer = true
124
134
  end
125
135
  else
126
136
  # We correctly come here after each chunk gets read.
127
- p "Got A BLANK chunk line"
137
+ # p "Got A BLANK chunk line"
128
138
  end
129
139
 
130
140
  end
@@ -134,7 +144,7 @@ module Protocols
134
144
  # We get a single chunk. Append it to the incoming content and switch back to line mode.
135
145
  #
136
146
  def receive_chunked_text text
137
- p "RECEIVED #{text.length} CHUNK"
147
+ # p "RECEIVED #{text.length} CHUNK"
138
148
  (@content ||= []) << text
139
149
  end
140
150
 
@@ -224,7 +234,7 @@ module Protocols
224
234
 
225
235
  h,prt,ssl = args[:host], Integer(args[:port]), (args[:tls] || args[:ssl])
226
236
  conn = EM.connect( h, prt, self )
227
- # TODO, start_tls if necessary
237
+ conn.start_tls if ssl
228
238
  conn.set_default_host_header( h, prt, ssl )
229
239
  conn
230
240
  end
@@ -1,4 +1,4 @@
1
- # $Id: httpclient.rb 786 2008-09-16 07:33:27Z francis $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -65,6 +65,12 @@ class HttpClient < Connection
65
65
  # Refactor this code so that protocol errors all get handled one way (an exception?),
66
66
  # instead of sprinkling set_deferred_status :failed calls everywhere.
67
67
 
68
+ # === Arg list
69
+ # :host => 'ip/dns', :port => fixnum, :verb => 'GET', :request => 'path',
70
+ # :basic_auth => {:username => '', :password => ''}, :content => 'content',
71
+ # :contenttype => 'text/plain', :query_string => '', :host_header => '',
72
+ # :cookie => ''
73
+
68
74
  def self.request( args = {} )
69
75
  args[:port] ||= 80
70
76
  EventMachine.connect( args[:host], args[:port], self ) {|c|
@@ -1,4 +1,4 @@
1
- # $Id: line_and_text.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -27,7 +27,11 @@ require File.dirname(__FILE__) + '/buftok'
27
27
 
28
28
  module EventMachine
29
29
  module Protocols
30
-
30
+ # A protocol that handles line-oriented data with interspersed binary text.
31
+ #
32
+ # This version is optimized for performance. See EventMachine::Protocols::LineText2
33
+ # for a version which is optimized for correctness with regard to binary text blocks
34
+ # that can switch back to line mode.
31
35
  class LineAndTextProtocol < Connection
32
36
  MaxLineLength = 16*1024
33
37
  MaxBinaryLength = 32*1024*1024
@@ -1,4 +1,4 @@
1
- # $Id: linetext2.rb 778 2008-09-13 19:54:18Z francis $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -24,22 +24,20 @@
24
24
  #
25
25
  #
26
26
 
27
-
28
- # In the grand, time-honored tradition of re-inventing the wheel, we offer
29
- # here YET ANOTHER protocol that handles line-oriented data with interspersed
30
- # binary text. This one trades away some of the performance optimizations of
31
- # EventMachine::Protocols::LineAndTextProtocol in order to get better correctness
32
- # with regard to binary text blocks that can switch back to line mode. It also
33
- # permits the line-delimiter to change in midstream.
34
- # This was originally written to support Stomp.
35
-
36
- # TODO! We're not enforcing the limits on header lengths and text-lengths.
37
- # When we get around to that, call #receive_error if the user defined it, otherwise
38
- # throw exceptions.
39
-
40
27
  module EventMachine
41
28
  module Protocols
29
+ # In the grand, time-honored tradition of re-inventing the wheel, we offer
30
+ # here YET ANOTHER protocol that handles line-oriented data with interspersed
31
+ # binary text. This one trades away some of the performance optimizations of
32
+ # EventMachine::Protocols::LineAndTextProtocol in order to get better correctness
33
+ # with regard to binary text blocks that can switch back to line mode. It also
34
+ # permits the line-delimiter to change in midstream.
35
+ # This was originally written to support Stomp.
42
36
  module LineText2
37
+ # TODO! We're not enforcing the limits on header lengths and text-lengths.
38
+ # When we get around to that, call #receive_error if the user defined it, otherwise
39
+ # throw exceptions.
40
+
43
41
  MaxLineLength = 16*1024
44
42
  MaxBinaryLength = 32*1024*1024
45
43
 
@@ -1,5 +1,5 @@
1
1
  #
2
- # $Id: postgres.rb 783 2008-09-14 02:48:46Z francis $
2
+ # $Id$
3
3
  #
4
4
  # Author:: Francis Cianfrocca (gmail: blackhedd)
5
5
  # Homepage:: http://rubyeventmachine.com
@@ -1,4 +1,4 @@
1
- # $Id: saslauth.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -1,4 +1,4 @@
1
- # $Id: smtpclient.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -1,4 +1,4 @@
1
- # $Id: smtpserver.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -119,40 +119,53 @@ module Protocols
119
119
 
120
120
  def receive_line ln
121
121
  @@parms[:verbose] and $>.puts ">>> #{ln}"
122
- if @state.include?(:data)
123
- process_data_line ln
124
- elsif ln =~ EhloRegex
122
+
123
+ return process_data_line ln if @state.include?(:data)
124
+
125
+ case ln
126
+ when EhloRegex
125
127
  process_ehlo $'.dup
126
- elsif ln =~ HeloRegex
128
+ when HeloRegex
127
129
  process_helo $'.dup
128
- elsif ln =~ MailFromRegex
130
+ when MailFromRegex
129
131
  process_mail_from $'.dup
130
- elsif ln =~ RcptToRegex
132
+ when RcptToRegex
131
133
  process_rcpt_to $'.dup
132
- elsif ln =~ DataRegex
134
+ when DataRegex
133
135
  process_data
134
- elsif ln =~ RsetRegex
136
+ when RsetRegex
135
137
  process_rset
136
- elsif ln =~ VrfyRegex
138
+ when VrfyRegex
137
139
  process_vrfy
138
- elsif ln =~ ExpnRegex
140
+ when ExpnRegex
139
141
  process_expn
140
- elsif ln =~ HelpRegex
142
+ when HelpRegex
141
143
  process_help
142
- elsif ln =~ NoopRegex
144
+ when NoopRegex
143
145
  process_noop
144
- elsif ln =~ QuitRegex
146
+ when QuitRegex
145
147
  process_quit
146
- elsif ln =~ StarttlsRegex
148
+ when StarttlsRegex
147
149
  process_starttls
148
- elsif ln =~ AuthRegex
150
+ when AuthRegex
149
151
  process_auth $'.dup
150
152
  else
151
153
  process_unknown
152
154
  end
153
155
  end
154
156
 
155
-
157
+ # TODO - implement this properly, the implementation is a stub!
158
+ def process_vrfy
159
+ send_data "250 Ok, but unimplemented\r\n"
160
+ end
161
+ # TODO - implement this properly, the implementation is a stub!
162
+ def process_help
163
+ send_data "250 Ok, but unimplemented\r\n"
164
+ end
165
+ # TODO - implement this properly, the implementation is a stub!
166
+ def process_expn
167
+ send_data "250 Ok, but unimplemented\r\n"
168
+ end
156
169
 
157
170
  #--
158
171
  # This is called at several points to restore the protocol state
@@ -289,8 +302,8 @@ module Protocols
289
302
  d = receive_data_command
290
303
 
291
304
  if d.respond_to?(:callback)
292
- d.callback &succeeded
293
- d.errback &failed
305
+ d.callback(&succeeded)
306
+ d.errback(&failed)
294
307
  else
295
308
  (d ? succeeded : failed).call
296
309
  end
@@ -383,8 +396,8 @@ module Protocols
383
396
  d = receive_recipient rcpt
384
397
 
385
398
  if d.respond_to?(:set_deferred_status)
386
- d.callback &succeeded
387
- d.errback &failed
399
+ d.callback(&succeeded)
400
+ d.errback(&failed)
388
401
  else
389
402
  (d ? succeeded : failed).call
390
403
  end
@@ -433,8 +446,8 @@ module Protocols
433
446
  d = receive_message
434
447
 
435
448
  if d.respond_to?(:set_deferred_status)
436
- d.callback &succeeded
437
- d.errback &failed
449
+ d.callback(&succeeded)
450
+ d.errback(&failed)
438
451
  else
439
452
  (d ? succeeded : failed).call
440
453
  end
@@ -1,4 +1,4 @@
1
- # $Id: stomp.rb 738 2008-07-06 01:01:04Z francis $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -31,6 +31,29 @@ module EventMachine
31
31
 
32
32
  # Implements Stomp (http://docs.codehaus.org/display/STOMP/Protocol).
33
33
  #
34
+ # == Usage example
35
+ #
36
+ # class StompClient < EM::Connection
37
+ # include EM::Protocols::Stomp
38
+ #
39
+ # def connection_completed
40
+ # connect :login => 'guest', :passcode => 'guest'
41
+ # end
42
+ #
43
+ # def receive_msg msg
44
+ # if msg.command == "CONNECTED"
45
+ # subscribe '/some/topic'
46
+ # else
47
+ # p ['got a message', msg]
48
+ # puts msg.body
49
+ # end
50
+ # end
51
+ # end
52
+ #
53
+ # EM.run{
54
+ # EM.connect 'localhost', 61613, StompClient
55
+ # }
56
+ #
34
57
  module Stomp
35
58
  include LineText2
36
59
 
@@ -1,4 +1,4 @@
1
- # $Id: tcptest.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -0,0 +1,77 @@
1
+ # EventMachine C++ Rakefile Stab Case
2
+ # TODO : track header files as a build dependency...
3
+ # TODO : cross platform support
4
+ # TODO : configure style functionality
5
+ namespace :cpp do
6
+
7
+ require 'rake/clean'
8
+
9
+ # *nix only atm...
10
+ module Cpp
11
+ class <<self
12
+ def cpp; "g++"; end
13
+ def archive; "ar"; end
14
+ def compile file, output, includes=nil, flags=nil
15
+ sh %{#{cpp} #{file} #{includes} #{flags} -c -o #{output}}
16
+ end
17
+ def link file, output, libs=nil, flags=nil
18
+ sh %{#{cpp} #{file} #{libs} #{flags} -o #{output}}
19
+ end
20
+ def static output, files
21
+ sh %{#{archive} cr #{output} #{files}}
22
+ end
23
+ end
24
+ end
25
+
26
+ module EmConfig
27
+ Path = ENV['EVENTMACHINE_SOURCE'] || 'ext'
28
+ Sources = FileList["#{Path}/*.cpp"]
29
+ Sources.delete_if { |s| /ruby/ =~ s }
30
+ Compiled = Sources.sub(%r{^#{Path}/(.*)\.cpp}, "#{Path}/\\1.o")
31
+
32
+ Flags = "-O2 -pipe -fno-common -DOS_UNIX -DWITHOUT_SSL"
33
+ Includes = ""
34
+ Libs = ''
35
+ end
36
+ CLEAN.include(EmConfig::Compiled)
37
+
38
+ rule %r{^#{EmConfig::Path}/.*\.o$} => [proc { |targ|
39
+ targ.sub(%r{^#{EmConfig::Path}/(.*)\.o$}, "#{EmConfig::Path}/\\1.cpp")
40
+ }] do |t|
41
+ Cpp.compile t.source, t.name, EmConfig::Includes, EmConfig::Flags
42
+ end
43
+
44
+ file "#{EmConfig::Path}/libeventmachine.a" => EmConfig::Compiled do |t|
45
+ Cpp.static t.name, EmConfig::Compiled
46
+ end
47
+ CLEAN.include("#{EmConfig::Path}/libeventmachine.a")
48
+
49
+ module AppConfig
50
+ Appname = 'echo_em'
51
+ Sources = FileList['*.cpp']
52
+ Compiled = Sources.sub(%r{^(.*)\.cpp}, '\\1.o')
53
+
54
+ Flags = ["", EmConfig::Flags].join(' ')
55
+ Includes = ["-I. -I#{EmConfig::Path}", EmConfig::Includes].join(' ')
56
+ Libs = ["-L#{EmConfig::Path} -leventmachine", EmConfig::Libs].join(' ')
57
+ end
58
+ CLEAN.include(AppConfig::Compiled)
59
+ CLEAN.include(AppConfig::Appname)
60
+
61
+ rule %r{^.*\.o$} => [proc { |targ|
62
+ targ.sub(%r{^(.*)\.o$}, '\\1.cpp')
63
+ }] do |t|
64
+ Cpp.compile t.source, t.name, AppConfig::Includes, AppConfig::Flags
65
+ end
66
+
67
+ file AppConfig::Appname => ["#{EmConfig::Path}/libeventmachine.a", AppConfig::Compiled] do |t|
68
+ Cpp.link AppConfig::Compiled, t.name, AppConfig::Libs, AppConfig::Flags
69
+ end
70
+
71
+ task :build => AppConfig::Appname
72
+
73
+ task :run => AppConfig::Appname do
74
+ sh "./#{AppConfig::Appname}"
75
+ end
76
+
77
+ end