예제 #1
0
파일: io.cpp 프로젝트: dziulius/rubinius
 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;
   if(!(O_WRONLY == io_mode || O_RDWR == io_mode)) {
     rb_raise(rb_eIOError, "not opened for writing");
   }
 }
예제 #2
0
파일: io.cpp 프로젝트: aemoncannon/rubinius
  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));

    if ((io->mode()->to_native() & O_ACCMODE) != O_RDONLY) {
      rb_raise(rb_eIOError, "not opened for reading");
    }
  }
예제 #3
0
  void test_connect_pipe() {
    IO* lhs = IO::allocate(state, G(io));
    IO* rhs = IO::allocate(state, G(io));

    TS_ASSERT(IO::connect_pipe(state, lhs, rhs)->true_p());
    TS_ASSERT_EQUALS(Fixnum::from(0), lhs->lineno());
    TS_ASSERT_EQUALS(Fixnum::from(0), rhs->lineno());
    TS_ASSERT(kind_of<IOBuffer>(lhs->ibuffer()));
    TS_ASSERT(kind_of<IOBuffer>(rhs->ibuffer()));
    int acc_mode = fcntl(lhs->to_fd(), F_GETFL);
    TS_ASSERT(acc_mode >= 0);
    TS_ASSERT_EQUALS(Fixnum::from(acc_mode), lhs->mode());
    acc_mode = fcntl(rhs->to_fd(), F_GETFL);
    TS_ASSERT(acc_mode >= 0);
    TS_ASSERT_EQUALS(Fixnum::from(acc_mode), rhs->mode());

    lhs->close(state);
    rhs->close(state);
  }
예제 #4
0
  void test_connect_pipe() {
    IO* lhs = IO::allocate(state, G(io));
    IO* rhs = IO::allocate(state, G(io));

    TS_ASSERT(IO::connect_pipe(state, lhs, rhs)->true_p());
    TS_ASSERT_EQUALS(Fixnum::from(0), lhs->lineno());
    TS_ASSERT_EQUALS(Fixnum::from(0), rhs->lineno());
    TS_ASSERT(kind_of<IOBuffer>(lhs->ibuffer()));
    TS_ASSERT(kind_of<IOBuffer>(rhs->ibuffer()));
    TS_ASSERT_EQUALS(Fixnum::from(O_RDONLY), lhs->mode());
    TS_ASSERT_EQUALS(Fixnum::from(O_WRONLY), rhs->mode());

    rhs->write(state, String::create(state, "hello"), 0);
    Object* obj = lhs->blocking_read(state, Fixnum::from(5));
    TS_ASSERT(kind_of<String>(obj));

    String* str = try_as<String>(obj);
    TS_ASSERT_EQUALS(std::string("hello"), str->c_str(state));

    lhs->close(state);
    rhs->close(state);
  }