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/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<Int64, Timer_t> Timers;
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
- Int64 NextHeartbeatTime;
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
@@ -113,6 +113,7 @@ extern "C" {
113
113
  void evma_set_epoll (int use);
114
114
  void evma_set_kqueue (int use);
115
115
 
116
+ uint64_t evma_get_current_loop_time();
116
117
  #if __cplusplus
117
118
  }
118
119
  #endif
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;
@@ -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
- LastIo = gCurrentLoopTime;
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
- LastIo = gCurrentLoopTime;
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 && ((gCurrentLoopTime - LastIo) >= InactivityTimeout))
269
+ if (InactivityTimeout && ((MyEventMachine->GetCurrentTime() - LastActivity) >= InactivityTimeout))
272
270
  ScheduleClose (false);
273
271
  //bCloseNow = true;
274
272
  }
@@ -96,6 +96,7 @@ typedef int socklen_t;
96
96
  typedef int pid_t;
97
97
  #endif
98
98
 
99
+ #include <stdint.h>
99
100
 
100
101
  using namespace std;
101
102
 
@@ -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
- if (len > 98)
756
- rb_raise (rb_eRuntimeError, "too many arguments to popen");
757
- char *strings [100];
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
- if (gCurrentLoopTime != 0) {
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(gCurrentLoopTime / 1000000), INT2NUM(gCurrentLoopTime % 1000000));
1012
+ return rb_funcall(cTime, at, 2, INT2NUM(current_time / 1000000), INT2NUM(current_time % 1000000));
1005
1013
  #else
1006
- return rb_time_new(gCurrentLoopTime / 1000000, gCurrentLoopTime % 1000000);
1014
+ return rb_time_new(current_time / 1000000, current_time % 1000000);
1007
1015
  #endif
1008
1016
  }
1009
1017
  return Qnil;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smparkes-eventmachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.10.2
4
+ version: 0.12.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis Cianfrocca