eventmachine 0.12.2 → 0.12.4

Sign up to get free protection for your applications and to get access to all the features.
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
data/ext/ed.h CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: ed.h 785 2008-09-15 09:46:23Z francis $
3
+ $Id$
4
4
 
5
5
  File: ed.h
6
6
  Date: 06Apr06
@@ -85,7 +85,14 @@ class EventableDescriptor: public Bindable_t
85
85
 
86
86
  protected:
87
87
  enum {
88
- PendingConnectTimeout = 4 // can easily be made an instance variable
88
+ // 4 seconds is too short, most other libraries default to OS settings
89
+ // which in 2.6 kernel defaults to a 60 second connect timeout.
90
+ //
91
+ // Curl-Multi: http://curl.haxx.se/mail/lib-2001-01/0019.html
92
+ //
93
+ // updating to 50 seconds, so we catch it before the OS does
94
+
95
+ PendingConnectTimeout = 50 // can easily be made an instance variable
89
96
  };
90
97
 
91
98
  void (*EventCallback)(const char*, int, const char*, int);
@@ -139,7 +146,7 @@ class ConnectionDescriptor: public EventableDescriptor
139
146
 
140
147
  int SendOutboundData (const char*, int);
141
148
 
142
- void SetConnectPending (bool f) { bConnectPending = f; }
149
+ void SetConnectPending (bool f);
143
150
 
144
151
  void SetNotifyReadable (bool readable) { bNotifyReadable = readable; }
145
152
  void SetNotifyWritable (bool writable) { bNotifyWritable = writable; }
data/ext/em.cpp CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: em.cpp 785 2008-09-15 09:46:23Z francis $
3
+ $Id$
4
4
 
5
5
  File: em.cpp
6
6
  Date: 06Apr06
@@ -426,7 +426,16 @@ bool EventMachine_t::_RunEpollOnce()
426
426
  #ifdef HAVE_EPOLL
427
427
  assert (epfd != -1);
428
428
  struct epoll_event ev [MaxEpollDescriptors];
429
- int s = epoll_wait (epfd, ev, MaxEpollDescriptors, 50);
429
+ int s;
430
+
431
+ #ifdef BUILD_FOR_RUBY
432
+ TRAP_BEG;
433
+ #endif
434
+ s = epoll_wait (epfd, ev, MaxEpollDescriptors, 50);
435
+ #ifdef BUILD_FOR_RUBY
436
+ TRAP_END;
437
+ #endif
438
+
430
439
  if (s > 0) {
431
440
  for (int i=0; i < s; i++) {
432
441
  EventableDescriptor *ed = (EventableDescriptor*) ev[i].data.ptr;
@@ -511,8 +520,11 @@ bool EventMachine_t::_RunEpollOnce()
511
520
  }
512
521
  }
513
522
 
514
- timeval tv = {0,0};
515
- EmSelect (0, NULL, NULL, NULL, &tv);
523
+ #ifdef BUILD_FOR_RUBY
524
+ if (!rb_thread_alone()) {
525
+ rb_thread_schedule();
526
+ }
527
+ #endif
516
528
 
517
529
  return true;
518
530
  #else
@@ -533,7 +545,14 @@ bool EventMachine_t::_RunKqueueOnce()
533
545
  struct kevent Karray [maxKevents];
534
546
  struct timespec ts = {0, 10000000}; // Too frequent. Use blocking_region
535
547
 
536
- int k = kevent (kqfd, NULL, 0, Karray, maxKevents, &ts);
548
+ int k;
549
+ #ifdef BUILD_FOR_RUBY
550
+ TRAP_BEG;
551
+ #endif
552
+ k = kevent (kqfd, NULL, 0, Karray, maxKevents, &ts);
553
+ #ifdef BUILD_FOR_RUBY
554
+ TRAP_END;
555
+ #endif
537
556
  struct kevent *ke = Karray;
538
557
  while (k > 0) {
539
558
  EventableDescriptor *ed = (EventableDescriptor*) (ke->udata);
@@ -587,8 +606,11 @@ bool EventMachine_t::_RunKqueueOnce()
587
606
 
588
607
 
589
608
  // TODO, replace this with rb_thread_blocking_region for 1.9 builds.
590
- timeval tv = {0,0};
591
- EmSelect (0, NULL, NULL, NULL, &tv);
609
+ #ifdef BUILD_FOR_RUBY
610
+ if (!rb_thread_alone()) {
611
+ rb_thread_schedule();
612
+ }
613
+ #endif
592
614
 
593
615
  return true;
594
616
  #else
@@ -631,6 +653,7 @@ SelectData_t::SelectData_t()
631
653
  }
