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
@@ -1,77 +1,83 @@
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
-
17
- # Minor platform details between *nix and Windows:
18
-
19
- if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
20
- GNU_CHAIN = $1 == 'mingw'
21
- OS_WIN32 = true
22
- add_define "OS_WIN32"
23
- else
24
- GNU_CHAIN = true
25
- OS_UNIX = true
26
- add_define 'OS_UNIX'
27
- end
28
-
29
-
30
-
31
- case RUBY_PLATFORM
32
- when /mswin32/, /mingw32/, /bccwin32/
33
- check_heads(%w[windows.h winsock.h], true)
34
- check_libs(%w[kernel32 rpcrt4 gdi32], true)
35
-
36
- if GNU_CHAIN
37
- CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
38
- else
39
- $defs.push "-EHs"
40
- $defs.push "-GR"
41
- end
42
-
43
- when /solaris/
44
- check_libs(%w[nsl socket], true)
45
-
46
- add_define 'OS_SOLARIS8'
47
-
48
- # Patch by Tim Pease, fixes SUNWspro compile problems.
49
- if CONFIG['CC'] == 'cc'
50
- # SUN CHAIN
51
- $CFLAGS = CONFIG['CFLAGS'] = "-KPIC -G"
52
- CONFIG['CCDLFLAGS'] = "-KPIC"
53
- else
54
- # GNU CHAIN
55
- # on Unix we need a g++ link, not gcc.
56
- CONFIG['LDSHARED'] = "$(CXX) -shared"
57
- end
58
- when /openbsd/
59
- # OpenBSD branch contributed by Guillaume Sellier.
60
-
61
- # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
62
- CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
63
- when /darwin/
64
- # on Unix we need a g++ link, not gcc.
65
- # Ff line contributed by Daniel Harple.
66
- CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
67
-
68
- when /linux/
69
-
70
- # on Unix we need a g++ link, not gcc.
71
- CONFIG['LDSHARED'] = "$(CXX) -shared"
72
- else
73
- # on Unix we need a g++ link, not gcc.
74
- CONFIG['LDSHARED'] = "$(CXX) -shared"
75
- end
76
-
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
+
17
+ # Minor platform details between *nix and Windows:
18
+
19
+ if RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
20
+ GNU_CHAIN = $1 == 'mingw'
21
+ OS_WIN32 = true
22
+ add_define "OS_WIN32"
23
+ else
24
+ GNU_CHAIN = true
25
+ OS_UNIX = true
26
+ add_define 'OS_UNIX'
27
+ end
28
+
29
+ # Main platform invariances:
30
+
31
+ case RUBY_PLATFORM
32
+ when /mswin32/, /mingw32/, /bccwin32/
33
+ check_heads(%w[windows.h winsock.h], true)
34
+ check_libs(%w[kernel32 rpcrt4 gdi32], true)
35
+
36
+ if GNU_CHAIN
37
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
38
+ else
39
+ $defs.push "-EHs"
40
+ $defs.push "-GR"
41
+ end
42
+
43
+ when /solaris/
44
+ add_define 'OS_SOLARIS8'
45
+ check_libs(%w[nsl socket], true)
46
+
47
+ # Patch by Tim Pease, fixes SUNWspro compile problems.
48
+ if CONFIG['CC'] == 'cc'
49
+ # SUN CHAIN
50
+ $CFLAGS = CONFIG['CFLAGS'] = "-KPIC -G"
51
+ CONFIG['CCDLFLAGS'] = "-KPIC"
52
+ else
53
+ # GNU CHAIN
54
+ # on Unix we need a g++ link, not gcc.
55
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
56
+ end
57
+
58
+ when /openbsd/
59
+ # OpenBSD branch contributed by Guillaume Sellier.
60
+
61
+ # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
62
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++ -fPIC"
63
+ CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
64
+
65
+ when /darwin/
66
+ # on Unix we need a g++ link, not gcc.
67
+ # Ff line contributed by Daniel Harple.
68
+ CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
69
+
70
+ when /linux/
71
+ # on Unix we need a g++ link, not gcc.
72
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
73
+
74
+ when /aix/
75
+ # on Unix we need a g++ link, not gcc.
76
+ CONFIG['LDSHARED'] = "$(CXX) -shared -Wl,-G"
77
+
78
+ else
79
+ # on Unix we need a g++ link, not gcc.
80
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
81
+ end
82
+
77
83
  create_makefile "fastfilereaderext"
