/** * Is this IO closed * * @return true if closed */ public boolean isClosed() { return (openFile.getMainStream() == null && openFile.getPipeStream() == null); }
/** * Is this IO closed * * @return true if closed */ public boolean isClosed() { return (openFile.getMainStream() == null && openFile.getPipeStream() == null); }
@JRubyMethod(name = "close_write") public IRubyObject close_write(ThreadContext context) { try { OpenFile myOpenFile = getOpenFileChecked(); if (myOpenFile.getPipeStream() == null && myOpenFile.isReadable()) { throw context.runtime.newIOError("closing non-duplex IO for writing"); } if (myOpenFile.getPipeStream() == null) { close(); } else{ myOpenFile.getPipeStream().fclose(); myOpenFile.setPipeStream(null); myOpenFile.setMode(myOpenFile.getMode() & ~OpenFile.WRITABLE); // TODO // n is result of fclose; but perhaps having a SysError below is enough? // if (n != 0) rb_sys_fail(fptr->path); } } catch (BadDescriptorException bde) { throw context.runtime.newErrnoEBADFError(); } catch (IOException ioe) { // hmmmm } return this; }
@JRubyMethod(name = "close_write") public IRubyObject close_write(ThreadContext context) { try { OpenFile myOpenFile = getOpenFileChecked(); if (myOpenFile.getPipeStream() == null && myOpenFile.isReadable()) { throw context.runtime.newIOError("closing non-duplex IO for writing"); } if (myOpenFile.getPipeStream() == null) { close(); } else{ myOpenFile.getPipeStream().fclose(); myOpenFile.setPipeStream(null); myOpenFile.setMode(myOpenFile.getMode() & ~OpenFile.WRITABLE); // TODO // n is result of fclose; but perhaps having a SysError below is enough? // if (n != 0) rb_sys_fail(fptr->path); } } catch (BadDescriptorException bde) { throw context.runtime.newErrnoEBADFError(); } catch (IOException ioe) { // hmmmm } return this; }
@JRubyMethod(name = "close_read") public IRubyObject close_read(ThreadContext context) { Ruby runtime = context.runtime; try { OpenFile myOpenFile = getOpenFileChecked(); if (myOpenFile.getPipeStream() == null && myOpenFile.isWritable()) { throw runtime.newIOError("closing non-duplex IO for reading"); } if (myOpenFile.getPipeStream() == null) { close(); } else{ myOpenFile.getMainStreamSafe().fclose(); myOpenFile.setMode(myOpenFile.getMode() & ~OpenFile.READABLE); myOpenFile.setMainStream(myOpenFile.getPipeStream()); myOpenFile.setPipeStream(null); // TODO // n is result of fclose; but perhaps having a SysError below is enough? // if (n != 0) rb_sys_fail(fptr->path); } } catch (BadDescriptorException bde) { throw runtime.newErrnoEBADFError(); } catch (IOException ioe) { // I believe Ruby bails out with a "bug" if closing fails throw runtime.newIOErrorFromException(ioe); } return this; }
@JRubyMethod(name = "close_read") public IRubyObject close_read(ThreadContext context) { Ruby runtime = context.runtime; try { OpenFile myOpenFile = getOpenFileChecked(); if (myOpenFile.getPipeStream() == null && myOpenFile.isWritable()) { throw runtime.newIOError("closing non-duplex IO for reading"); } if (myOpenFile.getPipeStream() == null) { close(); } else{ myOpenFile.getMainStreamSafe().fclose(); myOpenFile.setMode(myOpenFile.getMode() & ~OpenFile.READABLE); myOpenFile.setMainStream(myOpenFile.getPipeStream()); myOpenFile.setPipeStream(null); // TODO // n is result of fclose; but perhaps having a SysError below is enough? // if (n != 0) rb_sys_fail(fptr->path); } } catch (BadDescriptorException bde) { throw runtime.newErrnoEBADFError(); } catch (IOException ioe) { // I believe Ruby bails out with a "bug" if closing fails throw runtime.newIOErrorFromException(ioe); } return this; }
protected void initSocket(Ruby runtime, ChannelDescriptor descriptor) { // continue with normal initialization MakeOpenFile(); try { openFile.setMainStream(ChannelStream.fdopen(runtime, descriptor, newModeFlags(runtime, ModeFlags.RDONLY))); openFile.setPipeStream(ChannelStream.fdopen(runtime, descriptor, newModeFlags(runtime, ModeFlags.WRONLY))); openFile.getPipeStream().setSync(true); } catch (org.jruby.util.io.InvalidValueException ex) { throw runtime.newErrnoEINVALError(); } openFile.setMode(OpenFile.READWRITE | OpenFile.SYNC); // see rsock_init_sock in MRI; sockets are initialized to binary setAscii8bitBinmode(); }
protected void initSocket(Ruby runtime, ChannelDescriptor descriptor) { // continue with normal initialization MakeOpenFile(); try { openFile.setMainStream(ChannelStream.fdopen(runtime, descriptor, newModeFlags(runtime, ModeFlags.RDONLY))); openFile.setPipeStream(ChannelStream.fdopen(runtime, descriptor, newModeFlags(runtime, ModeFlags.WRONLY))); openFile.getPipeStream().setSync(true); } catch (org.jruby.util.io.InvalidValueException ex) { throw runtime.newErrnoEINVALError(); } openFile.setMode(OpenFile.READWRITE | OpenFile.SYNC); // see rsock_init_sock in MRI; sockets are initialized to binary setAscii8bitBinmode(); }
if(openFile.getPipeStream() != null) { openFile.setMainStream(openFile.getPipeStream()); openFile.setPipeStream(null);
if(openFile.getPipeStream() != null) { openFile.setMainStream(openFile.getPipeStream()); openFile.setPipeStream(null);
@Override @JRubyMethod public IRubyObject close_write(ThreadContext context) { Ruby runtime = context.runtime; if (!openFile.isWritable()) { return runtime.getNil(); } if (openFile.getPipeStream() == null && openFile.isReadable()) { throw runtime.newIOError("closing non-duplex IO for writing"); } if (!openFile.isReadable()) { close(); } else { // shutdown write try { shutdownInternal(context, 1); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } } return context.nil; }
if (openFile.getPipeStream() != null) { openFile.getPipeStream().fclose(); openFile.setPipeStream(null); if (openFile.getPipeStream() != null) {
@Override @JRubyMethod public IRubyObject close_write(ThreadContext context) { Ruby runtime = context.runtime; if (!openFile.isWritable()) { return runtime.getNil(); } if (openFile.getPipeStream() == null && openFile.isReadable()) { throw runtime.newIOError("closing non-duplex IO for writing"); } if (!openFile.isReadable()) { close(); } else { // shutdown write try { shutdownInternal(context, 1); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } } return context.nil; }
if (openFile.getPipeStream() != null) { openFile.getPipeStream().fclose(); openFile.setPipeStream(null); if (openFile.getPipeStream() != null) {
if (origFile.getPipeStream() != null) { origFile.getPipeStream().fflush(); } else if (origFile.isWritable()) { origStream.fflush(); selfStream.setModes(origStream.getModes()); } else { Stream pipeFile = selfFile.getPipeStream(); selfStream.fclose(); selfFile.setPipeStream(null); if (selfFile.getPipeStream() != null && selfDescriptor.getFileno() != selfFile.getPipeStream().getDescriptor().getFileno()) { int fd = selfFile.getPipeStream().getDescriptor().getFileno(); if (origFile.getPipeStream() == null) { selfFile.getPipeStream().fclose(); selfFile.setPipeStream(null); } else if (fd != origFile.getPipeStream().getDescriptor().getFileno()) { selfFile.getPipeStream().fclose(); ChannelDescriptor newFD2 = origFile.getPipeStream().getDescriptor().dup2(fd); selfFile.setPipeStream(ChannelStream.fdopen(runtime, newFD2, newIOOptions(runtime, "w").getModeFlags()));
if (origFile.getPipeStream() != null) { origFile.getPipeStream().fflush(); } else if (origFile.isWritable()) { origStream.fflush(); selfStream.setModes(origStream.getModes()); } else { Stream pipeFile = selfFile.getPipeStream(); selfStream.fclose(); selfFile.setPipeStream(null); if (selfFile.getPipeStream() != null && selfDescriptor.getFileno() != selfFile.getPipeStream().getDescriptor().getFileno()) { int fd = selfFile.getPipeStream().getDescriptor().getFileno(); if (origFile.getPipeStream() == null) { selfFile.getPipeStream().fclose(); selfFile.setPipeStream(null); } else if (fd != origFile.getPipeStream().getDescriptor().getFileno()) { selfFile.getPipeStream().fclose(); ChannelDescriptor newFD2 = origFile.getPipeStream().getDescriptor().dup2(fd); selfFile.setPipeStream(ChannelStream.fdopen(runtime, newFD2, newIOOptions(runtime, "w").getModeFlags()));
if (originalFile.getPipeStream() != null) { originalFile.getPipeStream().fflush(); originalFile.getMainStreamSafe().lseek(0, Stream.SEEK_CUR); } else if (originalFile.isWritable()) { if (newFile.isReadable()) { if (newFile.isWritable()) { if (newFile.getPipeStream() != null) { modes = newIOOptions(runtime, ModeFlags.RDONLY); } else {
if (originalFile.getPipeStream() != null) { originalFile.getPipeStream().fflush(); originalFile.getMainStreamSafe().lseek(0, Stream.SEEK_CUR); } else if (originalFile.isWritable()) { if (newFile.isReadable()) { if (newFile.isWritable()) { if (newFile.getPipeStream() != null) { modes = newIOOptions(runtime, ModeFlags.RDONLY); } else {