Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 30f875df1c0a
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 246a9cc616e3
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Oct 13, 2015

  1. Copy the full SHA
    e7f45e0 View commit details
  2. Copy the full SHA
    246a9cc View commit details
Showing with 32 additions and 29 deletions.
  1. +15 −1 kernel/common/io.rb
  2. +17 −28 vm/capi/io.cpp
16 changes: 15 additions & 1 deletion kernel/common/io.rb
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ def self.choose_type(fd)
when "fifo", "characterSpecial"
FIFOFileDescriptor.new(fd, stat)
when "socket"
raise "cannot make socket yet"
SocketFileDescriptor.new(fd, stat)
when "directory"
DirectoryFileDescriptor.new(fd, stat)
when "blockSpecial"
@@ -709,6 +709,20 @@ def sysseek(offset, whence=SEEK_SET)
class DirectoryFileDescriptor < FileDescriptor
end # class DirectoryFileDescriptor

class SocketFileDescriptor < FIFOFileDescriptor
def initialize(fd, stat)
super

@mode &= O_ACCMODE
@sync = true
end

def force_read_write
@mode &= ~(O_RDONLY | O_WRONLY)
@mode |= O_RDWR
end
end # class SocketFileDescriptor

# Encapsulates all of the logic necessary for handling #select.
class Select
#eval(Rubinius::Config['rbx.platform.timeval.class'])
45 changes: 17 additions & 28 deletions vm/capi/io.cpp
Original file line number Diff line number Diff line change
@@ -67,7 +67,6 @@ namespace rubinius {

if(type_ != cRIO) {
native_int fd = -1;
//int fd = (int)io_obj->descriptor()->to_native();
VALUE fileno = rb_funcall(jobj, id_descriptor, 0);
Fixnum* tmp_fd = try_as<Fixnum>(env->get_object(fileno));

@@ -83,7 +82,6 @@ namespace rubinius {
rb_raise(rb_eIOError, "%s (%d)", err, errno);
}

//FILE* f = fdopen(fd, flags_modestr(io_obj->mode()->to_native()));
FILE* f = fdopen(fd, flags_modestr(try_as<Fixnum>(env->get_object(rb_funcall(jobj, id_mode, 0)))->to_native()));

if(!f) {
@@ -177,9 +175,7 @@ extern "C" {
int rb_io_fd(VALUE io_handle) {
NativeMethodEnvironment* env = NativeMethodEnvironment::get();

//IO* io = c_as<IO>(env->get_object(io_handle));
//return io->descriptor()->to_native();
return c_as<Fixnum>(env->get_object(rb_funcall(io_handle, rb_intern("fileno"), 0)))->to_native();
return c_as<Fixnum>(env->get_object(rb_funcall(io_handle, rb_intern("fileno"), 0)))->to_native();
}

long rb_io_fread(char* ptr, int len, FILE* f) {
@@ -364,11 +360,8 @@ extern "C" {

void rb_io_set_nonblock(rb_io_t* iot) {
VALUE io_handle = iot->handle;
//NativeMethodEnvironment* env = NativeMethodEnvironment::get();
VALUE fd_ivar = rb_ivar_get(io_handle, rb_intern("fd"));

//IO* io = c_as<IO>(env->get_object(io_handle));
//io->set_nonblock(env->state());
rb_funcall(fd_ivar, rb_intern("set_nonblock"), 0);
}

@@ -384,20 +377,16 @@ extern "C" {
void rb_io_check_closed(rb_io_t* iot) {
VALUE io_handle = iot->handle;
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
//IO* io = c_as<IO>(env->get_object(io_handle));

//if(io->descriptor()->to_native() == -1) {
if(c_as<Fixnum>(env->get_object(rb_funcall(io_handle, rb_intern("fileno"), 0)))->to_native() == -1) {
if(c_as<Fixnum>(env->get_object(rb_funcall(io_handle, rb_intern("fileno"), 0)))->to_native() == -1) {
rb_raise(rb_eIOError, "closed stream");
}
}

void rb_io_check_readable(rb_io_t* iot) {
VALUE io_handle = iot->handle;
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
//IO* io = c_as<IO>(env->get_object(io_handle));
//int io_mode = io->mode()->to_native() & O_ACCMODE;
int io_mode = c_as<Fixnum>(env->get_object(rb_funcall(io_handle, rb_intern("mode"), 0)))->to_native() & O_ACCMODE;
int io_mode = c_as<Fixnum>(env->get_object(rb_funcall(io_handle, rb_intern("mode"), 0)))->to_native() & O_ACCMODE;
if(!(O_RDONLY == io_mode || O_RDWR == io_mode)) {
rb_raise(rb_eIOError, "not opened for reading");
}
@@ -406,42 +395,42 @@ extern "C" {
void rb_io_check_writable(rb_io_t* iot) {
VALUE io_handle = iot->handle;
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
//IO* io = c_as<IO>(env->get_object(io_handle));
//int io_mode = io->mode()->to_native() & O_ACCMODE;
int io_mode = c_as<Fixnum>(env->get_object(rb_funcall(io_handle, rb_intern("mode"), 0)))->to_native() & O_ACCMODE;
int io_mode = c_as<Fixnum>(env->get_object(rb_funcall(io_handle, rb_intern("mode"), 0)))->to_native() & O_ACCMODE;
if(!(O_WRONLY == io_mode || O_RDWR == io_mode)) {
rb_raise(rb_eIOError, "not opened for writing");
}
}

void rb_update_max_fd(int fd) {
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
//IO::update_max_fd(env->state(), fd);
VALUE fd_class = rb_path2class("IO::FileDescriptor");
State *state = env->state();
Object* fd_object = G(io)->get_const(env->state(), "FileDescriptor");
VALUE fd_class = env->get_handle(fd_object);
VALUE descriptor = env->get_handle(Fixnum::from(fd));

rb_funcall(fd_class, rb_intern("update_max_fd"), descriptor);
rb_funcall(fd_class, rb_intern("update_max_fd"), 1, descriptor);
}

void rb_fd_fix_cloexec(int fd) {
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
//IO::new_open_fd(env->state(), fd);
State *state = env->state();
Object* fd_object = G(io)->get_const(env->state(), "FileDescriptor");
VALUE fd_class = env->get_handle(fd_object);
VALUE descriptor = env->get_handle(Fixnum::from(fd));
VALUE fd_class = rb_path2class("IO::FileDescriptor");

rb_funcall(fd_class, rb_intern("new_open_fd"), descriptor);
rb_funcall(fd_class, rb_intern("new_open_fd"), 1, descriptor);
}

int rb_cloexec_open(const char *pathname, int flags, int mode) {
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
VALUE fd_class = rb_path2class("IO::FileDescriptor");
State *state = env->state();
Object* fd_object = G(io)->get_const(env->state(), "FileDescriptor");
VALUE fd_class = env->get_handle(fd_object);
VALUE pathname_v = env->get_handle(String::create(env->state(), pathname));
VALUE flags_v = env->get_handle(Fixnum::from(flags));
VALUE mode_v = env->get_handle(Fixnum::from(mode));
//return -1; //IO::open_with_cloexec(env->state(), pathname, mode, flags);
VALUE result = rb_funcall(fd_class, rb_intern("open_with_cloexec"), pathname_v, flags_v, mode_v);
VALUE result = rb_funcall(fd_class, rb_intern("open_with_cloexec"), 3, pathname_v, flags_v, mode_v);

return c_as<Fixnum>(env->get_object(result))->to_native();
return c_as<Fixnum>(env->get_object(result))->to_native();
}
}