smparkes-eventmachine 0.12.10.2 → 0.12.10.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/eventmachine.gemspec +1 -1
- data/ext/binder.cpp +0 -1
- data/ext/cmain.cpp +32 -8
- data/ext/ed.cpp +62 -98
- data/ext/ed.h +19 -27
- data/ext/em.cpp +224 -194
- data/ext/em.h +20 -11
- data/ext/eventmachine.h +1 -0
- data/ext/kb.cpp +1 -3
- data/ext/pipe.cpp +3 -5
- data/ext/project.h +1 -0
- data/ext/rubymain.cpp +14 -6
- metadata +1 -1
data/ext/em.h
CHANGED
@@ -57,15 +57,6 @@ See the file COPYING for complete licensing information.
|
|
57
57
|
#define EmSelect select
|
58
58
|
#endif
|
59
59
|
|
60
|
-
#ifdef OS_UNIX
|
61
|
-
typedef long long Int64;
|
62
|
-
#endif
|
63
|
-
#ifdef OS_WIN32
|
64
|
-
typedef __int64 Int64;
|
65
|
-
#endif
|
66
|
-
|
67
|
-
extern Int64 gCurrentLoopTime;
|
68
|
-
|
69
60
|
class EventableDescriptor;
|
70
61
|
class InotifyDescriptor;
|
71
62
|
|
@@ -136,6 +127,8 @@ class EventMachine_t
|
|
136
127
|
void _HandleKqueuePidEvent (struct kevent*);
|
137
128
|
#endif
|
138
129
|
|
130
|
+
uint64_t GetCurrentTime() { return MyCurrentLoopTime; }
|
131
|
+
|
139
132
|
// Temporary:
|
140
133
|
void _UseEpoll();
|
141
134
|
void _UseKqueue();
|
@@ -143,6 +136,11 @@ class EventMachine_t
|
|
143
136
|
bool UsingKqueue() { return bKqueue; }
|
144
137
|
bool UsingEpoll() { return bEpoll; }
|
145
138
|
|
139
|
+
void QueueHeartbeat(EventableDescriptor*);
|
140
|
+
void ClearHeartbeat(uint64_t);
|
141
|
+
|
142
|
+
uint64_t GetRealTime();
|
143
|
+
|
146
144
|
private:
|
147
145
|
bool _RunOnce();
|
148
146
|
bool _RunTimers();
|
@@ -150,12 +148,15 @@ class EventMachine_t
|
|
150
148
|
void _AddNewDescriptors();
|
151
149
|
void _ModifyDescriptors();
|
152
150
|
void _InitializeLoopBreaker();
|
151
|
+
void _CleanupSockets();
|
153
152
|
|
154
153
|
bool _RunSelectOnce();
|
155
154
|
bool _RunEpollOnce();
|
156
155
|
bool _RunKqueueOnce();
|
157
156
|
|
158
157
|
void _ModifyEpollEvent (EventableDescriptor*);
|
158
|
+
void _DispatchHeartbeats();
|
159
|
+
timeval _TimeTilNextEvent();
|
159
160
|
|
160
161
|
public:
|
161
162
|
void _ReadLoopBreaker();
|
@@ -172,14 +173,15 @@ class EventMachine_t
|
|
172
173
|
class Timer_t: public Bindable_t {
|
173
174
|
};
|
174
175
|
|
175
|
-
multimap<
|
176
|
+
multimap<uint64_t, Timer_t> Timers;
|
177
|
+
multimap<uint64_t, EventableDescriptor*> Heartbeats;
|
176
178
|
map<int, Bindable_t*> Files;
|
177
179
|
map<int, Bindable_t*> Pids;
|
178
180
|
vector<EventableDescriptor*> Descriptors;
|
179
181
|
vector<EventableDescriptor*> NewDescriptors;
|
180
182
|
set<EventableDescriptor*> ModifiedDescriptors;
|
181
183
|
|
182
|
-
|
184
|
+
uint64_t NextHeartbeatTime;
|
183
185
|
|
184
186
|
int LoopBreakerReader;
|
185
187
|
int LoopBreakerWriter;
|
@@ -189,6 +191,13 @@ class EventMachine_t
|
|
189
191
|
|
190
192
|
timeval Quantum;
|
191
193
|
|
194
|
+
uint64_t MyCurrentLoopTime;
|
195
|
+
|
196
|
+
#ifdef OS_WIN32
|
197
|
+
unsigned TickCountTickover;
|
198
|
+
unsigned LastTickCount;
|
199
|
+
#endif
|
200
|
+
|
192
201
|
private:
|
193
202
|
bool bEpoll;
|
194
203
|
int epfd; // Epoll file-descriptor
|
data/ext/eventmachine.h
CHANGED
data/ext/kb.cpp
CHANGED
@@ -26,9 +26,7 @@ KeyboardDescriptor::KeyboardDescriptor
|
|
26
26
|
|
27
27
|
KeyboardDescriptor::KeyboardDescriptor (EventMachine_t *parent_em):
|
28
28
|
EventableDescriptor (0, parent_em),
|
29
|
-
bReadAttemptedAfterClose (false)
|
30
|
-
LastIo (gCurrentLoopTime),
|
31
|
-
InactivityTimeout (0)
|
29
|
+
bReadAttemptedAfterClose (false)
|
32
30
|
{
|
33
31
|
#ifdef HAVE_EPOLL
|
34
32
|
EpollEvent.events = EPOLLIN;
|
data/ext/pipe.cpp
CHANGED
@@ -30,8 +30,6 @@ PipeDescriptor::PipeDescriptor
|
|
30
30
|
PipeDescriptor::PipeDescriptor (int fd, pid_t subpid, EventMachine_t *parent_em):
|
31
31
|
EventableDescriptor (fd, parent_em),
|
32
32
|
bReadAttemptedAfterClose (false),
|
33
|
-
LastIo (gCurrentLoopTime),
|
34
|
-
InactivityTimeout (0),
|
35
33
|
OutboundDataSize (0),
|
36
34
|
SubprocessPid (subpid)
|
37
35
|
{
|
@@ -143,7 +141,7 @@ void PipeDescriptor::Read()
|
|
143
141
|
return;
|
144
142
|
}
|
145
143
|
|
146
|
-
|
144
|
+
LastActivity = MyEventMachine->GetCurrentTime();
|
147
145
|
|
148
146
|
int total_bytes_read = 0;
|
149
147
|
char readbuffer [16 * 1024];
|
@@ -203,7 +201,7 @@ void PipeDescriptor::Write()
|
|
203
201
|
int sd = GetSocket();
|
204
202
|
assert (sd != INVALID_SOCKET);
|
205
203
|
|
206
|
-
|
204
|
+
LastActivity = MyEventMachine->GetCurrentTime();
|
207
205
|
char output_buffer [16 * 1024];
|
208
206
|
size_t nbytes = 0;
|
209
207
|
|
@@ -268,7 +266,7 @@ PipeDescriptor::Heartbeat
|
|
268
266
|
void PipeDescriptor::Heartbeat()
|
269
267
|
{
|
270
268
|
// If an inactivity timeout is defined, then check for it.
|
271
|
-
if (InactivityTimeout && ((
|
269
|
+
if (InactivityTimeout && ((MyEventMachine->GetCurrentTime() - LastActivity) >= InactivityTimeout))
|
272
270
|
ScheduleClose (false);
|
273
271
|
//bCloseNow = true;
|
274
272
|
}
|
data/ext/project.h
CHANGED
data/ext/rubymain.cpp
CHANGED
@@ -494,6 +494,7 @@ static VALUE t_connect_server (VALUE self, VALUE server, VALUE port)
|
|
494
494
|
} catch (std::runtime_error e) {
|
495
495
|
rb_raise (EM_eConnectionError, e.what());
|
496
496
|
}
|
497
|
+
return Qnil;
|
497
498
|
}
|
498
499
|
|
499
500
|
/*********************
|
@@ -514,6 +515,7 @@ static VALUE t_bind_connect_server (VALUE self, VALUE bind_addr, VALUE bind_port
|
|
514
515
|
} catch (std::runtime_error e) {
|
515
516
|
rb_raise (EM_eConnectionError, e.what());
|
516
517
|
}
|
518
|
+
return Qnil;
|
517
519
|
}
|
518
520
|
|
519
521
|
/*********************
|
@@ -752,9 +754,11 @@ static VALUE t_invoke_popen (VALUE self, VALUE cmd)
|
|
752
754
|
#else
|
753
755
|
int len = RARRAY (cmd)->len;
|
754
756
|
#endif
|
755
|
-
|
756
|
-
|
757
|
-
|
757
|
+
char** strings = new char*[len+2];
|
758
|
+
if(!strings) {
|
759
|
+
rb_raise (rb_eRuntimeError, "%s", "no popen: no memory");
|
760
|
+
return ULONG2NUM (0);
|
761
|
+
}
|
758
762
|
for (int i=0; i < len; i++) {
|
759
763
|
VALUE ix = INT2FIX (i);
|
760
764
|
VALUE s = rb_ary_aref (1, &ix, cmd);
|
@@ -770,6 +774,7 @@ static VALUE t_invoke_popen (VALUE self, VALUE cmd)
|
|
770
774
|
snprintf (buf, sizeof(buf)-1, "no popen: %s", (err?err:"???"));
|
771
775
|
rb_raise (rb_eRuntimeError, "%s", buf);
|
772
776
|
}
|
777
|
+
delete [] strings;
|
773
778
|
return ULONG2NUM (f);
|
774
779
|
}
|
775
780
|
|
@@ -798,6 +803,7 @@ static VALUE t_watch_filename (VALUE self, VALUE fname)
|
|
798
803
|
} catch (std::runtime_error e) {
|
799
804
|
rb_raise (EM_eUnsupported, e.what());
|
800
805
|
}
|
806
|
+
return Qnil;
|
801
807
|
}
|
802
808
|
|
803
809
|
|
@@ -823,6 +829,7 @@ static VALUE t_watch_pid (VALUE self, VALUE pid)
|
|
823
829
|
} catch (std::runtime_error e) {
|
824
830
|
rb_raise (EM_eUnsupported, e.what());
|
825
831
|
}
|
832
|
+
return Qnil;
|
826
833
|
}
|
827
834
|
|
828
835
|
|
@@ -999,11 +1006,12 @@ static VALUE t_get_loop_time (VALUE self)
|
|
999
1006
|
static ID at = rb_intern("at");
|
1000
1007
|
#endif
|
1001
1008
|
|
1002
|
-
|
1009
|
+
uint64_t current_time = evma_get_current_loop_time();
|
1010
|
+
if (current_time != 0) {
|
1003
1011
|
#ifndef HAVE_RB_TIME_NEW
|
1004
|
-
return rb_funcall(cTime, at, 2, INT2NUM(
|
1012
|
+
return rb_funcall(cTime, at, 2, INT2NUM(current_time / 1000000), INT2NUM(current_time % 1000000));
|
1005
1013
|
#else
|
1006
|
-
return rb_time_new(
|
1014
|
+
return rb_time_new(current_time / 1000000, current_time % 1000000);
|
1007
1015
|
#endif
|
1008
1016
|
}
|
1009
1017
|
return Qnil;
|