| Methods from org.jruby.RubyIO: |
|---|
|
addBlockingThread, binmode, checkClosed, checkInitialized, close, close2, close_read, close_write, closed_p, copy_stream, createIOClass, ctl, each_byte, each_line, eof_p, fcntl, fdopen, fileno, flush, foreach, fsync, fwrite, getBlocking, getChannel, getDescriptorByFileno, getHandler, getIOModes, getIOModesIntFromString, getInStream, getNewFileno, getOpenFile, getOpenFileChecked, getOutStream, getc, getline, getlineFast, gets, initialize, initialize_copy, interruptBlockingThreads, ioctl, lineno, lineno_set, newIO, newInstance, op_append, open, pid, pipe, popen, pos, pos_set, print, printf, putc, puts, read, read, read, read, read, read, read, read, readAll, read_nonblock, readchar, readline, readlines, readlines, readpartial, registerDescriptor, removeBlockingThread, reopen, rewind, seek, seek, seek, select, select_static, stat, swallow, sync, sync_set, sysread, sysseek, syswrite, toString, to_io, tty_p, ungetc, unregisterDescriptor, waitReadable, waitWritable, write, write, writeDataBuffered, write_nonblock |
| Method from org.jruby.ext.socket.RubyTCPServer Detail: |
public IRubyObject accept() {
RubyTCPSocket socket = new RubyTCPSocket(getRuntime(),getRuntime().fastGetClass("TCPSocket"));
ThreadContext context = getRuntime().getCurrentContext();
boolean oldBlocking = ssc.isBlocking();
try {
ssc.configureBlocking(false);
while (true) {
boolean ready = context.getThread().selectForAccept(this);
if (!ready) {
// we were woken up without being selected...poll for thread events and go back to sleep
getRuntime().getCurrentContext().pollThreadEvents();
} else {
try {
SocketChannel connected = ssc.accept();
connected.finishConnect();
// otherwise one key has been selected (ours) so we get the channel and hand it off
socket.initSocket(new ChannelDescriptor(connected, RubyIO.getNewFileno(), new ModeFlags(ModeFlags.RDWR), new FileDescriptor()));
} catch (InvalidValueException ex) {
throw getRuntime().newErrnoEINVALError();
}
return socket;
}
}
} catch(IOException e) {
throw sockerr(this, "problem when accepting");
} finally {
try { ssc.configureBlocking(oldBlocking); } catch (IOException ioe) {}
}
}
|
public IRubyObject accept_nonblock() {
RubyTCPSocket socket = new RubyTCPSocket(getRuntime(),getRuntime().fastGetClass("TCPSocket"));
Selector selector = null;
try {
ssc.configureBlocking(false);
selector = Selector.open();
SelectionKey key = ssc.register(selector, SelectionKey.OP_ACCEPT);
int selected = selector.selectNow();
if (selected == 0) {
// no connection immediately accepted, let them try again
throw getRuntime().newErrnoEAGAINError("Resource temporarily unavailable");
} else {
try {
// otherwise one key has been selected (ours) so we get the channel and hand it off
socket.initSocket(new ChannelDescriptor(ssc.accept(), RubyIO.getNewFileno(), new ModeFlags(ModeFlags.RDWR), new FileDescriptor()));
} catch (InvalidValueException ex) {
throw getRuntime().newErrnoEINVALError();
}
return socket;
}
} catch(IOException e) {
throw sockerr(this, "problem when accepting");
} finally {
try {
if (selector != null) selector.close();
} catch (IOException ioe) {
}
}
}
|
static void createTCPServer(Ruby runtime) {
RubyClass rb_cTCPServer = runtime.defineClass("TCPServer", runtime.fastGetClass("TCPSocket"), TCPSERVER_ALLOCATOR);
rb_cTCPServer.defineAnnotatedMethods(RubyTCPServer.class);
runtime.getObject().fastSetConstant("TCPserver",rb_cTCPServer);
}
|
public IRubyObject getpeername(IRubyObject[] args) {
throw getRuntime().newNotImplementedError("not supported");
}
|
public IRubyObject initialize(IRubyObject[] args) {
IRubyObject hostname = args[0];
IRubyObject port = args.length > 1 ? args[1] : getRuntime().getNil();
if(hostname.isNil()) {
hostname = getRuntime().newString("0.0.0.0");
} else if (hostname instanceof RubyFixnum) {
// numeric host, use it for port
port = hostname;
hostname = getRuntime().newString("0.0.0.0");
}
String shost = hostname.convertToString().toString();
try {
InetAddress addr = InetAddress.getByName(shost);
ssc = ServerSocketChannel.open();
int portInt;
if (port instanceof RubyInteger) {
portInt = RubyNumeric.fix2int(port);
} else {
IRubyObject portString = port.convertToString();
IRubyObject portInteger = portString.convertToInteger(MethodIndex.TO_I, "to_i");
portInt = RubyNumeric.fix2int(portInteger);
if (portInt < = 0) {
portInt = RubyNumeric.fix2int(RubySocket.getservbyname(getRuntime().getObject(), new IRubyObject[] {portString}));
}
}
socket_address = new InetSocketAddress(addr, portInt);
ssc.socket().bind(socket_address);
initSocket(new ChannelDescriptor(ssc, RubyIO.getNewFileno(), new ModeFlags(ModeFlags.RDWR), new FileDescriptor()));
} catch (InvalidValueException ex) {
throw getRuntime().newErrnoEINVALError();
} catch(UnknownHostException e) {
throw sockerr(this, "initialize: name or service not known");
} catch(BindException e) {
// e.printStackTrace();
throw getRuntime().newErrnoEADDRINUSEError();
} catch(IOException e) {
throw sockerr(this, "initialize: name or service not known");
}
return this;
}
|
public IRubyObject listen(IRubyObject backlog) {
return RubyFixnum.zero(getRuntime());
}
|
public static IRubyObject open(IRubyObject recv,
IRubyObject[] args,
Block block) {
ThreadContext context = recv.getRuntime().getCurrentContext();
IRubyObject tcpServer = recv.callMethod(context, "new", args);
if (!block.isGiven()) return tcpServer;
try {
return block.yield(context, tcpServer);
} finally {
tcpServer.callMethod(context, "close");
}
}
|
public IRubyObject peeraddr(IRubyObject[] args) {
throw getRuntime().newNotImplementedError("not supported");
}
|