Permalink
Browse files

Implement EM::Connection#get_sockname() for the JRuby EM port.

  • Loading branch information...
1 parent 76aa7e9 commit f0e4aa98ee2d3b8904ef7d83dbde73cb5b2ec58f @neilconway neilconway committed May 16, 2012
@@ -524,6 +524,10 @@ public void setTimerQuantum (int mills) {
return Connections.get(sig).getPeerName();
}
+ public Object[] getSockName (long sig) {
+ return Connections.get(sig).getSockName();
+ }
+
public long attachChannel (SocketChannel sc, boolean watch_mode) {
long b = createBinding();
@@ -60,6 +60,7 @@
public void setCommInactivityTimeout (long seconds);
public Object[] getPeerName();
+ public Object[] getSockName();
public boolean isWatchOnly();
@@ -183,6 +183,12 @@ public void setCommInactivityTimeout (long seconds) {
}
}
+ public Object[] getSockName () {
+ DatagramSocket socket = channel.socket();
+ return new Object[]{ socket.getLocalPort(),
+ socket.getLocalAddress().getHostAddress() };
+ }
+
public boolean isWatchOnly() { return false; }
public boolean isNotifyReadable() { return false; }
public boolean isNotifyWritable() { return false; }
@@ -302,6 +302,12 @@ public void setCommInactivityTimeout (long seconds) {
return new Object[]{ sock.getPort(), sock.getInetAddress().getHostAddress() };
}
+ public Object[] getSockName () {
+ Socket sock = channel.socket();
+ return new Object[]{ sock.getLocalPort(),
+ sock.getLocalAddress().getHostAddress() };
+ }
+
public void setWatchOnly() {
bWatchOnly = true;
updateEvents();
View
@@ -203,6 +203,11 @@ def self.get_peername sig
Socket.pack_sockaddr_in(*peer)
end
end
+ def self.get_sockname sig
+ if sockName = @em.getSockName(sig)
+ Socket.pack_sockaddr_in(*sockName)
+ end
+ end
# @private
def self.attach_fd fileno, watch_mode
# 3Aug09: We could pass in the actual SocketChannel, but then it would be modified (set as non-blocking), and

0 comments on commit f0e4aa9

Please sign in to comment.