632
654
 
633
655
 
656
+ #ifdef BUILD_FOR_RUBY
634
657
  /*****************
635
658
  _SelectDataSelect
636
659
  *****************/
@@ -651,7 +674,7 @@ SelectData_t::_Select
651
674
  int SelectData_t::_Select()
652
675
  {
653
676
  #ifdef HAVE_TBR
654
- rb_thread_blocking_region (_SelectDataSelect, (void*)this, RB_UBF_DFL, 0);
677
+ rb_thread_blocking_region (_SelectDataSelect, (void*)this, RUBY_UBF_IO, 0);
655
678
  return nSockets;
656
679
  #endif
657
680
 
@@ -659,6 +682,7 @@ int SelectData_t::_Select()
659
682
  return EmSelect (maxsocket+1, &fdreads, &fdwrites, NULL, &tv);
660
683
  #endif
661
684
  }
685
+ #endif
662
686
 
663
687
 
664
688
 
@@ -738,7 +762,7 @@ bool EventMachine_t::_RunSelectOnce()
738
762
  //timeval tv = Quantum;
739
763
  SelectData.tv = Quantum;
740
764
  int s = SelectData._Select();
741
- //rb_thread_blocking_region(xxx,(void*)&SelectData,RB_UBF_DFL,0);
765
+ //rb_thread_blocking_region(xxx,(void*)&SelectData,RUBY_UBF_IO,0);
742
766
  //int s = EmSelect (SelectData.maxsocket+1, &(SelectData.fdreads), &(SelectData.fdwrites), NULL, &(SelectData.tv));
743
767
  //int s = SelectData.nSockets;
