From 6c59b07c500b36274788abe47b34103a3a8586a6 Mon Sep 17 00:00:00 2001
From: Aman Gupta <aman@tmm1.net>
Date: Mon, 9 Feb 2015 23:45:00 -0800
Subject: [PATCH 10/11] fix build on ruby 1.9.1

Conflicts:
	ext/extconf.rb
---
 ext/em.cpp     | 2 +-
 ext/em.h       | 9 +++++++--
 ext/extconf.rb | 2 ++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/ext/em.cpp b/ext/em.cpp
index 27ea088..315d7d7 100644
--- a/ext/em.cpp
+++ b/ext/em.cpp
@@ -814,7 +814,7 @@ _SelectDataSelect
 static VALUE _SelectDataSelect (void *v)
 {
 	SelectData_t *sd = (SelectData_t*)v;
-	sd->nSockets = select (sd->maxsocket+1, &(sd->fdreads), &(sd->fdwrites), &(sd->fderrors), &(sd->tv));
+	sd->nSockets = select (sd->maxsocket+1, rb_fd_ptr(&(sd->fdreads)), rb_fd_ptr(&(sd->fdwrites)), rb_fd_ptr(&(sd->fderrors)), &(sd->tv));
 	return Qnil;
 }
 #endif
diff --git a/ext/em.h b/ext/em.h
index 3799bba..86909ad 100644
--- a/ext/em.h
+++ b/ext/em.h
@@ -22,7 +22,12 @@ See the file COPYING for complete licensing information.
 
 #ifdef BUILD_FOR_RUBY
   #include <ruby.h>
-  #define EmSelect rb_thread_fd_select
+  #ifdef HAVE_RB_THREAD_FD_SELECT
+    #define EmSelect rb_thread_fd_select
+  #else
+    // ruby 1.9.1 and below
+    #define EmSelect rb_thread_select
+  #endif
 
   #ifdef HAVE_RB_WAIT_FOR_SINGLE_FD
     #include <ruby/io.h>
@@ -60,7 +65,7 @@ See the file COPYING for complete licensing information.
   #define EmSelect select
 #endif
 
-#if defined(BUILD_FOR_RUBY) && !defined(rb_fd_max)
+#if defined(BUILD_FOR_RUBY) && !defined(HAVE_RB_FDSET_T)
 #define fd_check(n) (((n) < FD_SETSIZE) ? 1 : 0*fprintf(stderr, "fd %d too large for select\n", (n)))
 // These definitions are cribbed from include/ruby/intern.h in Ruby 1.9.3,
 // with this change: any macros that read or write the nth element of an
diff --git a/ext/extconf.rb b/ext/extconf.rb
index 448802a..28cd687 100644
--- a/ext/extconf.rb
+++ b/ext/extconf.rb
@@ -70,6 +70,8 @@ add_define "HAVE_TBR" if have_func('rb_thread_blocking_region')# and have_macro(
 add_define "HAVE_INOTIFY" if inotify = have_func('inotify_init', 'sys/inotify.h')
 add_define "HAVE_OLD_INOTIFY" if !inotify && have_macro('__NR_inotify_init', 'sys/syscall.h')
 add_define 'HAVE_WRITEV' if have_func('writev', 'sys/uio.h')
+add_define 'HAVE_RB_THREAD_FD_SELECT' if have_func('rb_thread_fd_select')
+add_define 'HAVE_RB_FDSET_T' if have_type('rb_fdset_t', 'ruby/intern.h')
 
 have_func('rb_wait_for_single_fd')
 have_func('rb_enable_interrupt')
-- 
2.1.4

