From bc2f90c24822eb6a16341bea03115bc620dae71b Mon Sep 17 00:00:00 2001 From: Watson Date: Wed, 30 Nov 2011 14:59:18 +0900 Subject: [PATCH] ext/socket: fix #1424. try to open file when can't convert to IO's object. --- ext/socket/socket.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 696d172e9..7c08d852f 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -3062,13 +3062,13 @@ socket_sendfile(VALUE self, SEL sel, VALUE file, VALUE offset, VALUE len) rb_io_t *socket; GetOpenFile(self, socket); - if (TYPE(file) == T_STRING) { - file = rb_f_open(rb_cIO, 0, 1, &file); + VALUE io = rb_io_check_io(file); + if (NIL_P(io)) { + io = rb_f_open(rb_cIO, 0, 1, &file); needs_to_close = true; } - file = rb_io_check_io(file); - rb_io_t *source = ExtractIOStruct(file); + rb_io_t *source = ExtractIOStruct(io); rb_io_check_closed(source); if (sendfile(source->fd, socket->fd, to_offset, &to_write, NULL, 0) == -1) {