Skip to content

Commit

Permalink
Modifications to read_from
Browse files Browse the repository at this point in the history
Signed-off-by: UpeksheJay <[email protected]>
  • Loading branch information
UpeksheJay committed Aug 17, 2016
1 parent c58d5a9 commit 10da2c6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ext/nio4r/bytebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,25 @@ static VALUE NIO_ByteBuffer_writeTo(VALUE self, VALUE io){
return self;
}

static VALUE NIO_ByteBuffer_readFrom(VALUE self, VALUE file){
static VALUE NIO_ByteBuffer_readFrom(VALUE self, VALUE io){
struct NIO_ByteBuffer *byteBuffer;
Data_Get_Struct(self, struct NIO_ByteBuffer, byteBuffer);
int size = byteBuffer->limit + 1 - byteBuffer->position;

#if HAVE_RB_IO_T
rb_io_t *fptr;
#else
OpenFile *fptr;
#endif

GetOpenFile(rb_convert_type(io, T_FILE, "IO", "to_io"), fptr);
rb_io_set_nonblock(fptr);
while(NIO_ByteBuffer_hasRemaining(self) == Qtrue){
char* nextByte;
read(FPTR_TO_FD(fptr), &nextByte, 1);
VALUE byte = rb_str_new2(nextByte);
NIO_ByteBuffer_put(self, byte);
}
return self;
}

Expand Down

0 comments on commit 10da2c6

Please sign in to comment.