Skip to content

Commit

Permalink
Add support for get_peername to jruby reactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Jun 16, 2009
1 parent 17ed668 commit d12f6e5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions java/src/com/rubyeventmachine/EmReactor.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,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();
}
}
2 changes: 2 additions & 0 deletions java/src/com/rubyeventmachine/EventableChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ public interface EventableChannel {
public boolean writeOutboundData();

public void setCommInactivityTimeout (long seconds);

public Object[] getPeerName();
}
9 changes: 9 additions & 0 deletions java/src/com/rubyeventmachine/EventableDatagramChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
6 changes: 6 additions & 0 deletions java/src/com/rubyeventmachine/EventableSocketChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -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() };
}
}
6 changes: 6 additions & 0 deletions lib/jeventmachine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

require 'java'
require 'em_reactor'
require 'socket'

module EventMachine
# TODO: These event numbers are defined in way too many places.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d12f6e5

Please sign in to comment.