brianmario-eventmachine 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- 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/eventmachine.gemspec +15 -0
- data/ext/binder.cpp +126 -0
- data/ext/binder.h +48 -0
- data/ext/cmain.cpp +553 -0
- data/ext/cplusplus.cpp +172 -0
- data/ext/ed.cpp +1473 -0
- data/ext/ed.h +361 -0
- data/ext/em.cpp +1890 -0
- data/ext/em.h +170 -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 +90 -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/page.cpp +107 -0
- data/ext/page.h +51 -0
- data/ext/pipe.cpp +327 -0
- data/ext/project.h +119 -0
- data/ext/rubymain.cpp +678 -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/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 +1756 -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 +132 -0
- data/lib/pr_eventmachine.rb +1011 -0
- data/lib/protocols/buftok.rb +127 -0
- data/lib/protocols/header_and_content.rb +129 -0
- data/lib/protocols/httpcli2.rb +784 -0
- data/lib/protocols/httpclient.rb +264 -0
- data/lib/protocols/line_and_text.rb +122 -0
- data/lib/protocols/linetext2.rb +163 -0
- data/lib/protocols/postgres.rb +261 -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 +130 -0
- data/lib/protocols/tcptest.rb +57 -0
- data/setup.rb +1585 -0
- metadata +126 -0
data/TODO
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
$Id$
|
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
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "eventmachine"
|
3
|
+
s.version = "0.12.2"
|
4
|
+
s.date = "2008-9-18"
|
5
|
+
s.summary = "bugfix for start_tls args, using File.exist checks"
|
6
|
+
s.email = "brianmario@me.com"
|
7
|
+
s.homepage = "http://github.com/brianmario/eventmachine"
|
8
|
+
s.description = "bugfix for start_tls args, using File.exist checks"
|
9
|
+
s.has_rdoc = true
|
10
|
+
s.authors = ["Brian Lopez"]
|
11
|
+
s.files = ["RELEASE_NOTES", "README", "LEGAL", "COPYING", "GNU", "TODO", "DEFERRABLES", "EPOLL", "SPAWNED_PROCESSES", "LIGHTWEIGHT_CONCURRENCY", "SMTP", "PURE_RUBY", "KEYBOARD", "setup.rb", "eventmachine.gemspec", "lib/em", "lib/em/deferrable.rb", "lib/em/eventable.rb", "lib/em/future.rb", "lib/em/messages.rb", "lib/em/processes.rb", "lib/em/spawnable.rb", "lib/em/streamer.rb", "lib/eventmachine.rb", "lib/eventmachine_version.rb", "lib/evma", "lib/evma/callback.rb", "lib/evma/container.rb", "lib/evma/factory.rb", "lib/evma/protocol.rb", "lib/evma/reactor.rb", "lib/evma.rb", "lib/jeventmachine.rb", "lib/pr_eventmachine.rb", "lib/protocols", "lib/protocols/buftok.rb", "lib/protocols/header_and_content.rb", "lib/protocols/httpcli2.rb", "lib/protocols/httpclient.rb", "lib/protocols/line_and_text.rb", "lib/protocols/linetext2.rb", "lib/protocols/postgres.rb", "lib/protocols/saslauth.rb", "lib/protocols/smtpclient.rb", "lib/protocols/smtpserver.rb", "lib/protocols/stomp.rb", "lib/protocols/tcptest.rb", "ext/binder.cpp", "ext/binder.h", "ext/cmain.cpp", "ext/cplusplus.cpp", "ext/ed.cpp", "ext/ed.h", "ext/em.cpp", "ext/em.h", "ext/emwin.cpp", "ext/emwin.h", "ext/epoll.cpp", "ext/epoll.h", "ext/eventmachine.h", "ext/eventmachine_cpp.h", "ext/extconf.rb", "ext/files.cpp", "ext/files.h", "ext/kb.cpp", "ext/page.cpp", "ext/page.h", "ext/pipe.cpp", "ext/project.h", "ext/rubymain.cpp", "ext/sigs.cpp", "ext/sigs.h", "ext/ssl.cpp", "ext/ssl.h"]
|
12
|
+
s.test_files = []
|
13
|
+
s.extensions = 'ext/extconf.rb'
|
14
|
+
s.extra_rdoc_files = ["README"]
|
15
|
+
end
|
data/ext/binder.cpp
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
|
3
|
+
$Id$
|
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$
|
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,553 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
|
3
|
+
$Id$
|
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
|
+
evma_attach_fd
|
108
|
+
**************/
|
109
|
+
|
110
|
+
extern "C" const char *evma_attach_fd (int file_descriptor, int notify_readable, int notify_writable)
|
111
|
+
{
|
112
|
+
if (!EventMachine)
|
113
|
+
throw std::runtime_error ("not initialized");
|
114
|
+
return EventMachine->AttachFD (file_descriptor, (notify_readable ? true : false), (notify_writable ? true : false));
|
115
|
+
}
|
116
|
+
|
117
|
+
/**************
|
118
|
+
evma_detach_fd
|
119
|
+
**************/
|
120
|
+
|
121
|
+
extern "C" int evma_detach_fd (const char *binding)
|
122
|
+
{
|
123
|
+
if (!EventMachine)
|
124
|
+
throw std::runtime_error ("not initialized");
|
125
|
+
|
126
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
127
|
+
if (ed)
|
128
|
+
return EventMachine->DetachFD (ed);
|
129
|
+
else
|
130
|
+
throw std::runtime_error ("invalid binding to detach");
|
131
|
+
}
|
132
|
+
|
133
|
+
/**********************
|
134
|
+
evma_create_tcp_server
|
135
|
+
**********************/
|
136
|
+
|
137
|
+
extern "C" const char *evma_create_tcp_server (const char *address, int port)
|
138
|
+
{
|
139
|
+
if (!EventMachine)
|
140
|
+
throw std::runtime_error ("not initialized");
|
141
|
+
return EventMachine->CreateTcpServer (address, port);
|
142
|
+
}
|
143
|
+
|
144
|
+
/******************************
|
145
|
+
evma_create_unix_domain_server
|
146
|
+
******************************/
|
147
|
+
|
148
|
+
extern "C" const char *evma_create_unix_domain_server (const char *filename)
|
149
|
+
{
|
150
|
+
if (!EventMachine)
|
151
|
+
throw std::runtime_error ("not initialized");
|
152
|
+
return EventMachine->CreateUnixDomainServer (filename);
|
153
|
+
}
|
154
|
+
|
155
|
+
/*************************
|
156
|
+
evma_open_datagram_socket
|
157
|
+
*************************/
|
158
|
+
|
159
|
+
extern "C" const char *evma_open_datagram_socket (const char *address, int port)
|
160
|
+
{
|
161
|
+
if (!EventMachine)
|
162
|
+
throw std::runtime_error ("not initialized");
|
163
|
+
return EventMachine->OpenDatagramSocket (address, port);
|
164
|
+
}
|
165
|
+
|
166
|
+
/******************
|
167
|
+
evma_open_keyboard
|
168
|
+
******************/
|
169
|
+
|
170
|
+
extern "C" const char *evma_open_keyboard()
|
171
|
+
{
|
172
|
+
if (!EventMachine)
|
173
|
+
throw std::runtime_error ("not initialized");
|
174
|
+
return EventMachine->OpenKeyboard();
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
/****************************
|
180
|
+
evma_send_data_to_connection
|
181
|
+
****************************/
|
182
|
+
|
183
|
+
extern "C" int evma_send_data_to_connection (const char *binding, const char *data, int data_length)
|
184
|
+
{
|
185
|
+
if (!EventMachine)
|
186
|
+
throw std::runtime_error ("not initialized");
|
187
|
+
return ConnectionDescriptor::SendDataToConnection (binding, data, data_length);
|
188
|
+
}
|
189
|
+
|
190
|
+
/******************
|
191
|
+
evma_send_datagram
|
192
|
+
******************/
|
193
|
+
|
194
|
+
extern "C" int evma_send_datagram (const char *binding, const char *data, int data_length, const char *address, int port)
|
195
|
+
{
|
196
|
+
if (!EventMachine)
|
197
|
+
throw std::runtime_error ("not initialized");
|
198
|
+
return DatagramDescriptor::SendDatagram (binding, data, data_length, address, port);
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
/*********************
|
203
|
+
evma_close_connection
|
204
|
+
*********************/
|
205
|
+
|
206
|
+
extern "C" void evma_close_connection (const char *binding, int after_writing)
|
207
|
+
{
|
208
|
+
if (!EventMachine)
|
209
|
+
throw std::runtime_error ("not initialized");
|
210
|
+
ConnectionDescriptor::CloseConnection (binding, (after_writing ? true : false));
|
211
|
+
}
|
212
|
+
|
213
|
+
/***********************************
|
214
|
+
evma_report_connection_error_status
|
215
|
+
***********************************/
|
216
|
+
|
217
|
+
extern "C" int evma_report_connection_error_status (const char *binding)
|
218
|
+
{
|
219
|
+
if (!EventMachine)
|
220
|
+
throw std::runtime_error ("not initialized");
|
221
|
+
return ConnectionDescriptor::ReportErrorStatus (binding);
|
222
|
+
}
|
223
|
+
|
224
|
+
/********************
|
225
|
+
evma_stop_tcp_server
|
226
|
+
********************/
|
227
|
+
|
228
|
+
extern "C" void evma_stop_tcp_server (const char *binding)
|
229
|
+
{
|
230
|
+
if (!EventMachine)
|
231
|
+
throw std::runtime_error ("not initialized");
|
232
|
+
AcceptorDescriptor::StopAcceptor (binding);
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
/*****************
|
237
|
+
evma_stop_machine
|
238
|
+
*****************/
|
239
|
+
|
240
|
+
extern "C" void evma_stop_machine()
|
241
|
+
{
|
242
|
+
if (!EventMachine)
|
243
|
+
throw std::runtime_error ("not initialized");
|
244
|
+
EventMachine->ScheduleHalt();
|
245
|
+
}
|
246
|
+
|
247
|
+
|
248
|
+
/**************
|
249
|
+
evma_start_tls
|
250
|
+
**************/
|
251
|
+
|
252
|
+
extern "C" void evma_start_tls (const char *binding)
|
253
|
+
{
|
254
|
+
if (!EventMachine)
|
255
|
+
throw std::runtime_error ("not initialized");
|
256
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
257
|
+
if (ed)
|
258
|
+
ed->StartTls();
|
259
|
+
}
|
260
|
+
|
261
|
+
/******************
|
262
|
+
evma_set_tls_parms
|
263
|
+
******************/
|
264
|
+
|
265
|
+
extern "C" void evma_set_tls_parms (const char *binding, const char *privatekey_filename, const char *certchain_filename)
|
266
|
+
{
|
267
|
+
if (!EventMachine)
|
268
|
+
throw std::runtime_error ("not initialized");
|
269
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
270
|
+
if (ed)
|
271
|
+
ed->SetTlsParms (privatekey_filename, certchain_filename);
|
272
|
+
}
|
273
|
+
|
274
|
+
|
275
|
+
/*****************
|
276
|
+
evma_get_peername
|
277
|
+
*****************/
|
278
|
+
|
279
|
+
extern "C" int evma_get_peername (const char *binding, struct sockaddr *sa)
|
280
|
+
{
|
281
|
+
if (!EventMachine)
|
282
|
+
throw std::runtime_error ("not initialized");
|
283
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
284
|
+
if (ed) {
|
285
|
+
return ed->GetPeername (sa) ? 1 : 0;
|
286
|
+
}
|
287
|
+
else
|
288
|
+
return 0;
|
289
|
+
}
|
290
|
+
|
291
|
+
/*****************
|
292
|
+
evma_get_sockname
|
293
|
+
*****************/
|
294
|
+
|
295
|
+
extern "C" int evma_get_sockname (const char *binding, struct sockaddr *sa)
|
296
|
+
{
|
297
|
+
if (!EventMachine)
|
298
|
+
throw std::runtime_error ("not initialized");
|
299
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
300
|
+
if (ed) {
|
301
|
+
return ed->GetSockname (sa) ? 1 : 0;
|
302
|
+
}
|
303
|
+
else
|
304
|
+
return 0;
|
305
|
+
}
|
306
|
+
|
307
|
+
/***********************
|
308
|
+
evma_get_subprocess_pid
|
309
|
+
***********************/
|
310
|
+
|
311
|
+
extern "C" int evma_get_subprocess_pid (const char *binding, pid_t *pid)
|
312
|
+
{
|
313
|
+
if (!EventMachine)
|
314
|
+
throw std::runtime_error ("not initialized");
|
315
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
316
|
+
if (ed) {
|
317
|
+
return ed->GetSubprocessPid (pid) ? 1 : 0;
|
318
|
+
}
|
319
|
+
else
|
320
|
+
return 0;
|
321
|
+
}
|
322
|
+
|
323
|
+
/**************************
|
324
|
+
evma_get_subprocess_status
|
325
|
+
**************************/
|
326
|
+
|
327
|
+
extern "C" int evma_get_subprocess_status (const char *binding, int *status)
|
328
|
+
{
|
329
|
+
if (!EventMachine)
|
330
|
+
throw std::runtime_error ("not initialized");
|
331
|
+
if (status) {
|
332
|
+
*status = EventMachine->SubprocessExitStatus;
|
333
|
+
return 1;
|
334
|
+
}
|
335
|
+
else
|
336
|
+
return 0;
|
337
|
+
}
|
338
|
+
|
339
|
+
|
340
|
+
/*********************
|
341
|
+
evma_signal_loopbreak
|
342
|
+
*********************/
|
343
|
+
|
344
|
+
extern "C" void evma_signal_loopbreak()
|
345
|
+
{
|
346
|
+
if (!EventMachine)
|
347
|
+
throw std::runtime_error ("not initialized");
|
348
|
+
EventMachine->SignalLoopBreaker();
|
349
|
+
}
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
/****************
|
354
|
+
evma__write_file
|
355
|
+
****************/
|
356
|
+
|
357
|
+
extern "C" const char *evma__write_file (const char *filename)
|
358
|
+
{
|
359
|
+
if (!EventMachine)
|
360
|
+
throw std::runtime_error ("not initialized");
|
361
|
+
return EventMachine->_OpenFileForWriting (filename);
|
362
|
+
}
|
363
|
+
|
364
|
+
|
365
|
+
/********************************
|
366
|
+
evma_get_comm_inactivity_timeout
|
367
|
+
********************************/
|
368
|
+
|
369
|
+
extern "C" int evma_get_comm_inactivity_timeout (const char *binding, int *value)
|
370
|
+
{
|
371
|
+
if (!EventMachine)
|
372
|
+
throw std::runtime_error ("not initialized");
|
373
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
374
|
+
if (ed) {
|
375
|
+
return ed->GetCommInactivityTimeout (value);
|
376
|
+
}
|
377
|
+
else
|
378
|
+
return 0; //Perhaps this should be an exception. Access to an unknown binding.
|
379
|
+
}
|
380
|
+
|
381
|
+
/********************************
|
382
|
+
evma_set_comm_inactivity_timeout
|
383
|
+
********************************/
|
384
|
+
|
385
|
+
extern "C" int evma_set_comm_inactivity_timeout (const char *binding, int *value)
|
386
|
+
{
|
387
|
+
if (!EventMachine)
|
388
|
+
throw std::runtime_error ("not initialized");
|
389
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
390
|
+
if (ed) {
|
391
|
+
return ed->SetCommInactivityTimeout (value);
|
392
|
+
}
|
393
|
+
else
|
394
|
+
return 0; //Perhaps this should be an exception. Access to an unknown binding.
|
395
|
+
}
|
396
|
+
|
397
|
+
|
398
|
+
/**********************
|
399
|
+
evma_set_timer_quantum
|
400
|
+
**********************/
|
401
|
+
|
402
|
+
extern "C" void evma_set_timer_quantum (int interval)
|
403
|
+
{
|
404
|
+
if (!EventMachine)
|
405
|
+
throw std::runtime_error ("not initialized");
|
406
|
+
EventMachine->SetTimerQuantum (interval);
|
407
|
+
}
|
408
|
+
|
409
|
+
/************************
|
410
|
+
evma_set_max_timer_count
|
411
|
+
************************/
|
412
|
+
|
413
|
+
extern "C" void evma_set_max_timer_count (int ct)
|
414
|
+
{
|
415
|
+
// This may only be called if the reactor is not running.
|
416
|
+
if (EventMachine)
|
417
|
+
throw std::runtime_error ("already initialized");
|
418
|
+
EventMachine_t::SetMaxTimerCount (ct);
|
419
|
+
}
|
420
|
+
|
421
|
+
/******************
|
422
|
+
evma_setuid_string
|
423
|
+
******************/
|
424
|
+
|
425
|
+
extern "C" void evma_setuid_string (const char *username)
|
426
|
+
{
|
427
|
+
// We do NOT need to be running an EM instance because this method is static.
|
428
|
+
EventMachine_t::SetuidString (username);
|
429
|
+
}
|
430
|
+
|
431
|
+
|
432
|
+
/**********
|
433
|
+
evma_popen
|
434
|
+
**********/
|
435
|
+
|
436
|
+
extern "C" const char *evma_popen (char * const*cmd_strings)
|
437
|
+
{
|
438
|
+
if (!EventMachine)
|
439
|
+
throw std::runtime_error ("not initialized");
|
440
|
+
return EventMachine->Socketpair (cmd_strings);
|
441
|
+
}
|
442
|
+
|
443
|
+
|
444
|
+
/***************************
|
445
|
+
evma_get_outbound_data_size
|
446
|
+
***************************/
|
447
|
+
|
448
|
+
extern "C" int evma_get_outbound_data_size (const char *binding)
|
449
|
+
{
|
450
|
+
if (!EventMachine)
|
451
|
+
throw std::runtime_error ("not initialized");
|
452
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
453
|
+
return ed ? ed->GetOutboundDataSize() : 0;
|
454
|
+
}
|
455
|
+
|
456
|
+
|
457
|
+
/***********
|
458
|
+
evma__epoll
|
459
|
+
***********/
|
460
|
+
|
461
|
+
extern "C" void evma__epoll()
|
462
|
+
{
|
463
|
+
bUseEpoll = 1;
|
464
|
+
}
|
465
|
+
|
466
|
+
/************
|
467
|
+
evma__kqueue
|
468
|
+
************/
|
469
|
+
|
470
|
+
extern "C" void evma__kqueue()
|
471
|
+
{
|
472
|
+
bUseKqueue = 1;
|
473
|
+
}
|
474
|
+
|
475
|
+
|
476
|
+
/**********************
|
477
|
+
evma_set_rlimit_nofile
|
478
|
+
**********************/
|
479
|
+
|
480
|
+
extern "C" int evma_set_rlimit_nofile (int nofiles)
|
481
|
+
{
|
482
|
+
return EventMachine_t::SetRlimitNofile (nofiles);
|
483
|
+
}
|
484
|
+
|
485
|
+
|
486
|
+
/*********************************
|
487
|
+
evma_send_file_data_to_connection
|
488
|
+
*********************************/
|
489
|
+
|
490
|
+
extern "C" int evma_send_file_data_to_connection (const char *binding, const char *filename)
|
491
|
+
{
|
492
|
+
/* This is a sugaring over send_data_to_connection that reads a file into a
|
493
|
+
* locally-allocated buffer, and sends the file data to the remote peer.
|
494
|
+
* Return the number of bytes written to the caller.
|
495
|
+
* TODO, needs to impose a limit on the file size. This is intended only for
|
496
|
+
* small files. (I don't know, maybe 8K or less.) For larger files, use interleaved
|
497
|
+
* I/O to avoid slowing the rest of the system down.
|
498
|
+
* TODO: we should return a code rather than barf, in case of file-not-found.
|
499
|
+
* TODO, does this compile on Windows?
|
500
|
+
* TODO, given that we want this to work only with small files, how about allocating
|
501
|
+
* the buffer on the stack rather than the heap?
|
502
|
+
*
|
503
|
+
* Modified 25Jul07. This now returns -1 on file-too-large; 0 for success, and a positive
|
504
|
+
* errno in case of other errors.
|
505
|
+
*
|
506
|
+
/* Contributed by Kirk Haines.
|
507
|
+
*/
|
508
|
+
|
509
|
+
char data[32*1024];
|
510
|
+
int r;
|
511
|
+
|
512
|
+
if (!EventMachine)
|
513
|
+
throw std::runtime_error("not initialized");
|
514
|
+
|
515
|
+
int Fd = open (filename, O_RDONLY);
|
516
|
+
|
517
|
+
if (Fd < 0)
|
518
|
+
return errno;
|
519
|
+
// From here on, all early returns MUST close Fd.
|
520
|
+
|
521
|
+
struct stat st;
|
522
|
+
if (fstat (Fd, &st)) {
|
523
|
+
int e = errno;
|
524
|
+
close (Fd);
|
525
|
+
return e;
|
526
|
+
}
|
527
|
+
|
528
|
+
int filesize = st.st_size;
|
529
|
+
if (filesize <= 0) {
|
530
|
+
close (Fd);
|
531
|
+
return 0;
|
532
|
+
}
|
533
|
+
else if (filesize > sizeof(data)) {
|
534
|
+
close (Fd);
|
535
|
+
return -1;
|
536
|
+
}
|
537
|
+
|
538
|
+
|
539
|
+
r = read (Fd, data, filesize);
|
540
|
+
if (r != filesize) {
|
541
|
+
int e = errno;
|
542
|
+
close (Fd);
|
543
|
+
return e;
|
544
|
+
}
|
545
|
+
evma_send_data_to_connection (binding, data, r);
|
546
|
+
close (Fd);
|
547
|
+
|
548
|
+
return 0;
|
549
|
+
}
|
550
|
+
|
551
|
+
|
552
|
+
|
553
|
+
|