eventmachine 0.12.0-i386-mswin32
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.
- data/COPYING +60 -0
- data/DEFERRABLES +138 -0
- data/EPOLL +141 -0
- data/GNU +281 -0
- data/KEYBOARD +38 -0
- data/LEGAL +25 -0
- data/LIGHTWEIGHT_CONCURRENCY +72 -0
- data/PURE_RUBY +77 -0
- data/README +74 -0
- data/RELEASE_NOTES +96 -0
- data/SMTP +9 -0
- data/SPAWNED_PROCESSES +93 -0
- data/TODO +10 -0
- data/ext/Makefile +180 -0
- data/ext/binder.cpp +126 -0
- data/ext/binder.h +48 -0
- data/ext/cmain.cpp +527 -0
- data/ext/cplusplus.cpp +172 -0
- data/ext/ed.cpp +1442 -0
- data/ext/ed.h +351 -0
- data/ext/em.cpp +1781 -0
- data/ext/em.h +167 -0
- data/ext/emwin.cpp +300 -0
- data/ext/emwin.h +94 -0
- data/ext/epoll.cpp +26 -0
- data/ext/epoll.h +25 -0
- data/ext/eventmachine.h +83 -0
- data/ext/eventmachine_cpp.h +94 -0
- data/ext/extconf.rb +203 -0
- data/ext/files.cpp +94 -0
- data/ext/files.h +65 -0
- data/ext/kb.cpp +368 -0
- data/ext/mkmf.log +129 -0
- data/ext/page.cpp +107 -0
- data/ext/page.h +51 -0
- data/ext/pipe.cpp +327 -0
- data/ext/project.h +119 -0
- data/ext/rubyeventmachine-i386-mswin32.def +2 -0
- data/ext/rubyeventmachine-i386-mswin32.exp +0 -0
- data/ext/rubyeventmachine-i386-mswin32.lib +0 -0
- data/ext/rubyeventmachine-i386-mswin32.pdb +0 -0
- data/ext/rubyeventmachine.so +0 -0
- data/ext/rubymain.cpp +630 -0
- data/ext/sigs.cpp +89 -0
- data/ext/sigs.h +32 -0
- data/ext/ssl.cpp +408 -0
- data/ext/ssl.h +86 -0
- data/ext/vc60.pdb +0 -0
- data/lib/em/deferrable.rb +208 -0
- data/lib/em/eventable.rb +39 -0
- data/lib/em/future.rb +62 -0
- data/lib/em/messages.rb +66 -0
- data/lib/em/processes.rb +68 -0
- data/lib/em/spawnable.rb +88 -0
- data/lib/em/streamer.rb +112 -0
- data/lib/eventmachine.rb +1621 -0
- data/lib/eventmachine_version.rb +31 -0
- data/lib/evma.rb +32 -0
- data/lib/evma/callback.rb +32 -0
- data/lib/evma/container.rb +75 -0
- data/lib/evma/factory.rb +77 -0
- data/lib/evma/protocol.rb +87 -0
- data/lib/evma/reactor.rb +48 -0
- data/lib/jeventmachine.rb +106 -0
- data/lib/pr_eventmachine.rb +1011 -0
- data/lib/protocols/buftok.rb +127 -0
- data/lib/protocols/header_and_content.rb +123 -0
- data/lib/protocols/httpcli2.rb +784 -0
- data/lib/protocols/httpclient.rb +253 -0
- data/lib/protocols/line_and_text.rb +122 -0
- data/lib/protocols/linetext2.rb +145 -0
- data/lib/protocols/saslauth.rb +179 -0
- data/lib/protocols/smtpclient.rb +308 -0
- data/lib/protocols/smtpserver.rb +543 -0
- data/lib/protocols/stomp.rb +127 -0
- data/lib/protocols/tcptest.rb +57 -0
- data/lib/rubyeventmachine.so +0 -0
- data/tests/test_basic.rb +142 -0
- data/tests/test_defer.rb +63 -0
- data/tests/test_epoll.rb +168 -0
- data/tests/test_errors.rb +82 -0
- data/tests/test_eventables.rb +78 -0
- data/tests/test_exc.rb +58 -0
- data/tests/test_futures.rb +214 -0
- data/tests/test_hc.rb +221 -0
- data/tests/test_httpclient.rb +194 -0
- data/tests/test_httpclient2.rb +133 -0
- data/tests/test_kb.rb +61 -0
- data/tests/test_ltp.rb +190 -0
- data/tests/test_ltp2.rb +261 -0
- data/tests/test_next_tick.rb +58 -0
- data/tests/test_processes.rb +56 -0
- data/tests/test_pure.rb +128 -0
- data/tests/test_running.rb +47 -0
- data/tests/test_sasl.rb +73 -0
- data/tests/test_send_file.rb +238 -0
- data/tests/test_servers.rb +90 -0
- data/tests/test_smtpclient.rb +81 -0
- data/tests/test_smtpserver.rb +93 -0
- data/tests/test_spawn.rb +329 -0
- data/tests/test_timers.rb +138 -0
- data/tests/test_ud.rb +43 -0
- data/tests/testem.rb +5 -0
- metadata +170 -0
data/TODO
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
$Id: TODO 668 2008-01-04 23:00:34Z blackhedd $
|
2
|
+
|
3
|
+
TODO List:
|
4
|
+
|
5
|
+
12Aug06: Noticed by Don Stocks. A TCP connect-request that results
|
6
|
+
in a failed DNS resolution fires a fatal error back to user code.
|
7
|
+
Uuuuuugly. We should probably cause an unbind event to get fired
|
8
|
+
instead, and add some parameterization so the caller can detect
|
9
|
+
the nature of the failure.
|
10
|
+
|
data/ext/Makefile
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = .
|
7
|
+
topdir = c:/ruby/lib/ruby/1.8/i386-mswin32
|
8
|
+
hdrdir = $(topdir)
|
9
|
+
VPATH = $(srcdir);$(topdir);$(hdrdir)
|
10
|
+
|
11
|
+
DESTDIR = c:
|
12
|
+
prefix = $(DESTDIR)/ruby
|
13
|
+
exec_prefix = $(DESTDIR)/ruby
|
14
|
+
sitedir = $(prefix)/lib/ruby/site_ruby
|
15
|
+
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
16
|
+
archdir = $(rubylibdir)/$(arch)
|
17
|
+
sbindir = $(exec_prefix)/sbin
|
18
|
+
datadir = $(prefix)/share
|
19
|
+
includedir = $(prefix)/include
|
20
|
+
infodir = $(prefix)/info
|
21
|
+
sysconfdir = $(prefix)/etc
|
22
|
+
mandir = $(prefix)/man
|
23
|
+
libdir = $(DESTDIR)/ruby/lib
|
24
|
+
sharedstatedir = $(DESTDIR)/etc
|
25
|
+
oldincludedir = $(DESTDIR)/usr/include
|
26
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
27
|
+
localstatedir = $(DESTDIR)/var
|
28
|
+
bindir = $(exec_prefix)/bin
|
29
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
30
|
+
libexecdir = $(exec_prefix)/libexec
|
31
|
+
|
32
|
+
CC = cl -nologo
|
33
|
+
LIBRUBY = $(RUBY_SO_NAME).lib
|
34
|
+
LIBRUBY_A = msvcrt-ruby18-static.lib
|
35
|
+
LIBRUBYARG_SHARED = $(LIBRUBY)
|
36
|
+
LIBRUBYARG_STATIC = $(LIBRUBY_A)
|
37
|
+
|
38
|
+
RUBY_EXTCONF_H =
|
39
|
+
CFLAGS = -MD -Zi -O2b2xg- -G6
|
40
|
+
INCFLAGS = -I. -I. -Ic:/ruby/lib/ruby/1.8/i386-mswin32 -I.
|
41
|
+
CPPFLAGS = -DHAVE_WINDOWS_H -DHAVE_WINSOCK_H -DHAVE_OPENSSL_SSL_H -DHAVE_OPENSSL_ERR_H -D OS_WIN32 -D BUILD_FOR_RUBY -EHs -GR -D WITH_SSL
|
42
|
+
CXXFLAGS = $(CFLAGS)
|
43
|
+
DLDFLAGS = -link -incremental:no -debug -opt:ref -opt:icf -dll $(LIBPATH) -def:$(DEFFILE) -implib:$(*F:.so=)-$(arch).lib -pdb:$(*F:.so=)-$(arch).pdb
|
44
|
+
LDSHARED = cl -nologo -LD
|
45
|
+
AR = lib -nologo
|
46
|
+
EXEEXT = .exe
|
47
|
+
|
48
|
+
RUBY_INSTALL_NAME = ruby
|
49
|
+
RUBY_SO_NAME = msvcrt-ruby18
|
50
|
+
arch = i386-mswin32
|
51
|
+
sitearch = i386-msvcrt
|
52
|
+
ruby_version = 1.8
|
53
|
+
ruby = c:/ruby/bin/ruby
|
54
|
+
RUBY = $(ruby:/=\)
|
55
|
+
RM = $(RUBY) -run -e rm -- -f
|
56
|
+
MAKEDIRS = @$(RUBY) -run -e mkdir -- -p
|
57
|
+
INSTALL = @$(RUBY) -run -e install -- -vp
|
58
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
59
|
+
INSTALL_DATA = $(INSTALL) -m 0644
|
60
|
+
COPY = copy > nul
|
61
|
+
|
62
|
+
#### End of system configuration section. ####
|
63
|
+
|
64
|
+
preload =
|
65
|
+
|
66
|
+
libpath = $(libdir)
|
67
|
+
LIBPATH = -libpath:"$(libdir)"
|
68
|
+
DEFFILE = $(TARGET)-$(arch).def
|
69
|
+
|
70
|
+
CLEANFILES =
|
71
|
+
DISTCLEANFILES = vc*.pdb $(DEFFILE)
|
72
|
+
|
73
|
+
extout =
|
74
|
+
extout_prefix =
|
75
|
+
target_prefix =
|
76
|
+
LOCAL_LIBS =
|
77
|
+
LIBS = $(LIBRUBYARG_SHARED) libeay32.lib ssleay32.lib gdi32.lib rpcrt4.lib kernel32.lib oldnames.lib user32.lib advapi32.lib ws2_32.lib
|
78
|
+
SRCS = binder.cpp cmain.cpp cplusplus.cpp ed.cpp em.cpp emwin.cpp epoll.cpp files.cpp kb.cpp page.cpp pipe.cpp rubymain.cpp sigs.cpp ssl.cpp
|
79
|
+
OBJS = binder.obj cmain.obj cplusplus.obj ed.obj em.obj emwin.obj epoll.obj files.obj kb.obj page.obj pipe.obj rubymain.obj sigs.obj ssl.obj
|
80
|
+
TARGET = rubyeventmachine
|
81
|
+
DLLIB = $(TARGET).so
|
82
|
+
EXTSTATIC =
|
83
|
+
STATIC_LIB =
|
84
|
+
|
85
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
86
|
+
RUBYLIBDIR = C:/DOCUME~1/PAULAH~1/LOCALS~1/Temp/gembuilder/lib$(target_prefix)
|
87
|
+
RUBYARCHDIR = C:/DOCUME~1/PAULAH~1/LOCALS~1/Temp/gembuilder/lib$(target_prefix)
|
88
|
+
|
89
|
+
TARGET_SO = $(DLLIB)
|
90
|
+
CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
|
91
|
+
CLEANOBJS = *.obj *.lib *.s[ol] *.pdb *.exp *.bak
|
92
|
+
|
93
|
+
all: $(DLLIB)
|
94
|
+
static: $(STATIC_LIB)
|
95
|
+
|
96
|
+
clean:
|
97
|
+
@-$(RM) $(CLEANLIBS:/=\) $(CLEANOBJS:/=\) $(CLEANFILES:/=\)
|
98
|
+
|
99
|
+
distclean: clean
|
100
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
101
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES:/=\)
|
102
|
+
|
103
|
+
realclean: distclean
|
104
|
+
install: install-so install-rb
|
105
|
+
|
106
|
+
install-so: $(RUBYARCHDIR)
|
107
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
108
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
109
|
+
$(INSTALL_PROG) $(DLLIB:/=\) $(RUBYARCHDIR:/=\)
|
110
|
+
install-rb: pre-install-rb install-rb-default
|
111
|
+
install-rb-default: pre-install-rb-default
|
112
|
+
pre-install-rb: Makefile
|
113
|
+
pre-install-rb-default: Makefile
|
114
|
+
$(RUBYARCHDIR):
|
115
|
+
$(MAKEDIRS) $@
|
116
|
+
|
117
|
+
site-install: site-install-so site-install-rb
|
118
|
+
site-install-so: install-so
|
119
|
+
site-install-rb: install-rb
|
120
|
+
|
121
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .obj
|
122
|
+
|
123
|
+
{$(srcdir)}.cc{}.obj:
|
124
|
+
$(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
|
125
|
+
|
126
|
+
{$(topdir)}.cc{}.obj:
|
127
|
+
$(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
|
128
|
+
|
129
|
+
{$(hdrdir)}.cc{}.obj:
|
130
|
+
$(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
|
131
|
+
|
132
|
+
.cc.obj:
|
133
|
+
$(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
|
134
|
+
|
135
|
+
{$(srcdir)}.cxx{}.obj:
|
136
|
+
$(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
|
137
|
+
|
138
|
+
{$(topdir)}.cxx{}.obj:
|
139
|
+
$(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
|
140
|
+
|
141
|
+
{$(hdrdir)}.cxx{}.obj:
|
142
|
+
$(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
|
143
|
+
|
144
|
+
.cxx.obj:
|
145
|
+
$(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
|
146
|
+
|
147
|
+
{$(srcdir)}.cpp{}.obj:
|
148
|
+
$(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
|
149
|
+
|
150
|
+
{$(topdir)}.cpp{}.obj:
|
151
|
+
$(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
|
152
|
+
|
153
|
+
{$(hdrdir)}.cpp{}.obj:
|
154
|
+
$(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
|
155
|
+
|
156
|
+
.cpp.obj:
|
157
|
+
$(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
|
158
|
+
|
159
|
+
{$(srcdir)}.c{}.obj:
|
160
|
+
$(CC) $(INCFLAGS) $(CFLAGS) $(CPPFLAGS) -c -Tc$(<:\=/)
|
161
|
+
|
162
|
+
{$(topdir)}.c{}.obj:
|
163
|
+
$(CC) $(INCFLAGS) $(CFLAGS) $(CPPFLAGS) -c -Tc$(<:\=/)
|
164
|
+
|
165
|
+
{$(hdrdir)}.c{}.obj:
|
166
|
+
$(CC) $(INCFLAGS) $(CFLAGS) $(CPPFLAGS) -c -Tc$(<:\=/)
|
167
|
+
|
168
|
+
.c.obj:
|
169
|
+
$(CC) $(INCFLAGS) $(CFLAGS) $(CPPFLAGS) -c -Tc$(<:\=/)
|
170
|
+
|
171
|
+
$(DLLIB): $(DEFFILE) $(OBJS)
|
172
|
+
@-$(RM) $@
|
173
|
+
$(LDSHARED) -Fe$(@) $(OBJS) $(LIBS) $(LOCAL_LIBS) $(DLDFLAGS)
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
$(DEFFILE):
|
178
|
+
$(RUBY) -e "puts 'EXPORTS', 'Init_$(TARGET)'" > $@
|
179
|
+
|
180
|
+
$(OBJS): {.;$(srcdir);$(topdir);$(hdrdir)}ruby.h {.;$(srcdir);$(topdir);$(hdrdir)}defines.h
|
data/ext/binder.cpp
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
|
3
|
+
$Id: binder.cpp 668 2008-01-04 23:00:34Z blackhedd $
|
4
|
+
|
5
|
+
File: binder.cpp
|
6
|
+
Date: 07Apr06
|
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
|
+
#include "project.h"
|
21
|
+
|
22
|
+
#define DEV_URANDOM "/dev/urandom"
|
23
|
+
|
24
|
+
|
25
|
+
map<string, Bindable_t*> Bindable_t::BindingBag;
|
26
|
+
|
27
|
+
|
28
|
+
/********************************
|
29
|
+
STATIC Bindable_t::CreateBinding
|
30
|
+
********************************/
|
31
|
+
|
32
|
+
string Bindable_t::CreateBinding()
|
33
|
+
{
|
34
|
+
static int index = 0;
|
35
|
+
static string seed;
|
36
|
+
|
37
|
+
if ((index >= 1000000) || (seed.length() == 0)) {
|
38
|
+
#ifdef OS_UNIX
|
39
|
+
int fd = open (DEV_URANDOM, O_RDONLY);
|
40
|
+
if (fd < 0)
|
41
|
+
throw std::runtime_error ("No entropy device");
|
42
|
+
|
43
|
+
unsigned char u[16];
|
44
|
+
size_t r = read (fd, u, sizeof(u));
|
45
|
+
if (r < sizeof(u))
|
46
|
+
throw std::runtime_error ("Unable to read entropy device");
|
47
|
+
|
48
|
+
unsigned char *u1 = (unsigned char*)u;
|
49
|
+
char u2 [sizeof(u) * 2 + 1];
|
50
|
+
|
51
|
+
for (size_t i=0; i < sizeof(u); i++)
|
52
|
+
sprintf (u2 + (i * 2), "%02x", u1[i]);
|
53
|
+
|
54
|
+
seed = string (u2);
|
55
|
+
#endif
|
56
|
+
|
57
|
+
|
58
|
+
#ifdef OS_WIN32
|
59
|
+
UUID uuid;
|
60
|
+
UuidCreate (&uuid);
|
61
|
+
unsigned char *uuidstring = NULL;
|
62
|
+
UuidToString (&uuid, &uuidstring);
|
63
|
+
if (!uuidstring)
|
64
|
+
throw std::runtime_error ("Unable to read uuid");
|
65
|
+
seed = string ((const char*)uuidstring);
|
66
|
+
|
67
|
+
RpcStringFree (&uuidstring);
|
68
|
+
#endif
|
69
|
+
|
70
|
+
index = 0;
|
71
|
+
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
stringstream ss;
|
76
|
+
ss << seed << (++index);
|
77
|
+
return ss.str();
|
78
|
+
}
|
79
|
+
|
80
|
+
|
81
|
+
/*****************************
|
82
|
+
STATIC: Bindable_t::GetObject
|
83
|
+
*****************************/
|
84
|
+
|
85
|
+
Bindable_t *Bindable_t::GetObject (const char *binding)
|
86
|
+
{
|
87
|
+
string s (binding ? binding : "");
|
88
|
+
return GetObject (s);
|
89
|
+
}
|
90
|
+
|
91
|
+
/*****************************
|
92
|
+
STATIC: Bindable_t::GetObject
|
93
|
+
*****************************/
|
94
|
+
|
95
|
+
Bindable_t *Bindable_t::GetObject (const string &binding)
|
96
|
+
{
|
97
|
+
map<string, Bindable_t*>::const_iterator i = BindingBag.find (binding);
|
98
|
+
if (i != BindingBag.end())
|
99
|
+
return i->second;
|
100
|
+
else
|
101
|
+
return NULL;
|
102
|
+
}
|
103
|
+
|
104
|
+
|
105
|
+
/**********************
|
106
|
+
Bindable_t::Bindable_t
|
107
|
+
**********************/
|
108
|
+
|
109
|
+
Bindable_t::Bindable_t()
|
110
|
+
{
|
111
|
+
Binding = Bindable_t::CreateBinding();
|
112
|
+
BindingBag [Binding] = this;
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
/***********************
|
118
|
+
Bindable_t::~Bindable_t
|
119
|
+
***********************/
|
120
|
+
|
121
|
+
Bindable_t::~Bindable_t()
|
122
|
+
{
|
123
|
+
BindingBag.erase (Binding);
|
124
|
+
}
|
125
|
+
|
126
|
+
|
data/ext/binder.h
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
|
3
|
+
$Id: binder.h 668 2008-01-04 23:00:34Z blackhedd $
|
4
|
+
|
5
|
+
File: binder.h
|
6
|
+
Date: 07Apr06
|
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
|
+
#ifndef __ObjectBindings__H_
|
21
|
+
#define __ObjectBindings__H_
|
22
|
+
|
23
|
+
|
24
|
+
class Bindable_t
|
25
|
+
{
|
26
|
+
public:
|
27
|
+
static string CreateBinding();
|
28
|
+
static Bindable_t *GetObject (const string&);
|
29
|
+
static Bindable_t *GetObject (const char*);
|
30
|
+
static map<string, Bindable_t*> BindingBag;
|
31
|
+
|
32
|
+
public:
|
33
|
+
Bindable_t();
|
34
|
+
virtual ~Bindable_t();
|
35
|
+
|
36
|
+
const string &GetBinding() {return Binding;}
|
37
|
+
const char *GetBindingChars() {return Binding.c_str();}
|
38
|
+
|
39
|
+
private:
|
40
|
+
string Binding;
|
41
|
+
};
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
#endif // __ObjectBindings__H_
|
48
|
+
|
data/ext/cmain.cpp
ADDED
@@ -0,0 +1,527 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
|
3
|
+
$Id: cmain.cpp 679 2008-01-19 01:40:06Z blackhedd $
|
4
|
+
|
5
|
+
File: cmain.cpp
|
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
|
+
#include "project.h"
|
21
|
+
|
22
|
+
|
23
|
+
static EventMachine_t *EventMachine;
|
24
|
+
static int bUseEpoll = 0;
|
25
|
+
static int bUseKqueue = 0;
|
26
|
+
|
27
|
+
|
28
|
+
/***********************
|
29
|
+
evma_initialize_library
|
30
|
+
***********************/
|
31
|
+
|
32
|
+
extern "C" void evma_initialize_library (void(*cb)(const char*, int, const char*, int))
|
33
|
+
{
|
34
|
+
// Probably a bad idea to mess with the signal mask of a process
|
35
|
+
// we're just being linked into.
|
36
|
+
//InstallSignalHandlers();
|
37
|
+
if (EventMachine)
|
38
|
+
throw std::runtime_error ("already initialized");
|
39
|
+
EventMachine = new EventMachine_t (cb);
|
40
|
+
if (bUseEpoll)
|
41
|
+
EventMachine->_UseEpoll();
|
42
|
+
if (bUseKqueue)
|
43
|
+
EventMachine->_UseKqueue();
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
/********************
|
48
|
+
evma_release_library
|
49
|
+
********************/
|
50
|
+
|
51
|
+
extern "C" void evma_release_library()
|
52
|
+
{
|
53
|
+
if (!EventMachine)
|
54
|
+
throw std::runtime_error ("not initialized");
|
55
|
+
delete EventMachine;
|
56
|
+
EventMachine = NULL;
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
/****************
|
61
|
+
evma_run_machine
|
62
|
+
****************/
|
63
|
+
|
64
|
+
extern "C" void evma_run_machine()
|
65
|
+
{
|
66
|
+
if (!EventMachine)
|
67
|
+
throw std::runtime_error ("not initialized");
|
68
|
+
EventMachine->Run();
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
/**************************
|
73
|
+
evma_install_oneshot_timer
|
74
|
+
**************************/
|
75
|
+
|
76
|
+
extern "C" const char *evma_install_oneshot_timer (int seconds)
|
77
|
+
{
|
78
|
+
if (!EventMachine)
|
79
|
+
throw std::runtime_error ("not initialized");
|
80
|
+
return EventMachine->InstallOneshotTimer (seconds);
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
/**********************
|
85
|
+
evma_connect_to_server
|
86
|
+
**********************/
|
87
|
+
|
88
|
+
extern "C" const char *evma_connect_to_server (const char *server, int port)
|
89
|
+
{
|
90
|
+
if (!EventMachine)
|
91
|
+
throw std::runtime_error ("not initialized");
|
92
|
+
return EventMachine->ConnectToServer (server, port);
|
93
|
+
}
|
94
|
+
|
95
|
+
/***************************
|
96
|
+
evma_connect_to_unix_server
|
97
|
+
***************************/
|
98
|
+
|
99
|
+
extern "C" const char *evma_connect_to_unix_server (const char *server)
|
100
|
+
{
|
101
|
+
if (!EventMachine)
|
102
|
+
throw std::runtime_error ("not initialized");
|
103
|
+
return EventMachine->ConnectToUnixServer (server);
|
104
|
+
}
|
105
|
+
|
106
|
+
|
107
|
+
/**********************
|
108
|
+
evma_create_tcp_server
|
109
|
+
**********************/
|
110
|
+
|
111
|
+
extern "C" const char *evma_create_tcp_server (const char *address, int port)
|
112
|
+
{
|
113
|
+
if (!EventMachine)
|
114
|
+
throw std::runtime_error ("not initialized");
|
115
|
+
return EventMachine->CreateTcpServer (address, port);
|
116
|
+
}
|
117
|
+
|
118
|
+
/******************************
|
119
|
+
evma_create_unix_domain_server
|
120
|
+
******************************/
|
121
|
+
|
122
|
+
extern "C" const char *evma_create_unix_domain_server (const char *filename)
|
123
|
+
{
|
124
|
+
if (!EventMachine)
|
125
|
+
throw std::runtime_error ("not initialized");
|
126
|
+
return EventMachine->CreateUnixDomainServer (filename);
|
127
|
+
}
|
128
|
+
|
129
|
+
/*************************
|
130
|
+
evma_open_datagram_socket
|
131
|
+
*************************/
|
132
|
+
|
133
|
+
extern "C" const char *evma_open_datagram_socket (const char *address, int port)
|
134
|
+
{
|
135
|
+
if (!EventMachine)
|
136
|
+
throw std::runtime_error ("not initialized");
|
137
|
+
return EventMachine->OpenDatagramSocket (address, port);
|
138
|
+
}
|
139
|
+
|
140
|
+
/******************
|
141
|
+
evma_open_keyboard
|
142
|
+
******************/
|
143
|
+
|
144
|
+
extern "C" const char *evma_open_keyboard()
|
145
|
+
{
|
146
|
+
if (!EventMachine)
|
147
|
+
throw std::runtime_error ("not initialized");
|
148
|
+
return EventMachine->OpenKeyboard();
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
/****************************
|
154
|
+
evma_send_data_to_connection
|
155
|
+
****************************/
|
156
|
+
|
157
|
+
extern "C" int evma_send_data_to_connection (const char *binding, const char *data, int data_length)
|
158
|
+
{
|
159
|
+
if (!EventMachine)
|
160
|
+
throw std::runtime_error ("not initialized");
|
161
|
+
return ConnectionDescriptor::SendDataToConnection (binding, data, data_length);
|
162
|
+
}
|
163
|
+
|
164
|
+
/******************
|
165
|
+
evma_send_datagram
|
166
|
+
******************/
|
167
|
+
|
168
|
+
extern "C" int evma_send_datagram (const char *binding, const char *data, int data_length, const char *address, int port)
|
169
|
+
{
|
170
|
+
if (!EventMachine)
|
171
|
+
throw std::runtime_error ("not initialized");
|
172
|
+
return DatagramDescriptor::SendDatagram (binding, data, data_length, address, port);
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
/*********************
|
177
|
+
evma_close_connection
|
178
|
+
*********************/
|
179
|
+
|
180
|
+
extern "C" void evma_close_connection (const char *binding, int after_writing)
|
181
|
+
{
|
182
|
+
if (!EventMachine)
|
183
|
+
throw std::runtime_error ("not initialized");
|
184
|
+
ConnectionDescriptor::CloseConnection (binding, (after_writing ? true : false));
|
185
|
+
}
|
186
|
+
|
187
|
+
/***********************************
|
188
|
+
evma_report_connection_error_status
|
189
|
+
***********************************/
|
190
|
+
|
191
|
+
extern "C" int evma_report_connection_error_status (const char *binding)
|
192
|
+
{
|
193
|
+
if (!EventMachine)
|
194
|
+
throw std::runtime_error ("not initialized");
|
195
|
+
return ConnectionDescriptor::ReportErrorStatus (binding);
|
196
|
+
}
|
197
|
+
|
198
|
+
/********************
|
199
|
+
evma_stop_tcp_server
|
200
|
+
********************/
|
201
|
+
|
202
|
+
extern "C" void evma_stop_tcp_server (const char *binding)
|
203
|
+
{
|
204
|
+
if (!EventMachine)
|
205
|
+
throw std::runtime_error ("not initialized");
|
206
|
+
AcceptorDescriptor::StopAcceptor (binding);
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
/*****************
|
211
|
+
evma_stop_machine
|
212
|
+
*****************/
|
213
|
+
|
214
|
+
extern "C" void evma_stop_machine()
|
215
|
+
{
|
216
|
+
if (!EventMachine)
|
217
|
+
throw std::runtime_error ("not initialized");
|
218
|
+
EventMachine->ScheduleHalt();
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
/**************
|
223
|
+
evma_start_tls
|
224
|
+
**************/
|
225
|
+
|
226
|
+
extern "C" void evma_start_tls (const char *binding)
|
227
|
+
{
|
228
|
+
if (!EventMachine)
|
229
|
+
throw std::runtime_error ("not initialized");
|
230
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
231
|
+
if (ed)
|
232
|
+
ed->StartTls();
|
233
|
+
}
|
234
|
+
|
235
|
+
/******************
|
236
|
+
evma_set_tls_parms
|
237
|
+
******************/
|
238
|
+
|
239
|
+
extern "C" void evma_set_tls_parms (const char *binding, const char *privatekey_filename, const char *certchain_filename)
|
240
|
+
{
|
241
|
+
if (!EventMachine)
|
242
|
+
throw std::runtime_error ("not initialized");
|
243
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
244
|
+
if (ed)
|
245
|
+
ed->SetTlsParms (privatekey_filename, certchain_filename);
|
246
|
+
}
|
247
|
+
|
248
|
+
|
249
|
+
/*****************
|
250
|
+
evma_get_peername
|
251
|
+
*****************/
|
252
|
+
|
253
|
+
extern "C" int evma_get_peername (const char *binding, struct sockaddr *sa)
|
254
|
+
{
|
255
|
+
if (!EventMachine)
|
256
|
+
throw std::runtime_error ("not initialized");
|
257
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
258
|
+
if (ed) {
|
259
|
+
return ed->GetPeername (sa) ? 1 : 0;
|
260
|
+
}
|
261
|
+
else
|
262
|
+
return 0;
|
263
|
+
}
|
264
|
+
|
265
|
+
/*****************
|
266
|
+
evma_get_sockname
|
267
|
+
*****************/
|
268
|
+
|
269
|
+
extern "C" int evma_get_sockname (const char *binding, struct sockaddr *sa)
|
270
|
+
{
|
271
|
+
if (!EventMachine)
|
272
|
+
throw std::runtime_error ("not initialized");
|
273
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
274
|
+
if (ed) {
|
275
|
+
return ed->GetSockname (sa) ? 1 : 0;
|
276
|
+
}
|
277
|
+
else
|
278
|
+
return 0;
|
279
|
+
}
|
280
|
+
|
281
|
+
/***********************
|
282
|
+
evma_get_subprocess_pid
|
283
|
+
***********************/
|
284
|
+
|
285
|
+
extern "C" int evma_get_subprocess_pid (const char *binding, pid_t *pid)
|
286
|
+
{
|
287
|
+
if (!EventMachine)
|
288
|
+
throw std::runtime_error ("not initialized");
|
289
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
290
|
+
if (ed) {
|
291
|
+
return ed->GetSubprocessPid (pid) ? 1 : 0;
|
292
|
+
}
|
293
|
+
else
|
294
|
+
return 0;
|
295
|
+
}
|
296
|
+
|
297
|
+
/**************************
|
298
|
+
evma_get_subprocess_status
|
299
|
+
**************************/
|
300
|
+
|
301
|
+
extern "C" int evma_get_subprocess_status (const char *binding, int *status)
|
302
|
+
{
|
303
|
+
if (!EventMachine)
|
304
|
+
throw std::runtime_error ("not initialized");
|
305
|
+
if (status) {
|
306
|
+
*status = EventMachine->SubprocessExitStatus;
|
307
|
+
return 1;
|
308
|
+
}
|
309
|
+
else
|
310
|
+
return 0;
|
311
|
+
}
|
312
|
+
|
313
|
+
|
314
|
+
/*********************
|
315
|
+
evma_signal_loopbreak
|
316
|
+
*********************/
|
317
|
+
|
318
|
+
extern "C" void evma_signal_loopbreak()
|
319
|
+
{
|
320
|
+
if (!EventMachine)
|
321
|
+
throw std::runtime_error ("not initialized");
|
322
|
+
EventMachine->SignalLoopBreaker();
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
/****************
|
328
|
+
evma__write_file
|
329
|
+
****************/
|
330
|
+
|
331
|
+
extern "C" const char *evma__write_file (const char *filename)
|
332
|
+
{
|
333
|
+
if (!EventMachine)
|
334
|
+
throw std::runtime_error ("not initialized");
|
335
|
+
return EventMachine->_OpenFileForWriting (filename);
|
336
|
+
}
|
337
|
+
|
338
|
+
|
339
|
+
/********************************
|
340
|
+
evma_get_comm_inactivity_timeout
|
341
|
+
********************************/
|
342
|
+
|
343
|
+
extern "C" int evma_get_comm_inactivity_timeout (const char *binding, int *value)
|
344
|
+
{
|
345
|
+
if (!EventMachine)
|
346
|
+
throw std::runtime_error ("not initialized");
|
347
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
348
|
+
if (ed) {
|
349
|
+
return ed->GetCommInactivityTimeout (value);
|
350
|
+
}
|
351
|
+
else
|
352
|
+
return 0; //Perhaps this should be an exception. Access to an unknown binding.
|
353
|
+
}
|
354
|
+
|
355
|
+
/********************************
|
356
|
+
evma_set_comm_inactivity_timeout
|
357
|
+
********************************/
|
358
|
+
|
359
|
+
extern "C" int evma_set_comm_inactivity_timeout (const char *binding, int *value)
|
360
|
+
{
|
361
|
+
if (!EventMachine)
|
362
|
+
throw std::runtime_error ("not initialized");
|
363
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
364
|
+
if (ed) {
|
365
|
+
return ed->SetCommInactivityTimeout (value);
|
366
|
+
}
|
367
|
+
else
|
368
|
+
return 0; //Perhaps this should be an exception. Access to an unknown binding.
|
369
|
+
}
|
370
|
+
|
371
|
+
|
372
|
+
/**********************
|
373
|
+
evma_set_timer_quantum
|
374
|
+
**********************/
|
375
|
+
|
376
|
+
extern "C" void evma_set_timer_quantum (int interval)
|
377
|
+
{
|
378
|
+
if (!EventMachine)
|
379
|
+
throw std::runtime_error ("not initialized");
|
380
|
+
EventMachine->SetTimerQuantum (interval);
|
381
|
+
}
|
382
|
+
|
383
|
+
/************************
|
384
|
+
evma_set_max_timer_count
|
385
|
+
************************/
|
386
|
+
|
387
|
+
extern "C" void evma_set_max_timer_count (int ct)
|
388
|
+
{
|
389
|
+
// This may only be called if the reactor is not running.
|
390
|
+
if (EventMachine)
|
391
|
+
throw std::runtime_error ("already initialized");
|
392
|
+
EventMachine_t::SetMaxTimerCount (ct);
|
393
|
+
}
|
394
|
+
|
395
|
+
/******************
|
396
|
+
evma_setuid_string
|
397
|
+
******************/
|
398
|
+
|
399
|
+
extern "C" void evma_setuid_string (const char *username)
|
400
|
+
{
|
401
|
+
// We do NOT need to be running an EM instance because this method is static.
|
402
|
+
EventMachine_t::SetuidString (username);
|
403
|
+
}
|
404
|
+
|
405
|
+
|
406
|
+
/**********
|
407
|
+
evma_popen
|
408
|
+
**********/
|
409
|
+
|
410
|
+
extern "C" const char *evma_popen (char * const*cmd_strings)
|
411
|
+
{
|
412
|
+
if (!EventMachine)
|
413
|
+
throw std::runtime_error ("not initialized");
|
414
|
+
return EventMachine->Socketpair (cmd_strings);
|
415
|
+
}
|
416
|
+
|
417
|
+
|
418
|
+
/***************************
|
419
|
+
evma_get_outbound_data_size
|
420
|
+
***************************/
|
421
|
+
|
422
|
+
extern "C" int evma_get_outbound_data_size (const char *binding)
|
423
|
+
{
|
424
|
+
if (!EventMachine)
|
425
|
+
throw std::runtime_error ("not initialized");
|
426
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
427
|
+
return ed ? ed->GetOutboundDataSize() : 0;
|
428
|
+
}
|
429
|
+
|
430
|
+
|
431
|
+
/***********
|
432
|
+
evma__epoll
|
433
|
+
***********/
|
434
|
+
|
435
|
+
extern "C" void evma__epoll()
|
436
|
+
{
|
437
|
+
bUseEpoll = 1;
|
438
|
+
}
|
439
|
+
|
440
|
+
/************
|
441
|
+
evma__kqueue
|
442
|
+
************/
|
443
|
+
|
444
|
+
extern "C" void evma__kqueue()
|
445
|
+
{
|
446
|
+
bUseKqueue = 1;
|
447
|
+
}
|
448
|
+
|
449
|
+
|
450
|
+
/**********************
|
451
|
+
evma_set_rlimit_nofile
|
452
|
+
**********************/
|
453
|
+
|
454
|
+
extern "C" int evma_set_rlimit_nofile (int nofiles)
|
455
|
+
{
|
456
|
+
return EventMachine_t::SetRlimitNofile (nofiles);
|
457
|
+
}
|
458
|
+
|
459
|
+
|
460
|
+
/*********************************
|
461
|
+
evma_send_file_data_to_connection
|
462
|
+
*********************************/
|
463
|
+
|
464
|
+
extern "C" int evma_send_file_data_to_connection (const char *binding, const char *filename)
|
465
|
+
{
|
466
|
+
/* This is a sugaring over send_data_to_connection that reads a file into a
|
467
|
+
* locally-allocated buffer, and sends the file data to the remote peer.
|
468
|
+
* Return the number of bytes written to the caller.
|
469
|
+
* TODO, needs to impose a limit on the file size. This is intended only for
|
470
|
+
* small files. (I don't know, maybe 8K or less.) For larger files, use interleaved
|
471
|
+
* I/O to avoid slowing the rest of the system down.
|
472
|
+
* TODO: we should return a code rather than barf, in case of file-not-found.
|
473
|
+
* TODO, does this compile on Windows?
|
474
|
+
* TODO, given that we want this to work only with small files, how about allocating
|
475
|
+
* the buffer on the stack rather than the heap?
|
476
|
+
*
|
477
|
+
* Modified 25Jul07. This now returns -1 on file-too-large; 0 for success, and a positive
|
478
|
+
* errno in case of other errors.
|
479
|
+
*
|
480
|
+
/* Contributed by Kirk Haines.
|
481
|
+
*/
|
482
|
+
|
483
|
+
char data[32*1024];
|
484
|
+
int r;
|
485
|
+
|
486
|
+
if (!EventMachine)
|
487
|
+
throw std::runtime_error("not initialized");
|
488
|
+
|
489
|
+
int Fd = open (filename, O_RDONLY);
|
490
|
+
|
491
|
+
if (Fd < 0)
|
492
|
+
return errno;
|
493
|
+
// From here on, all early returns MUST close Fd.
|
494
|
+
|
495
|
+
struct stat st;
|
496
|
+
if (fstat (Fd, &st)) {
|
497
|
+
int e = errno;
|
498
|
+
close (Fd);
|
499
|
+
return e;
|
500
|
+
}
|
501
|
+
|
502
|
+
int filesize = st.st_size;
|
503
|
+
if (filesize <= 0) {
|
504
|
+
close (Fd);
|
505
|
+
return 0;
|
506
|
+
}
|
507
|
+
else if (filesize > sizeof(data)) {
|
508
|
+
close (Fd);
|
509
|
+
return -1;
|
510
|
+
}
|
511
|
+
|
512
|
+
|
513
|
+
r = read (Fd, data, filesize);
|
514
|
+
if (r != filesize) {
|
515
|
+
int e = errno;
|
516
|
+
close (Fd);
|
517
|
+
return e;
|
518
|
+
}
|
519
|
+
evma_send_data_to_connection (binding, data, r);
|
520
|
+
close (Fd);
|
521
|
+
|
522
|
+
return 0;
|
523
|
+
}
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
|