Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of git://github.com/eventmachine/eventmachine

  • Loading branch information...
commit 84fb03e1b5f8b45a5470583c56302ed36fc296ea 2 parents 0e1e763 + 9d473be
@coderrr authored
View
12 Rakefile
@@ -256,6 +256,18 @@ namespace :java do
end
end
+namespace :osx do
+ desc "Build OSX binary gem"
+ task :gem do
+ Spec.platform = RUBY_PLATFORM.sub(/darwin.+$/, 'darwin')
+ Spec.files += %w[ lib/rubyeventmachine.bundle lib/fastfilereaderext.bundle ]
+ Spec.extensions = nil
+
+ Rake::Task['build'].invoke
+ Rake::Task['gem'].invoke
+ end
+end
+
task :gemspec => :clobber do
open("eventmachine.gemspec", 'w') { |f| f.write Spec.to_ruby }
end
View
7 ext/ed.cpp
@@ -33,9 +33,16 @@ bool SetSocketNonblocking (SOCKET sd)
#endif
#ifdef OS_WIN32
+ #ifdef BUILD_FOR_RUBY
+ // 14Jun09 Ruby provides its own wrappers for ioctlsocket. On 1.8 this is a simple wrapper,
+ // however, 1.9 keeps its own state about the socket.
+ // NOTE: F_GETFL is not supported
+ return (fcntl (sd, F_SETFL, O_NONBLOCK) == 0) ? true : false;
+ #else
unsigned long one = 1;
return (ioctlsocket (sd, FIONBIO, &one) == 0) ? true : false;
#endif
+ #endif
}
View
9 ext/em.h
@@ -37,8 +37,13 @@ See the file COPYING for complete licensing information.
#ifdef HAVE_RBTRAP
#include <rubysig.h>
#else
- #define TRAP_BEG
- #define TRAP_END
+ extern "C" {
+ void rb_enable_interrupt(void);
+ void rb_disable_interrupt(void);
+ }
+
+ #define TRAP_BEG rb_enable_interrupt()
+ #define TRAP_END do { rb_disable_interrupt(); rb_thread_check_ints(); } while(0)
#endif
// 1.9.0 compat
View
17 ext/rubymain.cpp
@@ -34,6 +34,7 @@ static VALUE EmConnection;
static VALUE EM_eUnknownTimerFired;
static VALUE EM_eConnectionNotBound;
+static VALUE EM_eUnsupported;
static VALUE Intern_at_signature;
static VALUE Intern_at_timers;
@@ -723,7 +724,7 @@ t__epoll
static VALUE t__epoll (VALUE self)
{
if (t__epoll_p(self) == Qfalse)
- return Qfalse;
+ rb_raise (EM_eUnsupported, "epoll is not supported on this platform");
evma_set_epoll (1);
return Qtrue;
@@ -736,7 +737,7 @@ t__epoll_set
static VALUE t__epoll_set (VALUE self, VALUE val)
{
if (t__epoll_p(self) == Qfalse)
- return Qfalse;
+ rb_raise (EM_eUnsupported, "epoll is not supported on this platform");
evma_set_epoll (val == Qtrue ? 1 : 0);
return val;
@@ -763,7 +764,7 @@ t__kqueue
static VALUE t__kqueue (VALUE self)
{
if (t__kqueue_p(self) == Qfalse)
- return Qfalse;
+ rb_raise (EM_eUnsupported, "kqueue is not supported on this platform");
evma_set_kqueue (1);
return Qtrue;
@@ -776,7 +777,7 @@ t__kqueue_set
static VALUE t__kqueue_set (VALUE self, VALUE val)
{
if (t__kqueue_p(self) == Qfalse)
- return Qfalse;
+ rb_raise (EM_eUnsupported, "kqueue is not supported on this platform");
evma_set_kqueue (val == Qtrue ? 1 : 0);
return val;
@@ -866,13 +867,8 @@ t_get_loop_time
static VALUE t_get_loop_time (VALUE self)
{
- VALUE cTime = rb_path2class("Time");
if (gCurrentLoopTime != 0) {
- return rb_funcall(cTime,
- rb_intern("at"),
- 2,
- INT2NUM(gCurrentLoopTime / 1000000),
- INT2NUM(gCurrentLoopTime % 1000000));
+ return rb_time_new(gCurrentLoopTime / 1000000, gCurrentLoopTime % 1000000);
}
return Qnil;
}
@@ -959,6 +955,7 @@ extern "C" void Init_rubyeventmachine()
rb_define_class_under (EmModule, "NoHandlerForAcceptedConnection", rb_eException);
EM_eConnectionNotBound = rb_define_class_under (EmModule, "ConnectionNotBound", rb_eRuntimeError);
EM_eUnknownTimerFired = rb_define_class_under (EmModule, "UnknownTimerFired", rb_eRuntimeError);
+ EM_eUnsupported = rb_define_class_under (EmModule, "Unsupported", rb_eRuntimeError);
rb_define_module_function (EmModule, "initialize_event_machine", (VALUE(*)(...))t_initialize_event_machine, 0);
rb_define_module_function (EmModule, "run_machine", (VALUE(*)(...))t_run_machine_without_threads, 0);
View
34 java/src/com/rubyeventmachine/EmReactor.java
@@ -47,7 +47,7 @@
public final int EM_LOOPBREAK_SIGNAL = 105;
private Selector mySelector;
- private TreeMap<Long, String> Timers;
+ private TreeMap<Long, LinkedList<String>> Timers;
private TreeMap<String, EventableChannel> Connections;
private TreeMap<String, ServerSocketChannel> Acceptors;
@@ -59,7 +59,7 @@
private int timerQuantum;
public EmReactor() {
- Timers = new TreeMap<Long, String>();
+ Timers = new TreeMap<Long, LinkedList<String>>();
Connections = new TreeMap<String, EventableChannel>();
Acceptors = new TreeMap<String, ServerSocketChannel>();
@@ -235,18 +235,34 @@ void runTimers() {
//System.out.println (k - now);
if (k > now)
break;
- String s = Timers.remove(k);
- eventCallback ("", EM_TIMER_FIRED, ByteBuffer.wrap(s.getBytes()));
+
+ LinkedList<String> callbacks = Timers.get(k);
+ Timers.remove(k);
+
+ // Fire all timers at this timestamp
+ ListIterator<String> iter = callbacks.listIterator(0);
+ while (iter.hasNext()) {
+ eventCallback ("", EM_TIMER_FIRED, ByteBuffer.wrap(iter.next().getBytes()));
+ }
}
}
-
+
public String installOneshotTimer (int milliseconds) {
BindingIndex++;
String s = createBinding();
- Timers.put(new Date().getTime() + milliseconds, s);
+ long deadline = new Date().getTime() + milliseconds;
+
+ if (Timers.containsKey(deadline)) {
+ Timers.get(deadline).add(s);
+ } else {
+ LinkedList<String> callbacks = new LinkedList<String>();
+ callbacks.add(s);
+ Timers.put(deadline, callbacks);
+ }
+
return s;
}
-
+
public String startTcpServer (SocketAddress sa) throws EmReactorException {
try {
ServerSocketChannel server = ServerSocketChannel.open();
@@ -420,4 +436,8 @@ public void setTimerQuantum (int mills) {
throw new RuntimeException ("attempt to set invalid timer-quantum value: "+mills);
timerQuantum = mills;
}
+
+ public Object[] getPeerName (String sig) {
+ return Connections.get(sig).getPeerName();
+ }
}
View
2  java/src/com/rubyeventmachine/EventableChannel.java
@@ -54,4 +54,6 @@
public boolean writeOutboundData();
public void setCommInactivityTimeout (long seconds);
+
+ public Object[] getPeerName();
}
View
9 java/src/com/rubyeventmachine/EventableDatagramChannel.java
@@ -168,4 +168,13 @@ public void setCommInactivityTimeout (long seconds) {
// TODO
System.out.println ("DATAGRAM: SET COMM INACTIVITY UNIMPLEMENTED " + seconds);
}
+
+ public Object[] getPeerName () {
+ if (returnAddress != null) {
+ InetSocketAddress inetAddr = (InetSocketAddress) returnAddress;
+ return new Object[]{ inetAddr.getPort(), inetAddr.getHostName() };
+ } else {
+ return null;
+ }
+ }
}
View
6 java/src/com/rubyeventmachine/EventableSocketChannel.java
@@ -40,6 +40,7 @@
import java.nio.*;
import java.util.*;
import java.io.*;
+import java.net.Socket;
import javax.net.ssl.*;
import javax.net.ssl.SSLEngineResult.*;
@@ -241,4 +242,9 @@ public void setCommInactivityTimeout (long seconds) {
// TODO
System.out.println ("SOCKET: SET COMM INACTIVITY UNIMPLEMENTED " + seconds);
}
+
+ public Object[] getPeerName () {
+ Socket sock = channel.socket();
+ return new Object[]{ sock.getPort(), sock.getInetAddress().getHostAddress() };
+ }
}
View
6 lib/eventmachine.rb
@@ -246,7 +246,11 @@ def self.run blk=nil, tail=nil, &block
ensure
if @threadpool
@threadpool.each { |t| t.exit }
- @threadpool.each { |t| t.kill! if t.alive? }
+ @threadpool.each do |t|
+ next unless t.alive?
+ # ruby 1.9 has no kill!
+ t.respond_to?(:kill!) ? t.kill! : t.kill
+ end
@threadqueue = nil
@resultqueue = nil
end
View
6 lib/jeventmachine.rb
@@ -29,6 +29,7 @@
require 'java'
require 'em_reactor'
+require 'socket'
module EventMachine
# TODO: These event numbers are defined in way too many places.
@@ -132,6 +133,11 @@ def self.set_max_timer_count num
def self.library_type
:java
end
+ def self.get_peername sig
+ if peer = @em.getPeerName(sig)
+ Socket.pack_sockaddr_in *peer
+ end
+ end
class Connection
def associate_callback_target sig
View
2  tests/test_epoll.rb
@@ -94,7 +94,6 @@ def test_defer
n = 0
work_proc = proc {n += 1}
callback_proc = proc {EM.stop}
- EM.epoll
EM.run {
EM.defer work_proc, callback_proc
}
@@ -120,7 +119,6 @@ def receive_data dgm
def test_datagrams
$in = $out = ""
- EM.epoll
EM.run {
EM.open_datagram_socket "127.0.0.1", 9500, TestDatagramServer
EM.open_datagram_socket "127.0.0.1", 0, TestDatagramClient
View
2  tests/test_next_tick.rb
@@ -33,7 +33,6 @@ class TestNextTick < Test::Unit::TestCase
def test_tick_arg
pr = proc {EM.stop}
- EM.epoll
EM.run {
EM.next_tick pr
}
@@ -41,7 +40,6 @@ def test_tick_arg
end
def test_tick_block
- EM.epoll
EM.run {
EM.next_tick {EM.stop}
}
Please sign in to comment.
Something went wrong with that request. Please try again.