744
768
  if (s > 0) {
@@ -1183,14 +1207,15 @@ const char *EventMachine_t::AttachFD (int fd, bool notify_readable, bool notify_
1183
1207
  #endif
1184
1208
 
1185
1209
  {// Check for duplicate descriptors
1186
- for (size_t i = 0; i < Descriptors.size(); i++) {
1210
+ size_t i;
1211
+ for (i = 0; i < Descriptors.size(); i++) {
1187
1212
  EventableDescriptor *ed = Descriptors[i];
1188
1213
  assert (ed);
1189
1214
  if (ed->GetSocket() == fd)
1190
1215
  throw std::runtime_error ("adding existing descriptor");
1191
1216
  }
1192
1217
 
1193
- for (size_t i = 0; i < NewDescriptors.size(); i++) {
1218
+ for (i = 0; i < NewDescriptors.size(); i++) {
1194
1219
  EventableDescriptor *ed = NewDescriptors[i];
1195
1220
  assert (ed);
1196
1221
  if (ed->GetSocket() == fd)
@@ -1284,7 +1309,9 @@ struct sockaddr *name2address (const char *server, int port, int *family, int *b
1284
1309
  // Return NULL if no resolution.
1285
1310
 
1286
1311
  static struct sockaddr_in in4;
1312
+ #ifndef __CYGWIN__
1287
1313
  static struct sockaddr_in6 in6;
1314
+ #endif
1288
1315
  struct hostent *hp;
1289
1316
 
1290
1317
  if (!server || !*server)
@@ -1301,7 +1328,7 @@ struct sockaddr *name2address (const char *server, int port, int *family, int *b
1301
1328
  return (struct sockaddr*)&in4;
1302
1329
  }
1303
1330
 
1304
- #ifdef OS_UNIX
1331
+ #if defined(OS_UNIX) && !defined(__CYGWIN__)
1305
1332
  memset (&in6, 0, sizeof(in6));
1306
1333
  if (inet_pton (AF_INET6, server, in6.sin6_addr.s6_addr) > 0) {
1307
1334
  if (family)
data/ext/em.h CHANGED
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: em.h 785 2008-09-15 09:46:23Z francis $
3
+ $Id$
4
4
 
5
5
  File: em.h
6
6
  Date: 06Apr06
@@ -33,6 +33,18 @@ See the file COPYING for complete licensing information.
33
33
  #ifdef BUILD_FOR_RUBY
34
34
  #include <ruby.h>
35
35
  #define EmSelect rb_thread_select
36
+
37
+ #ifdef HAVE_RBTRAP
38
+ #include <rubysig.h>
39
+ #else
40
+ #define TRAP_BEG
41
+ #define TRAP_END
42
+ #endif
43
+
44
+ // 1.9.0 compat
45
+ #ifndef RUBY_UDF_IO
46
+ #define RUBY_UDF_IO RB_UDF_DFL
47
+ #endif
36
48
  #else
37
49
  #define EmSelect select
38
50
  #endif
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: emwin.cpp 668 2008-01-04 23:00:34Z blackhedd $
3
+ $Id$
4
4
 
5
5
  File: emwin.cpp
6
6
  Date: 05May06
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: emwin.h 668 2008-01-04 23:00:34Z blackhedd $
3
+ $Id$
4
4
 
5
5
  File: emwin.h
6
6
  Date: 05May06
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: epoll.cpp 668 2008-01-04 23:00:34Z blackhedd $
3
+ $Id$
4
4
 
5
5
  File: epoll.cpp
6
6
  Date: 06Jun07
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: epoll.h 668 2008-01-04 23:00:34Z blackhedd $
3
+ $Id$
4
4
 
5
5
  File: epoll.h
6
6
  Date: 06Jun07
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: eventmachine.h 785 2008-09-15 09:46:23Z francis $
3
+ $Id$
4
4
 
5
5
  File: eventmachine.h
6
6
  Date: 15Apr06
@@ -1,6 +1,6 @@
1
1
  /*****************************************************************************
2
2
 
3
- $Id: eventmachine_cpp.h 668 2008-01-04 23:00:34Z blackhedd $
3
+ $Id$
4
4
 
5
5
  File: eventmachine_cpp.h
6
6
  Date: 27Jul07
@@ -1,15 +1,15 @@
1
- # $Id: extconf.rb 677 2008-01-08 20:37:24Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  #----------------------------------------------------------------------------
4
4
  #
5
5
  # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
6
6
  # Gmail: blackhedd
7
- #
7
+ #
8
8
  # This program is free software; you can redistribute it and/or modify
9
9
  # it under the terms of either: 1) the GNU General Public License
10
10
  # as published by the Free Software Foundation; either version 2 of the
11
11
  # License, or (at your option) any later version; or 2) Ruby's License.
12
- #
12
+ #
13
13
  # See the file COPYING for complete licensing information.
14
14
  #
15
15
  #---------------------------------------------------------------------------
@@ -18,56 +18,59 @@
18
18
  # We have to munge LDSHARED because this code needs a C++ link.
19
19
  #
20
20
 
21
+ def check_libs libs = [], fatal = false
22
+ libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
23
+ end
24
+
25
+ def check_heads heads = [], fatal = false
26
+ heads.all? { |head| have_header(head) || (abort("could not find header: #{head}") if fatal)}
27
+ end
28
+
29
+ def add_define(name)
30
+ $defs.push("-D#{name}")
31
+ end
32
+
21
33
  require 'mkmf'
22
34
 
23
- flags = []
35
+ add_define 'BUILD_FOR_RUBY'
36
+ add_define 'HAVE_RBTRAP' if have_var('rb_trap_immediate', ['ruby.h', 'rubysig.h'])
37
+ add_define "HAVE_TBR" if have_func('rb_thread_blocking_region')# and have_macro('RUBY_UBF_IO', 'ruby.h')
24
38
 
25
- case RUBY_PLATFORM.split('-',2)[1]
26
- when 'mswin32', 'mingw32', 'bccwin32'
27
- unless have_header('windows.h') and
28
- have_header('winsock.h') and
29
- have_library('kernel32') and
30
- have_library('rpcrt4') and
31
- have_library('gdi32')
32
- exit
33
- end
39
+ # Minor platform details between *nix and Windows:
34
40
 
35
- flags << "-D OS_WIN32"
36
- flags << '-D BUILD_FOR_RUBY'
37
- flags << "-EHs"
38
- flags << "-GR"
39
-
40
- dir_config('ssl')
41
- if have_library('ssleay32') and
42
- have_library('libeay32') and
43
- have_header('openssl/ssl.h') and
44
- have_header('openssl/err.h')
45
- flags << '-D WITH_SSL'
46
- else
47
- flags << '-D WITHOUT_SSL'
48
- end
41
+ if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
42
+ GNU_CHAIN = $1 == 'mingw'
43
+ OS_WIN32 = true
44
+ add_define "OS_WIN32"
45
+ else
46
+ GNU_CHAIN = true
47
+ OS_UNIX = true
48
+ add_define 'OS_UNIX'
49
49
 
50
- when /solaris/
51
- unless have_library('pthread') and
52
- have_library('nsl') and
53
- have_library('socket')
54
- exit
55
- end
50
+ add_define "HAVE_KQUEUE" if have_header("sys/event.h") and have_header("sys/queue.h")
51
+
52
+ # check_libs(%w[pthread], true)
53
+ end
54
+
55
+ # Main platform invariances:
56
56
 
57
- flags << '-D OS_UNIX'
58
- flags << '-D OS_SOLARIS8'
59
- flags << '-D BUILD_FOR_RUBY'
57
+ case RUBY_PLATFORM
58
+ when /mswin32/, /mingw32/, /bccwin32/
59
+ check_heads(%w[windows.h winsock.h], true)
60
+ check_libs(%w[kernel32 rpcrt4 gdi32], true)
60
61
 
61
- dir_config('ssl')
62
- if have_library('ssl') and
63
- have_library('crypto') and
64
- have_header('openssl/ssl.h') and
65
- have_header('openssl/err.h')
66
- flags << '-D WITH_SSL'
62
+ if GNU_CHAIN
63
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
67
64
  else
68
- flags << '-D WITHOUT_SSL'
65
+ $defs.push "-EHs"
66
+ $defs.push "-GR"
69
67
  end
70
68
 
69
+ when /solaris/
70
+ check_libs(%w[nsl socket], true)
71
+
72
+ add_define 'OS_SOLARIS8'
73
+
71
74
  # on Unix we need a g++ link, not gcc.
72
75
  CONFIG['LDSHARED'] = "$(CXX) -shared"
73
76
 
@@ -77,127 +80,71 @@ when /solaris/
77
80
  CONFIG['CCDLFLAGS'] = "-fPIC"
78
81
  end
79
82
 
80
- when /openbsd/
83
+ when /openbsd/
81
84
  # OpenBSD branch contributed by Guillaume Sellier.
82
- flags << '-DOS_UNIX'
83
- flags << '-DBUILD_FOR_RUBY'
84
-
85
- dir_config('ssl') # here I don't know why we have to check -lcrypto before -lssl otherwise -lssl is not found
86
- if have_library('crypto') and
87
- have_library('ssl') and
88
- have_header('openssl/ssl.h') and
89
- have_header('openssl/err.h')
90
- flags << '-DWITH_SSL'
91
- else
92
- flags << '-DWITHOUT_SSL'
93
- end
85
+
94
86
  # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
95
87
  CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
96
88
 
97
-
98
89
  when /darwin/
99
- flags << '-DOS_UNIX'
100
- flags << '-DBUILD_FOR_RUBY'
101
-
102
- if have_header("sys/event.h") and have_header("sys/queue.h")
103
- flags << "-DHAVE_KQUEUE"
104
- end
105
90
 
106
- dir_config('ssl')
107
- if have_library('ssl') and
108
- have_library('crypto') and
109
- have_library('C') and
110
- have_header('openssl/ssl.h') and
111
- have_header('openssl/err.h')
112
- flags << '-DWITH_SSL'
113
- else
114
- flags << '-DWITHOUT_SSL'
115
- end
116
91
  # on Unix we need a g++ link, not gcc.
117
92
  # Ff line contributed by Daniel Harple.
118
93
  CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
119
94
 
120
95
  when /linux/
121
- unless have_library('pthread')
122
- exit
123
- end
124
-
125
- flags << '-DOS_UNIX'
126
- flags << '-DBUILD_FOR_RUBY'
127
96
 
128
97
  # Original epoll test is inadequate because 2.4 kernels have the header
129
98
  # but not the code.
130
- #flags << '-DHAVE_EPOLL' if have_header('sys/epoll.h')
99
+ # add_define 'HAVE_EPOLL' if have_header('sys/epoll.h')
131
100
  if have_header('sys/epoll.h')
132
- File.open("hasEpollTest.c", "w") {|f|
133
- f.puts "#include <sys/epoll.h>"
134
- f.puts "int main() { epoll_create(1024); return 0;}"
135
- }
136
- (e = system( "gcc hasEpollTest.c -o hasEpollTest " )) and (e = $?.to_i)
137
- `rm -f hasEpollTest.c hasEpollTest`
138
- flags << '-DHAVE_EPOLL' if e == 0
139
- end
140
-
141
- if have_func('rb_thread_blocking_region') and have_macro('RB_UBF_DFL', 'ruby.h')
142
- flags << "-DHAVE_TBR"
101
+ File.open("hasEpollTest.c", "w") {|f|
102
+ f.puts "#include <sys/epoll.h>"
103
+ f.puts "int main() { epoll_create(1024); return 0;}"
104
+ }
105
+ (e = system( "gcc hasEpollTest.c -o hasEpollTest " )) and (e = $?.to_i)
106
+ `rm -f hasEpollTest.c hasEpollTest`
107
+ add_define 'HAVE_EPOLL' if e == 0
143
108
  end
144
109
 
145
- dir_config('ssl', "#{ENV['OPENSSL']}/include", ENV['OPENSSL'])
146
- # Check for libcrypto twice, before and after ssl. That's because on some platforms
147
- # and openssl versions, libssl will emit unresolved externals from crypto. It
148
- # would be cleaner to simply check crypto first, but that doesn't always work in
149
- # Ruby. The order we check them doesn't seem to control the order in which they're
150
- # emitted into the link command. This is pretty weird, I have to admit.
151
- if have_library('crypto') and
152
- have_library('ssl') and
153
- have_library('crypto') and
154
- have_header('openssl/ssl.h') and
155
- have_header('openssl/err.h')
156
- flags << '-DWITH_SSL'
157
- else
158
- flags << '-DWITHOUT_SSL'
159
- end
160
110
  # on Unix we need a g++ link, not gcc.
161
111
  CONFIG['LDSHARED'] = "$(CXX) -shared"
162
-
163
- # Modify the mkmf constant LINK_SO so the generated shared object is stripped.
164
- # You might think modifying CONFIG['LINK_SO'] would be a better way to do this,
165
- # but it doesn't work because mkmf doesn't look at CONFIG['LINK_SO'] again after
166
- # it initializes.
167
- linkso = Object.send :remove_const, "LINK_SO"
168
- LINK_SO = linkso + "; strip $@"
169
-
170
112
  else
171
- unless have_library('pthread')
172
- exit
173
- end
174
-
175
- flags << '-DOS_UNIX'
176
- flags << '-DBUILD_FOR_RUBY'
177
-
178
- if have_header("sys/event.h") and have_header("sys/queue.h")
179
- flags << "-DHAVE_KQUEUE"
180
- end
181
-
182
- dir_config('ssl')
183
- if have_library('ssl') and
184
- have_library('crypto') and
185
- have_header('openssl/ssl.h') and
186
- have_header('openssl/err.h')
187
- flags << '-DWITH_SSL'
188
- else
189
- flags << '-DWITHOUT_SSL'
190
- end
191
113
  # on Unix we need a g++ link, not gcc.
192
114
  CONFIG['LDSHARED'] = "$(CXX) -shared"
115
+ end
193
116
 
117
+ # OpenSSL:
118
+
119
+ def manual_ssl_config
120
+ ssl_libs_heads_args = {
121
+ :unix => [%w[ssl crypto], %w[openssl/ssl.h openssl/err.h]],
122
+ :darwin => [%w[ssl crypto C], %w[openssl/ssl.h openssl/err.h]],
123
+ # openbsd and linux:
124
+ :crypto_hack => [%w[crypto ssl crypto], %w[openssl/ssl.h openssl/err.h]],
125
+ :mswin => [%w[ssleay32 libeay32], %w[openssl/ssl.h openssl/err.h]],
126
+ }
127
+
128
+ dc_flags = ['ssl']
129
+ dc_flags += ["#{ENV['OPENSSL']}/include", ENV['OPENSSL']] if /linux/ =~ RUBY_PLATFORM
130
+
131
+ libs, heads = case RUBY_PLATFORM
132
+ when /mswin/ ; ssl_libs_heads_args[:mswin]
133
+ when /mingw/ ; ssl_libs_heads_args[:unix]
134
+ when /darwin/ ; ssl_libs_heads_args[:darwin]
135
+ when /openbsd/ ; ssl_libs_heads_args[:crypto_hack]
136
+ when /linux/ ; ssl_libs_heads_args[:crypto_hack]
137
+ else ssl_libs_heads_args[:unix]
138
+ end
139
+ dir_config(*dc_flags)
140
+ check_libs(libs) and check_heads(heads)
194
141
  end
195
142
 
196
- if $CPPFLAGS
197
- $CPPFLAGS += ' ' + flags.join(' ')
143
+ # Try to use pkg_config first, fixes #73
144
+ if pkg_config('openssl') || manual_ssl_config
145
+ add_define "WITH_SSL"
198
146
  else
199
- $CFLAGS += ' ' + flags.join(' ')
147
+ add_define "WITHOUT_SSL"
200
148
  end
201
149
 
202
-
203
- create_makefile "rubyeventmachine"
150
+ create_makefile "rubyeventmachine"