Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/ext/socket/RubyTCPServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.io.FilenoUtil;
import org.jruby.util.io.SelectorFactory;

import java.io.IOException;
Expand Down Expand Up @@ -251,7 +250,7 @@ public IRubyObject sysaccept(ThreadContext context) {

connected.finishConnect();

return asFixnum(context, FilenoUtil.filenoFrom(connected));
return asFixnum(context, newChannelFD(context.runtime, connected).bestFileno());
}
}

Expand Down
21 changes: 14 additions & 7 deletions core/src/main/java/org/jruby/ext/socket/RubyUNIXServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ public IRubyObject initialize(ThreadContext context, IRubyObject path) {

@JRubyMethod
public IRubyObject accept(ThreadContext context) {
UnixSocketChannel socketChannel = acceptChannel(context);

RubyUNIXSocket sock = (RubyUNIXSocket)(Helpers.invoke(context, Access.getClass(context, "UNIXSocket"), "allocate"));

sock.init_sock(context.runtime, socketChannel, "");

return sock;
}

private UnixSocketChannel acceptChannel(ThreadContext context) {
try {

while (true) { // select loop to allow interrupting
Expand All @@ -84,12 +94,10 @@ public IRubyObject accept(ThreadContext context) {

} else {
UnixSocketChannel socketChannel = asUnixServer().accept();
// null when another thread made the channel nonblocking and took the connection first
if (socketChannel == null) continue;

RubyUNIXSocket sock = (RubyUNIXSocket)(Helpers.invoke(context, Access.getClass(context, "UNIXSocket"), "allocate"));

sock.init_sock(context.runtime, socketChannel, "");

return sock;
return socketChannel;
}
}

Expand Down Expand Up @@ -154,8 +162,7 @@ public IRubyObject listen(ThreadContext context, IRubyObject log) {

@JRubyMethod
public IRubyObject sysaccept(ThreadContext context) {
RubyUNIXSocket socket = (RubyUNIXSocket) accept(context);
return asFixnum(context, ((UnixSocketChannel) socket.getChannel()).getFD());
return asFixnum(context, newChannelFD(context.runtime, acceptChannel(context)).bestFileno());
}

@JRubyMethod
Expand Down
4 changes: 0 additions & 4 deletions spec/tags/ruby/library/socket/tcpserver/sysaccept_tags.txt

This file was deleted.

Loading