@@ -1,140 +1,151 @@
1
- /*****************************************************************************
2
-
3
- $Id$
4
-
5
- File: project.h
6
- Date: 06Apr06
7
-
8
- Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9
- Gmail: blackhedd
10
-
11
- This program is free software; you can redistribute it and/or modify
12
- it under the terms of either: 1) the GNU General Public License
13
- as published by the Free Software Foundation; either version 2 of the
14
- License, or (at your option) any later version; or 2) Ruby's License.
15
-
16
- See the file COPYING for complete licensing information.
17
-
18
- *****************************************************************************/
19
-
20
-
21
- #ifndef __Project__H_
22
- #define __Project__H_
23
-
24
-
25
- #ifdef OS_WIN32
26
- #pragma warning(disable:4786)
27
- #endif
28
-
29
- #include <iostream>
30
- #include <map>
31
- #include <set>
32
- #include <vector>
33
- #include <deque>
34
- #include <string>
35
- #include <sstream>
36
- #include <stdexcept>
37
-
38
-
39
- #ifdef OS_UNIX
40
- #include <signal.h>
41
- #include <netdb.h>
42
- #include <time.h>
43
- #include <sys/time.h>
44
- #include <sys/types.h>
45
- #include <sys/stat.h>
46
- #include <sys/socket.h>
47
- #include <sys/un.h>
48
- #include <sys/resource.h>
49
- #include <sys/wait.h>
50
- #include <assert.h>
51
- #include <unistd.h>
52
- #include <fcntl.h>
53
- #include <errno.h>
54
- #include <netinet/in.h>
55
- #include <netinet/tcp.h>
56
- #include <arpa/inet.h>
57
- #include <pwd.h>
58
- typedef int SOCKET;
59
- #define closesocket close
60
- #define INVALID_SOCKET -1
61
- #define SOCKET_ERROR -1
62
- #ifdef OS_SOLARIS8
63
- #include <strings.h>
64
- #include <sys/un.h>
65
- #ifndef AF_LOCAL
66
- #define AF_LOCAL AF_UNIX
67
- #endif
68
- // INADDR_NONE is undefined on Solaris < 8. Thanks to Brett Eisenberg and Tim Pease.
69
- #ifndef INADDR_NONE
70
- #define INADDR_NONE ((unsigned long)-1)
71
- #endif
72
- #endif
73
- #endif
74
-
75
-
76
- #ifdef OS_WIN32
77
- #define WIN32_LEAN_AND_MEAN
78
- #include <windows.h>
79
- #include <winsock2.h>
80
- #include <ws2tcpip.h>
81
- #include <rpc.h>
82
- #include <fcntl.h>
83
- #include <assert.h>
84
- typedef int socklen_t;
85
- typedef int pid_t;
86
- #endif
87
-
88
-
89
- using namespace std;
90
-
91
- #ifdef WITH_SSL
92
- #include <openssl/ssl.h>
93
- #include <openssl/err.h>
94
- #endif
95
-
96
- #ifdef HAVE_EPOLL
97
- #include <sys/epoll.h>
98
- #endif
99
-
100
- #ifdef HAVE_KQUEUE
101
- #include <sys/event.h>
102
- #include <sys/queue.h>
103
- #endif
104
-
105
- #ifdef HAVE_INOTIFY
106
- #include <sys/inotify.h>
107
- #endif
108
-
109
- #ifdef HAVE_OLD_INOTIFY
110
- #include <sys/syscall.h>
111
- #include <linux/inotify.h>
112
- static inline int inotify_init (void) { return syscall (__NR_inotify_init); }
113
- static inline int inotify_add_watch (int fd, const char *name, __u32 mask) { return syscall (__NR_inotify_add_watch, fd, name, mask); }
114
- static inline int inotify_rm_watch (int fd, __u32 wd) { return syscall (__NR_inotify_rm_watch, fd, wd); }
115
- #define HAVE_INOTIFY 1
116
- #endif
117
-
118
- #ifdef HAVE_INOTIFY
119
- #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
120
- #endif
121
-
122
- #ifdef HAVE_WRITEV
123
- #include <sys/uio.h>
124
- #endif
125
-
126
- #include "binder.h"
127
- #include "em.h"
128
- #include "epoll.h"
129
- #include "sigs.h"
130
- #include "ed.h"
131
- #include "files.h"
132
- #include "page.h"
133
- #include "ssl.h"
134
- #include "eventmachine.h"
135
- #include "eventmachine_cpp.h"
136
-
137
-
138
-
139
-
140
- #endif // __Project__H_
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: project.h
6
+ Date: 06Apr06
7
+
8
+ Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: blackhedd
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of either: 1) the GNU General Public License
13
+ as published by the Free Software Foundation; either version 2 of the
14
+ License, or (at your option) any later version; or 2) Ruby's License.
15
+
16
+ See the file COPYING for complete licensing information.
17
+
18
+ *****************************************************************************/
19
+
20
+
21
+ #ifndef __Project__H_
22
+ #define __Project__H_
23
+
24
+
25
+ #ifdef OS_WIN32
26
+ #pragma warning(disable:4786)
27
+ #endif
28
+
29
+ #include <iostream>
30
+ #include <map>
31
+ #include <set>
32
+ #include <vector>
33
+ #include <deque>
34
+ #include <string>
35
+ #include <sstream>
36
+ #include <stdexcept>
37
+
38
+
39
+ #ifdef OS_UNIX
40
+ #include <signal.h>
41
+ #include <netdb.h>
42
+ #include <time.h>
43
+ #include <sys/time.h>
44
+ #include <sys/types.h>
45
+ #include <sys/stat.h>
46
+ #include <sys/socket.h>
47
+ #include <sys/un.h>
48
+ #include <sys/resource.h>
49
+ #include <sys/wait.h>
50
+ #include <assert.h>
51
+ #include <unistd.h>
52
+ #include <fcntl.h>
53
+ #include <errno.h>
54
+ #include <netinet/in.h>
55
+ #include <netinet/tcp.h>
56
+ #include <arpa/inet.h>
57
+ #include <pwd.h>
58
+ typedef int SOCKET;
59
+ #define closesocket close
60
+ #define INVALID_SOCKET -1
61
+ #define SOCKET_ERROR -1
62
+ #ifdef OS_SOLARIS8
63
+ #include <strings.h>
64
+ #include <sys/un.h>
65
+ #ifndef AF_LOCAL
66
+ #define AF_LOCAL AF_UNIX
67
+ #endif
68
+ // INADDR_NONE is undefined on Solaris < 8. Thanks to Brett Eisenberg and Tim Pease.
69
+ #ifndef INADDR_NONE
70
+ #define INADDR_NONE ((unsigned long)-1)
71
+ #endif
72
+ #endif /* OS_SOLARIS8 */
73
+
74
+ #ifdef _AIX
75
+ #include <strings.h>
76
+ #ifndef AF_LOCAL
77
+ #define AF_LOCAL AF_UNIX
78
+ #endif
79
+ #endif /* _AIX */
80
+
81
+ #endif /* OS_UNIX */
82
+
83
+ #ifdef OS_WIN32
84
+ // 21Sep09: windows limits select() to 64 sockets by default, we increase it to 1024 here (before including winsock2.h)
85
+ #define FD_SETSIZE 1024
86
+
87
+ #define WIN32_LEAN_AND_MEAN
88
+ #include <windows.h>
89
+ #include <winsock2.h>
90
+ #include <ws2tcpip.h>
91
+ #include <rpc.h>
92
+ #include <fcntl.h>
93
+ #include <assert.h>
94
+
95
+ typedef int socklen_t;
96
+ typedef int pid_t;
97
+ #endif
98
+
99
+
100
+ using namespace std;
101
+
102
+ #ifdef WITH_SSL
103
+ #include <openssl/ssl.h>
104
+ #include <openssl/err.h>
105
+ #endif
106
+
107
+ #ifdef HAVE_EPOLL
108
+ #include <sys/epoll.h>
109
+ #endif
110
+
111
+ #ifdef HAVE_KQUEUE
112
+ #include <sys/event.h>
113
+ #include <sys/queue.h>
114
+ #endif
115
+
116
+ #ifdef HAVE_INOTIFY
117
+ #include <sys/inotify.h>
118
+ #endif
119
+
120
+ #ifdef HAVE_OLD_INOTIFY
121
+ #include <sys/syscall.h>
122
+ #include <linux/inotify.h>
123
+ static inline int inotify_init (void) { return syscall (__NR_inotify_init); }
124
+ static inline int inotify_add_watch (int fd, const char *name, __u32 mask) { return syscall (__NR_inotify_add_watch, fd, name, mask); }
125
+ static inline int inotify_rm_watch (int fd, __u32 wd) { return syscall (__NR_inotify_rm_watch, fd, wd); }
126
+ #define HAVE_INOTIFY 1
127
+ #endif
128
+
129
+ #ifdef HAVE_INOTIFY
130
+ #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
131
+ #endif
132
+
133
+ #ifdef HAVE_WRITEV
134
+ #include <sys/uio.h>
135
+ #endif
136
+
137
+ #include "binder.h"
138
+ #include "em.h"
139
+ #include "epoll.h"
140
+ #include "sigs.h"
141
+ #include "ed.h"
142
+ #include "files.h"
143
+ #include "page.h"
144
+ #include "ssl.h"
145
+ #include "eventmachine.h"
146
+ #include "eventmachine_cpp.h"
147
+
148
+
149
+
150
+
151
+ #endif // __Project__H_
@@ -32,8 +32,10 @@ Statics
32
32
  static VALUE EmModule;
