10 #ifdef HAVE_RUBY_THREAD_H
11 # include <ruby/thread.h>
14 #include <sys/types.h>
15 #include <sys/socket.h>
17 #include <netinet/in.h>
20 #include <arpa/inet.h>
24 #include "ancient_ruby.h"
26 void init_kgio_wait(void);
27 void init_kgio_read(void);
28 void init_kgio_write(void);
29 void init_kgio_writev(void);
30 void init_kgio_accept(void);
31 void init_kgio_connect(void);
32 void init_kgio_poll(void);
33 void init_kgio_tryopen(void);
35 VALUE
kgio_call_wait_writable(VALUE io
);
36 VALUE
kgio_call_wait_readable(VALUE io
);
37 #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) && defined(HAVE_RUBY_THREAD_H)
38 # define KGIO_WITHOUT_GVL(fn,data1,ubf,data2) \
39 rb_thread_call_without_gvl((fn),(data1),(ubf),(data2))
40 #elif defined(HAVE_RB_THREAD_BLOCKING_REGION)
41 typedef VALUE(*kgio_blocking_fn_t
)(void*);
42 # define KGIO_WITHOUT_GVL(fn,data1,ubf,data2) \
43 rb_thread_blocking_region((kgio_blocking_fn_t)(fn),(data1),(ubf),(data2))
44 #endif /* HAVE_RB_THREAD_CALL_WITHOUT_GVL || HAVE_RB_THREAD_BLOCKING_REGION */
46 #if defined(KGIO_WITHOUT_GVL) && defined(HAVE_POLL)
47 # define USE_KGIO_POLL
48 #endif /* USE_KGIO_POLL */
50 #ifndef HAVE_RB_UPDATE_MAX_FD
51 # define rb_update_max_fd(fd) for (;0;)
55 * 2012/12/13 - Linux 3.7 was released on 2012/12/10 with TFO.
56 * Headers distributed with glibc will take some time to catch up and
57 * be officially released. Most GNU/Linux distros will take a few months
58 * to a year longer. "Enterprise" distros will probably take 5-7 years.
59 * So keep these until 2017 at least...
63 # define MSG_FASTOPEN 0x20000000 /* for clients */
66 # define TCP_FASTOPEN 23 /* for listeners */
68 /* we _may_ have TFO support */
69 # define KGIO_TFO_MAYBE (1)
70 #else /* rely entirely on standard system headers */
71 # define KGIO_TFO_MAYBE (0)
74 extern unsigned kgio_tfo
;
75 NORETURN(void kgio_raise_empty_bt(VALUE
, const char *));
76 NORETURN(void kgio_wr_sys_fail(const char *));
77 NORETURN(void kgio_rd_sys_fail(const char *));
80 * we know MSG_DONTWAIT works properly on all stream sockets under Linux
81 * we can define this macro for other platforms as people care and
84 # if defined(__linux__)
85 # define USE_MSG_DONTWAIT
88 /* prefer rb_str_subseq because we don't use negative offsets */
89 #ifndef HAVE_RB_STR_SUBSEQ
90 #define MY_STR_SUBSEQ(str,beg,len) rb_str_substr((str),(beg),(len))
92 #define MY_STR_SUBSEQ(str,beg,len) rb_str_subseq((str),(beg),(len))