33
33
  static VALUE EmConnection;
34
34
 
35
+ static VALUE EM_eConnectionError;
35
36
  static VALUE EM_eUnknownTimerFired;
36
37
  static VALUE EM_eConnectionNotBound;
38
+ static VALUE EM_eUnsupported;
37
39
 
38
40
  static VALUE Intern_at_signature;
39
41
  static VALUE Intern_at_timers;
@@ -53,10 +55,10 @@ static VALUE Intern_proxy_target_unbound;
53
55
  static VALUE rb_cProcStatus;
54
56
 
55
57
  struct em_event {
56
- const char *a1;
58
+ unsigned long a1;
57
59
  int a2;
58
60
  const char *a3;
59
- int a4;
61
+ unsigned long a4;
60
62
  };
61
63
 
62
64
  /****************
@@ -65,30 +67,30 @@ t_event_callback
65
67
 
66
68
  static void event_callback (struct em_event* e)
67
69
  {
68
- const char *a1 = e->a1;
70
+ const unsigned long a1 = e->a1;
69
71
  int a2 = e->a2;
70
72
  const char *a3 = e->a3;
71
- int a4 = e->a4;
73
+ const unsigned long a4 = e->a4;
72
74
 
73
75
  if (a2 == EM_CONNECTION_READ) {
74
76
  VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
75
- VALUE q = rb_hash_aref (t, rb_str_new2(a1));
77
+ VALUE q = rb_hash_aref (t, ULONG2NUM (a1));
76
78
  if (q == Qnil)
77
- rb_raise (EM_eConnectionNotBound, "received %d bytes of data for unknown signature: %s", a4, a1);
79
+ rb_raise (EM_eConnectionNotBound, "received %lu bytes of data for unknown signature: %lu", a4, a1);
78
80
  rb_funcall (q, Intern_receive_data, 1, rb_str_new (a3, a4));
79
81
  }
80
82
  else if (a2 == EM_CONNECTION_NOTIFY_READABLE) {
81
83
  VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
82
- VALUE q = rb_hash_aref (t, rb_str_new2(a1));
84
+ VALUE q = rb_hash_aref (t, ULONG2NUM (a1));
83
85
  if (q == Qnil)
84
- rb_raise (EM_eConnectionNotBound, "unknown connection: %s", a1);
86
+ rb_raise (EM_eConnectionNotBound, "unknown connection: %lu", a1);
85
87
  rb_funcall (q, Intern_notify_readable, 0);
86
88
  }
87
89
  else if (a2 == EM_CONNECTION_NOTIFY_WRITABLE) {
88
90
  VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
89
- VALUE q = rb_hash_aref (t, rb_str_new2(a1));
91
+ VALUE q = rb_hash_aref (t, ULONG2NUM (a1));
90
92
  if (q == Qnil)
91
- rb_raise (EM_eConnectionNotBound, "unknown connection: %s", a1);
93
+ rb_raise (EM_eConnectionNotBound, "unknown connection: %lu", a1);
92
94
  rb_funcall (q, Intern_notify_writable, 0);
93
95
  }
94
96
  else if (a2 == EM_LOOPBREAK_SIGNAL) {
@@ -96,9 +98,9 @@ static void event_callback (struct em_event* e)
96
98
  }
97
99
  else if (a2 == EM_TIMER_FIRED) {
98
100
  VALUE t = rb_ivar_get (EmModule, Intern_at_timers);
99
- VALUE q = rb_funcall (t, Intern_delete, 1, rb_str_new(a3, a4));
101
+ VALUE q = rb_funcall (t, Intern_delete, 1, ULONG2NUM (a4));
100
102
  if (q == Qnil) {
101
- rb_raise (EM_eUnknownTimerFired, "no such timer: %s", a1);
103
+ rb_raise (EM_eUnknownTimerFired, "no such timer: %lu", a4);
102
104
  } else if (q == Qfalse) {
103
105
  /* Timer Canceled */
104
106
  } else {
@@ -108,16 +110,16 @@ static void event_callback (struct em_event* e)
108
110
  #ifdef WITH_SSL
109
111
  else if (a2 == EM_SSL_HANDSHAKE_COMPLETED) {
110
112
  VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
111
- VALUE q = rb_hash_aref (t, rb_str_new2(a1));
113
+ VALUE q = rb_hash_aref (t, ULONG2NUM (a1));
112
114
  if (q == Qnil)
113
- rb_raise (EM_eConnectionNotBound, "unknown connection: %s", a1);
115
+ rb_raise (EM_eConnectionNotBound, "unknown connection: %lu", a1);
114
116
  rb_funcall (q, Intern_ssl_handshake_completed, 0);
115
117
  }
116
118
  else if (a2 == EM_SSL_VERIFY) {
117
119
  VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
118
- VALUE q = rb_hash_aref (t, rb_str_new2(a1));
120
+ VALUE q = rb_hash_aref (t, ULONG2NUM (a1));
119
121
  if (q == Qnil)
120
- rb_raise (EM_eConnectionNotBound, "unknown connection: %s", a1);
122
+ rb_raise (EM_eConnectionNotBound, "unknown connection: %lu", a1);
121
123
  VALUE r = rb_funcall (q, Intern_ssl_verify_peer, 1, rb_str_new(a3, a4));
122
124
  if (RTEST(r))
123
125
  evma_accept_ssl_peer (a1);
@@ -125,13 +127,13 @@ static void event_callback (struct em_event* e)
125
127
  #endif
126
128
  else if (a2 == EM_PROXY_TARGET_UNBOUND) {
127
129
  VALUE t = rb_ivar_get (EmModule, Intern_at_conns);
128
- VALUE q = rb_hash_aref (t, rb_str_new2(a1));
130
+ VALUE q = rb_hash_aref (t, ULONG2NUM (a1));
129
131
  if (q == Qnil)
130
- rb_raise (EM_eConnectionNotBound, "unknown connection: %s", a1);
132
+ rb_raise (EM_eConnectionNotBound, "unknown connection: %lu", a1);
131
133
  rb_funcall (q, Intern_proxy_target_unbound, 0);
132
134
  }
133
135
  else
134
- rb_funcall (EmModule, Intern_event_callback, 3, rb_str_new2(a1), (a2 << 1) | 1, rb_str_new(a3,a4));
136
+ rb_funcall (EmModule, Intern_event_callback, 3, ULONG2NUM(a1), INT2FIX(a2), a3 ? rb_str_new(a3,a4) : ULONG2NUM(a4));
135
137
  }
136
138
 
137
139
  /*******************
@@ -148,7 +150,7 @@ static void event_error_handler(VALUE unused, VALUE err)
148
150
  event_callback_wrapper
149
151
  **********************/
150
152
 
151
- static void event_callback_wrapper (const char *a1, int a2, const char *a3, int a4)
153
+ static void event_callback_wrapper (const unsigned long a1, int a2, const char *a3, const unsigned long a4)
152
154
  {
153
155
  struct em_event e;
154
156
  e.a1 = a1;
@@ -191,10 +193,10 @@ t_add_oneshot_timer
191
193
 
192
194
  static VALUE t_add_oneshot_timer (VALUE self, VALUE interval)
193
195
  {
194
- const char *f = evma_install_oneshot_timer (FIX2INT (interval));
195
- if (!f || !*f)
196
- rb_raise (rb_eRuntimeError, "no timer");
197
- return rb_str_new2 (f);
196
+ const unsigned long f = evma_install_oneshot_timer (FIX2INT (interval));
197
+ if (!f)
198
+ rb_raise (rb_eRuntimeError, "ran out of timers; use #set_max_timers to increase limit");
199
+ return ULONG2NUM (f);
198
200
  }
199
201
 
200
202
 
@@ -204,10 +206,10 @@ t_start_server
204
206
 
205
207
  static VALUE t_start_server (VALUE self, VALUE server, VALUE port)
206
208
  {
207
- const char *f = evma_create_tcp_server (StringValuePtr(server), FIX2INT(port));
208
- if (!f || !*f)
209
+ const unsigned long f = evma_create_tcp_server (StringValuePtr(server), FIX2INT(port));
210
+ if (!f)
209
211
  rb_raise (rb_eRuntimeError, "no acceptor");
210
- return rb_str_new2 (f);
212
+ return ULONG2NUM (f);
211
213
  }
212
214
 
213
215
  /*************
@@ -216,7 +218,7 @@ t_stop_server
216
218
 
217
219
  static VALUE t_stop_server (VALUE self, VALUE signature)
218
220
  {
219
- evma_stop_tcp_server (StringValuePtr (signature));
221
+ evma_stop_tcp_server (NUM2ULONG (signature));
220
222
  return Qnil;
221
223
  }
222
224
 
@@ -227,10 +229,10 @@ t_start_unix_server
227
229
 
228
230
  static VALUE t_start_unix_server (VALUE self, VALUE filename)
229
231
  {
230
- const char *f = evma_create_unix_domain_server (StringValuePtr(filename));
231
- if (!f || !*f)
232
+ const unsigned long f = evma_create_unix_domain_server (StringValuePtr(filename));
233
+ if (!f)
232
234
  rb_raise (rb_eRuntimeError, "no unix-domain acceptor");
233
- return rb_str_new2 (f);
235
+ return ULONG2NUM (f);
234
236
  }
235
237
 
236
238
 
@@ -241,7 +243,7 @@ t_send_data
241
243
 
242
244
  static VALUE t_send_data (VALUE self, VALUE signature, VALUE data, VALUE data_length)
243
245
  {
244
- int b = evma_send_data_to_connection (StringValuePtr (signature), StringValuePtr (data), FIX2INT (data_length));
246
+ int b = evma_send_data_to_connection (NUM2ULONG (signature), StringValuePtr (data), FIX2INT (data_length));
245
247
  return INT2NUM (b);
246
248
  }
247
249
 
@@ -252,7 +254,7 @@ t_start_tls
252
254
 
253
255
  static VALUE t_start_tls (VALUE self, VALUE signature)
254
256
  {
255
- evma_start_tls (StringValuePtr (signature));
257
+ evma_start_tls (NUM2ULONG (signature));
256
258
  return Qnil;
257
259
  }
258
260
 
@@ -267,7 +269,7 @@ static VALUE t_set_tls_parms (VALUE self, VALUE signature, VALUE privkeyfile, VA
267
269
  * It's expected that the parameter list will grow as we add more supported features.
268
270
  * ALL of these parameters are optional, and can be specified as empty or NULL strings.
269
271
  */
270
- evma_set_tls_parms (StringValuePtr (signature), StringValuePtr (privkeyfile), StringValuePtr (certchainfile), (verify_peer == Qtrue ? 1 : 0));
272
+ evma_set_tls_parms (NUM2ULONG (signature), StringValuePtr (privkeyfile), StringValuePtr (certchainfile), (verify_peer == Qtrue ? 1 : 0));
271
273
  return Qnil;
272
274
  }
273
275
 
@@ -284,7 +286,7 @@ static VALUE t_get_peer_cert (VALUE self, VALUE signature)
284
286
  BUF_MEM *buf;
285
287
  BIO *out;
286
288
 
287
- cert = evma_get_peer_cert (StringValuePtr (signature));
289
+ cert = evma_get_peer_cert (NUM2ULONG (signature));
288
290
 
289
291
  if (cert != NULL) {
290
292
  out = BIO_new(BIO_s_mem());
@@ -306,7 +308,7 @@ t_get_peername
306
308
  static VALUE t_get_peername (VALUE self, VALUE signature)
307
309
  {
308
310
  struct sockaddr s;
309
- if (evma_get_peername (StringValuePtr (signature), &s)) {
311
+ if (evma_get_peername (NUM2ULONG (signature), &s)) {
310
312
  return rb_str_new ((const char*)&s, sizeof(s));
311
313
  }
312
314
 
@@ -320,7 +322,7 @@ t_get_sockname
320
322
  static VALUE t_get_sockname (VALUE self, VALUE signature)
321
323
  {
322
324
  struct sockaddr s;
323
- if (evma_get_sockname (StringValuePtr (signature), &s)) {
325
+ if (evma_get_sockname (NUM2ULONG (signature), &s)) {
324
326
  return rb_str_new ((const char*)&s, sizeof(s));
325
327
  }
326
328
 
@@ -334,7 +336,7 @@ t_get_subprocess_pid
334
336
  static VALUE t_get_subprocess_pid (VALUE self, VALUE signature)
335
337
  {
336
338
  pid_t pid;
337
- if (evma_get_subprocess_pid (StringValuePtr (signature), &pid)) {
339
+ if (evma_get_subprocess_pid (NUM2ULONG (signature), &pid)) {
338
340
  return INT2NUM (pid);
339
341
  }
340
342
 
@@ -352,8 +354,8 @@ static VALUE t_get_subprocess_status (VALUE self, VALUE signature)
352
354
  int status;
353
355
  pid_t pid;
354
356
 
355
- if (evma_get_subprocess_status (StringValuePtr (signature), &status)) {
356
- if (evma_get_subprocess_pid (StringValuePtr (signature), &pid)) {
357
+ if (evma_get_subprocess_status (NUM2ULONG (signature), &status)) {
358
+ if (evma_get_subprocess_pid (NUM2ULONG (signature), &pid)) {
357
359
  proc_status = rb_obj_alloc(rb_cProcStatus);
358
360
  rb_iv_set(proc_status, "status", INT2FIX(status));
359
361
  rb_iv_set(proc_status, "pid", INT2FIX(pid));
@@ -378,7 +380,7 @@ t_get_comm_inactivity_timeout
378
380
 
379
381
  static VALUE t_get_comm_inactivity_timeout (VALUE self, VALUE signature)
380
382
  {
381
- return rb_float_new(evma_get_comm_inactivity_timeout(StringValuePtr(signature)));
383
+ return rb_float_new(evma_get_comm_inactivity_timeout(NUM2ULONG (signature)));
382
384
  }
383
385
 
384
386
  /*****************************
@@ -388,11 +390,31 @@ t_set_comm_inactivity_timeout
388
390
  static VALUE t_set_comm_inactivity_timeout (VALUE self, VALUE signature, VALUE timeout)
389
391
  {
390
392
  float ti = RFLOAT_VALUE(timeout);
391
- if (evma_set_comm_inactivity_timeout (StringValuePtr (signature), ti));
393
+ if (evma_set_comm_inactivity_timeout (NUM2ULONG (signature), ti));
392
394
  return Qtrue;
393
395
  return Qfalse;
394
396
  }
395
397
 
398
+ /*****************************
399
+ t_get_pending_connect_timeout
400
+ *****************************/
401
+
402
+ static VALUE t_get_pending_connect_timeout (VALUE self, VALUE signature)
403
+ {
404
+ return rb_float_new(evma_get_pending_connect_timeout(NUM2ULONG (signature)));
405
+ }
406
+
407
+ /*****************************
408
+ t_set_pending_connect_timeout
409
+ *****************************/
410
+
411
+ static VALUE t_set_pending_connect_timeout (VALUE self, VALUE signature, VALUE timeout)
412
+ {
413
+ float ti = RFLOAT_VALUE(timeout);
414
+ if (evma_set_pending_connect_timeout (NUM2ULONG (signature), ti));
415
+ return Qtrue;
416
+ return Qfalse;
417
+ }
396
418
 
397
419
  /***************
398
420
  t_send_datagram
@@ -400,7 +422,7 @@ t_send_datagram
400
422
 
401
423
  static VALUE t_send_datagram (VALUE self, VALUE signature, VALUE data, VALUE data_length, VALUE address, VALUE port)
402
424
  {
403
- int b = evma_send_datagram (StringValuePtr (signature), StringValuePtr (data), FIX2INT (data_length), StringValuePtr(address), FIX2INT(port));
425
+ int b = evma_send_datagram (NUM2ULONG (signature), StringValuePtr (data), FIX2INT (data_length), StringValuePtr(address), FIX2INT(port));
404
426
  return INT2NUM (b);
405
427
  }
406
428
 
@@ -411,7 +433,7 @@ t_close_connection
411
433
 
412
434
  static VALUE t_close_connection (VALUE self, VALUE signature, VALUE after_writing)
413
435
  {
414
- evma_close_connection (StringValuePtr (signature), ((after_writing == Qtrue) ? 1 : 0));
436
+ evma_close_connection (NUM2ULONG (signature), ((after_writing == Qtrue) ? 1 : 0));
415
437
  return Qnil;
416
438
  }
417
439
 
@@ -421,7 +443,7 @@ t_report_connection_error_status
421
443
 
422
444
  static VALUE t_report_connection_error_status (VALUE self, VALUE signature)
423
445
  {
424
- int b = evma_report_connection_error_status (StringValuePtr (signature));
446
+ int b = evma_report_connection_error_status (NUM2ULONG (signature));
425
447
  return INT2NUM (b);
426
448
  }
427
449
 
@@ -437,10 +459,14 @@ static VALUE t_connect_server (VALUE self, VALUE server, VALUE port)
437
459
  // Specifically, if the value of port comes in as a string rather than an integer,
438
460
  // NUM2INT will throw a type error, but FIX2INT will generate garbage.
439
461
 
440
- const char *f = evma_connect_to_server (NULL, 0, StringValuePtr(server), NUM2INT(port));
441
- if (!f || !*f)
442
- rb_raise (rb_eRuntimeError, "no connection");
443
- return rb_str_new2 (f);
462
+ try {
463
+ const unsigned long f = evma_connect_to_server (NULL, 0, StringValuePtr(server), NUM2INT(port));
464
+ if (!f)
465
+ rb_raise (EM_eConnectionError, "no connection");
466
+ return ULONG2NUM (f);
467
+ } catch (std::runtime_error e) {
468
+ rb_raise (EM_eConnectionError, e.what());
469
+ }
444
470
  }
445
471
 
446
472
  /*********************
@@ -453,15 +479,14 @@ static VALUE t_bind_connect_server (VALUE self, VALUE bind_addr, VALUE bind_port
453
479
  // Specifically, if the value of port comes in as a string rather than an integer,
454
480
  // NUM2INT will throw a type error, but FIX2INT will generate garbage.
455
481
 
456
- const char *f;
457
482
  try {
458
- f = evma_connect_to_server (StringValuePtr(bind_addr), NUM2INT(bind_port), StringValuePtr(server), NUM2INT(port));
459
- if (!f || !*f)
460
- rb_raise (rb_eRuntimeError, "no connection");
483
+ const unsigned long f = evma_connect_to_server (StringValuePtr(bind_addr), NUM2INT(bind_port), StringValuePtr(server), NUM2INT(port));
484
+ if (!f)
485
+ rb_raise (EM_eConnectionError, "no connection");
486
+ return ULONG2NUM (f);
461
487
  } catch (std::runtime_error e) {
462
- rb_sys_fail(e.what());
488
+ rb_raise (EM_eConnectionError, e.what());
463
489
  }
464
- return rb_str_new2 (f);
465
490
  }
466
491
 
467
492
  /*********************
@@ -470,31 +495,113 @@ t_connect_unix_server
470
495
 
471
496
  static VALUE t_connect_unix_server (VALUE self, VALUE serversocket)
472
497
  {
473
- const char *f = evma_connect_to_unix_server (StringValuePtr(serversocket));
474
- if (!f || !*f)
498
+ const unsigned long f = evma_connect_to_unix_server (StringValuePtr(serversocket));
499
+ if (!f)
475
500
  rb_raise (rb_eRuntimeError, "no connection");
476
- return rb_str_new2 (f);
501
+ return ULONG2NUM (f);
477
502
  }
478
503
 
479
504
  /***********
480
505
  t_attach_fd
481
506
  ***********/
482
507
 
483
- static VALUE t_attach_fd (VALUE self, VALUE file_descriptor, VALUE read_mode, VALUE write_mode)
508
+ static VALUE t_attach_fd (VALUE self, VALUE file_descriptor, VALUE watch_mode)
484
509
  {
485
- const char *f = evma_attach_fd (NUM2INT(file_descriptor), (read_mode == Qtrue) ? 1 : 0, (write_mode == Qtrue) ? 1 : 0);
486
- if (!f || !*f)
510
+ const unsigned long f = evma_attach_fd (NUM2INT(file_descriptor), watch_mode == Qtrue);
511
+ if (!f)
487
512
  rb_raise (rb_eRuntimeError, "no connection");
488
- return rb_str_new2 (f);
513
+ return ULONG2NUM (f);
489
514
  }
490
515
 
491
516
  /***********
492
517
  t_detach_fd
493
518
  ***********/
494
519
 
495
- static VALUE t_detach_fd (VALUE self, VALUE signature)
520
+ static VALUE t_detach_fd (VALUE self, VALUE signature)
521
+ {
522
+ return INT2NUM(evma_detach_fd (NUM2ULONG (signature)));
523
+ }
524
+
525
+ /**************
526
+ t_get_sock_opt
527
+ **************/
528
+
529
+ static VALUE t_get_sock_opt (VALUE self, VALUE signature, VALUE lev, VALUE optname)
530
+ {
531
+ int fd = evma_get_file_descriptor (NUM2ULONG (signature));
532
+ int level = NUM2INT(lev), option = NUM2INT(optname);
533
+ socklen_t len = 128;
534
+ char buf[128];
535
+
536
+ if (getsockopt(fd, level, option, buf, &len) < 0)
537
+ rb_sys_fail("getsockopt");
538
+
539
+ return rb_str_new(buf, len);
540
+ }
541
+
542
+ /********************
543
+ t_is_notify_readable
544
+ ********************/
545
+
546
+ static VALUE t_is_notify_readable (VALUE self, VALUE signature)
547
+ {
548
+ return evma_is_notify_readable(NUM2ULONG (signature)) ? Qtrue : Qfalse;
549
+ }
550
+
551
+ /*********************
552
+ t_set_notify_readable
553
+ *********************/
554
+
555
+ static VALUE t_set_notify_readable (VALUE self, VALUE signature, VALUE mode)
496
556
  {
497
- return INT2NUM(evma_detach_fd (StringValuePtr(signature)));
557
+ evma_set_notify_readable(NUM2ULONG (signature), mode == Qtrue);
558
+ return Qnil;
559
+ }
560
+
561
+ /********************
562
+ t_is_notify_readable
563
+ ********************/
564
+
565
+ static VALUE t_is_notify_writable (VALUE self, VALUE signature)
566
+ {
567
+ return evma_is_notify_writable(NUM2ULONG (signature)) ? Qtrue : Qfalse;
568
+ }
569
+
570
+ /*********************
571
+ t_set_notify_writable
572
+ *********************/
573
+
574
+ static VALUE t_set_notify_writable (VALUE self, VALUE signature, VALUE mode)
575
+ {
576
+ evma_set_notify_writable(NUM2ULONG (signature), mode == Qtrue);
577
+ return Qnil;
578
+ }
579
+
580
+ /*******
581
+ t_pause
582
+ *******/
583
+
584
+ static VALUE t_pause (VALUE self, VALUE signature)
585
+ {
586
+ return evma_pause(NUM2ULONG (signature)) ? Qtrue : Qfalse;
587
+ }
588
+
589
+ /********
590
+ t_resume
591
+ ********/
592
+
593
+ static VALUE t_resume (VALUE self, VALUE signature)
594
+ {
595
+ return evma_resume(NUM2ULONG (signature)) ? Qtrue : Qfalse;
596
+ }
597
+
598
+ /**********
599
+ t_paused_p
600
+ **********/
601
+
602
+ static VALUE t_paused_p (VALUE self, VALUE signature)
603
+ {
604
+ return evma_is_paused(NUM2ULONG (signature)) ? Qtrue : Qfalse;
498
605
  }
499
606
 
500
607
  /*****************
@@ -503,10 +610,10 @@ t_open_udp_socket
503
610
 
504
611
  static VALUE t_open_udp_socket (VALUE self, VALUE server, VALUE port)
505
612
  {
506
- const char *f = evma_open_datagram_socket (StringValuePtr(server), FIX2INT(port));
507
- if (!f || !*f)
613
+ const unsigned long f = evma_open_datagram_socket (StringValuePtr(server), FIX2INT(port));
614
+ if (!f)
508
615
  rb_raise (rb_eRuntimeError, "no datagram socket");
509
- return rb_str_new2 (f);
616
+ return ULONG2NUM (f);
510
617
  }
511
618
 
512
619
 
@@ -600,10 +707,10 @@ t__write_file
600
707
 
601
708
  static VALUE t__write_file (VALUE self, VALUE filename)
602
709
  {
603
- const char *f = evma__write_file (StringValuePtr (filename));
604
- if (!f || !*f)
710
+ const unsigned long f = evma__write_file (StringValuePtr (filename));
711
+ if (!f)
605
712
  rb_raise (rb_eRuntimeError, "file not opened");
606
- return rb_str_new2 (f);
713
+ return ULONG2NUM (f);
607
714
  }
608
715
 
609
716
  /**************
@@ -628,15 +735,15 @@ static VALUE t_invoke_popen (VALUE self, VALUE cmd)
628
735
  }
629
736
  strings[len] = NULL;
630
737
 
631
- const char *f = evma_popen (strings);
632
- if (!f || !*f) {
738
+ const unsigned long f = evma_popen (strings);
739
+ if (!f) {
633
740
  char *err = strerror (errno);
634
741
  char buf[100];
635
742
  memset (buf, 0, sizeof(buf));
636
743
  snprintf (buf, sizeof(buf)-1, "no popen: %s", (err?err:"???"));
637
- rb_raise (rb_eRuntimeError, buf);
744
+ rb_raise (rb_eRuntimeError, "%s", buf);
638
745
  }
639
- return rb_str_new2 (f);
746
+ return ULONG2NUM (f);
640
747
  }
641
748
 
642
749
 
@@ -646,10 +753,10 @@ t_read_keyboard
646
753
 
647
754
  static VALUE t_read_keyboard (VALUE self)
648
755
  {
649
- const char *f = evma_open_keyboard();
650
- if (!f || !*f)
756
+ const unsigned long f = evma_open_keyboard();
757
+ if (!f)
651
758
  rb_raise (rb_eRuntimeError, "no keyboard reader");
652
- return rb_str_new2 (f);
759
+ return ULONG2NUM (f);
653
760
  }
654
761
 
655
762
 
@@ -660,7 +767,7 @@ t_watch_filename
660
767
  static VALUE t_watch_filename (VALUE self, VALUE fname)
661
768
  {
662
769
  try {
663
- return rb_str_new2(evma_watch_filename(StringValuePtr(fname)));
770
+ return ULONG2NUM(evma_watch_filename(StringValuePtr(fname)));
664
771
  } catch (std::runtime_error e) {
665
772
  rb_sys_fail(e.what());
666
773
  }
@@ -673,7 +780,7 @@ t_unwatch_filename
673
780
 
674
781
  static VALUE t_unwatch_filename (VALUE self, VALUE sig)
675
782
  {
676
- evma_unwatch_filename(StringValuePtr(sig));
783
+ evma_unwatch_filename(NUM2ULONG (sig));
677
784
  return Qnil;
678
785
  }
679
786
 
@@ -685,7 +792,7 @@ t_watch_pid
685
792
  static VALUE t_watch_pid (VALUE self, VALUE pid)
686
793
  {
687
794
  try {
688
- return rb_str_new2(evma_watch_pid(NUM2INT(pid)));
795
+ return ULONG2NUM(evma_watch_pid(NUM2INT(pid)));
689
796
  } catch (std::runtime_error e) {
690
797
  rb_sys_fail(e.what());
691
798
  }
@@ -698,7 +805,7 @@ t_unwatch_pid
698
805
 
699
806
  static VALUE t_unwatch_pid (VALUE self, VALUE sig)
700
807
  {
701
- evma_unwatch_pid(StringValuePtr(sig));
808
+ evma_unwatch_pid(NUM2ULONG (sig));
702
809
  return Qnil;
703
810
  }
704
811
 
@@ -722,9 +829,6 @@ t__epoll
722
829
 
723
830
  static VALUE t__epoll (VALUE self)
724
831
  {
725
- if (t__epoll_p(self) == Qfalse)
726
- return Qfalse;
727
-
728
832
  evma_set_epoll (1);
729
833
  return Qtrue;
730
834
  }
@@ -736,7 +840,7 @@ t__epoll_set
736
840
  static VALUE t__epoll_set (VALUE self, VALUE val)
737
841
  {
738
842
  if (t__epoll_p(self) == Qfalse)
739
- return Qfalse;
843
+ rb_raise (EM_eUnsupported, "epoll is not supported on this platform");
740
844
 
741
845
  evma_set_epoll (val == Qtrue ? 1 : 0);
742
846
  return val;
@@ -762,9 +866,6 @@ t__kqueue
762
866
 
763
867
  static VALUE t__kqueue (VALUE self)
764
868
  {
765
- if (t__kqueue_p(self) == Qfalse)
766
- return Qfalse;
767
-
768
869
  evma_set_kqueue (1);
769
870
  return Qtrue;
770
871
  }
@@ -776,7 +877,7 @@ t__kqueue_set
776
877
  static VALUE t__kqueue_set (VALUE self, VALUE val)
777
878
  {
778
879
  if (t__kqueue_p(self) == Qfalse)
779
- return Qfalse;
880
+ rb_raise (EM_eUnsupported, "kqueue is not supported on this platform");
780
881
 
781
882
  evma_set_kqueue (val == Qtrue ? 1 : 0);
782
883
  return val;
@@ -812,7 +913,7 @@ static VALUE t_send_file_data (VALUE self, VALUE signature, VALUE filename)
812
913
  * do this. For one thing it's ugly. For another, we can't be sure zero is never a real errno.
813
914
  */
814
915
 
815
- int b = evma_send_file_data_to_connection (StringValuePtr(signature), StringValuePtr(filename));
916
+ int b = evma_send_file_data_to_connection (NUM2ULONG (signature), StringValuePtr(filename));
816
917
  if (b == -1)
817
918
  rb_raise(rb_eRuntimeError, "File too large. send_file_data() supports files under 32k.");
818
919
  if (b > 0) {
@@ -821,7 +922,7 @@ static VALUE t_send_file_data (VALUE self, VALUE signature, VALUE filename)
821
922
  memset (buf, 0, sizeof(buf));
822
923
  snprintf (buf, sizeof(buf)-1, ": %s %s", StringValuePtr(filename),(err?err:"???"));
823
924
 
824
- rb_raise (rb_eIOError, buf);
925
+ rb_raise (rb_eIOError, "%s", buf);
825
926
  }
826
927
 
827
928
  return INT2NUM (0);
@@ -845,7 +946,7 @@ conn_get_outbound_data_size
845
946
  static VALUE conn_get_outbound_data_size (VALUE self)
846
947
  {
847
948
  VALUE sig = rb_ivar_get (self, Intern_at_signature);
848
- return INT2NUM (evma_get_outbound_data_size (StringValuePtr(sig)));
949
+ return INT2NUM (evma_get_outbound_data_size (NUM2ULONG (sig)));
849
950
  }
850
951
 
851
952
 
@@ -866,12 +967,17 @@ t_get_loop_time
866
967
 
867
968
  static VALUE t_get_loop_time (VALUE self)
868
969
  {
869
- VALUE cTime = rb_path2class("Time");
970
+ #ifndef HAVE_RB_TIME_NEW
971
+ static VALUE cTime = rb_path2class("Time");
972
+ static ID at = rb_intern("at");
973
+ #endif
974
+
870
975
  if (gCurrentLoopTime != 0) {
871
- return rb_funcall(cTime,
872
- rb_intern("at"),
873
- 1,
874
- INT2NUM(gCurrentLoopTime));
976
+ #ifndef HAVE_RB_TIME_NEW
977
+ return rb_funcall(cTime, at, 2, INT2NUM(gCurrentLoopTime / 1000000), INT2NUM(gCurrentLoopTime % 1000000));
978
+ #else
979
+ return rb_time_new(gCurrentLoopTime / 1000000, gCurrentLoopTime % 1000000);
980
+ #endif
875
981
  }
876
982
  return Qnil;
877
983
  }
@@ -881,9 +987,9 @@ static VALUE t_get_loop_time (VALUE self)
881
987
  t_start_proxy
882
988
  **************/
883
989
 
884
- static VALUE t_start_proxy (VALUE self, VALUE from, VALUE to)
990
+ static VALUE t_start_proxy (VALUE self, VALUE from, VALUE to, VALUE bufsize)
885
991
  {
886
- evma_start_proxy(StringValuePtr(from), StringValuePtr(to));
992
+ evma_start_proxy(NUM2ULONG (from), NUM2ULONG (to), NUM2ULONG(bufsize));
887
993
  return Qnil;
888
994
  }
889
995
 
@@ -894,7 +1000,7 @@ t_stop_proxy
894
1000
 
895
1001
  static VALUE t_stop_proxy (VALUE self, VALUE from)
896
1002
  {
897
- evma_stop_proxy(StringValuePtr(from));
1003
+ evma_stop_proxy(NUM2ULONG (from));
898
1004
  return Qnil;
899
1005
  }
900
1006
 
@@ -955,9 +1061,11 @@ extern "C" void Init_rubyeventmachine()
955
1061
  EmModule = rb_define_module ("EventMachine");
956
1062
  EmConnection = rb_define_class_under (EmModule, "Connection", rb_cObject);
957
1063
 
958
- rb_define_class_under (EmModule, "NoHandlerForAcceptedConnection", rb_eException);
1064
+ rb_define_class_under (EmModule, "NoHandlerForAcceptedConnection", rb_eRuntimeError);
1065
+ EM_eConnectionError = rb_define_class_under (EmModule, "ConnectionError", rb_eRuntimeError);
959
1066
  EM_eConnectionNotBound = rb_define_class_under (EmModule, "ConnectionNotBound", rb_eRuntimeError);
960
1067
  EM_eUnknownTimerFired = rb_define_class_under (EmModule, "UnknownTimerFired", rb_eRuntimeError);
1068
+ EM_eUnsupported = rb_define_class_under (EmModule, "Unsupported", rb_eRuntimeError);
961
1069
 
962
1070
  rb_define_module_function (EmModule, "initialize_event_machine", (VALUE(*)(...))t_initialize_event_machine, 0);
963
1071
  rb_define_module_function (EmModule, "run_machine", (VALUE(*)(...))t_run_machine_without_threads, 0);
@@ -977,10 +1085,19 @@ extern "C" void Init_rubyeventmachine()
977
1085
  rb_define_module_function (EmModule, "bind_connect_server", (VALUE(*)(...))t_bind_connect_server, 4);
978
1086
  rb_define_module_function (EmModule, "connect_unix_server", (VALUE(*)(...))t_connect_unix_server, 1);
979
1087
 
980
- rb_define_module_function (EmModule, "attach_fd", (VALUE (*)(...))t_attach_fd, 3);
1088
+ rb_define_module_function (EmModule, "attach_fd", (VALUE (*)(...))t_attach_fd, 2);
981
1089
  rb_define_module_function (EmModule, "detach_fd", (VALUE (*)(...))t_detach_fd, 1);
1090
+ rb_define_module_function (EmModule, "get_sock_opt", (VALUE (*)(...))t_get_sock_opt, 3);
1091
+ rb_define_module_function (EmModule, "set_notify_readable", (VALUE (*)(...))t_set_notify_readable, 2);
1092
+ rb_define_module_function (EmModule, "set_notify_writable", (VALUE (*)(...))t_set_notify_writable, 2);
1093
+ rb_define_module_function (EmModule, "is_notify_readable", (VALUE (*)(...))t_is_notify_readable, 1);
1094
+ rb_define_module_function (EmModule, "is_notify_writable", (VALUE (*)(...))t_is_notify_writable, 1);
1095
+
1096
+ rb_define_module_function (EmModule, "pause_connection", (VALUE (*)(...))t_pause, 1);
1097
+ rb_define_module_function (EmModule, "resume_connection", (VALUE (*)(...))t_resume, 1);
1098
+ rb_define_module_function (EmModule, "connection_paused?", (VALUE (*)(...))t_paused_p, 1);
982
1099
 
983
- rb_define_module_function (EmModule, "start_proxy", (VALUE (*)(...))t_start_proxy, 2);
1100
+ rb_define_module_function (EmModule, "start_proxy", (VALUE (*)(...))t_start_proxy, 3);
984
1101
  rb_define_module_function (EmModule, "stop_proxy", (VALUE (*)(...))t_stop_proxy, 1);
985
1102
 
986
1103
  rb_define_module_function (EmModule, "watch_filename", (VALUE (*)(...))t_watch_filename, 1);
@@ -1015,6 +1132,8 @@ extern "C" void Init_rubyeventmachine()
1015
1132
  rb_define_module_function (EmModule, "get_subprocess_status", (VALUE(*)(...))t_get_subprocess_status, 1);
1016
1133
  rb_define_module_function (EmModule, "get_comm_inactivity_timeout", (VALUE(*)(...))t_get_comm_inactivity_timeout, 1);
1017
1134
  rb_define_module_function (EmModule, "set_comm_inactivity_timeout", (VALUE(*)(...))t_set_comm_inactivity_timeout, 2);
1135
+ rb_define_module_function (EmModule, "get_pending_connect_timeout", (VALUE(*)(...))t_get_pending_connect_timeout, 1);
1136
+ rb_define_module_function (EmModule, "set_pending_connect_timeout", (VALUE(*)(...))t_set_pending_connect_timeout, 2);
1018
1137
  rb_define_module_function (EmModule, "set_rlimit_nofile", (VALUE(*)(...))t_set_rlimit_nofile, 1);
1019
1138
  rb_define_module_function (EmModule, "get_connection_count", (VALUE(*)(...))t_get_connection_count, 0);
1020
1139