implement TCP Fast Open support (client + server)
[kgio.git] / ext / kgio / kgio.h
blob983280df44f678c52de9d4a0cf9c1adf6a0c8bc6
1 #ifndef KGIO_H
2 #define KGIO_H
4 #include <ruby.h>
5 #ifdef HAVE_RUBY_IO_H
6 # include <ruby/io.h>
7 #else
8 # include <rubyio.h>
9 #endif
10 #include <errno.h>
11 #include <sys/types.h>
12 #include <sys/socket.h>
13 #include <sys/un.h>
14 #include <netinet/in.h>
15 #include <fcntl.h>
16 #include <unistd.h>
17 #include <arpa/inet.h>
18 #include <assert.h>
19 #include <netdb.h>
21 #include "ancient_ruby.h"
23 struct io_args {
24 VALUE io;
25 VALUE buf;
26 char *ptr;
27 long len;
28 int fd;
31 void init_kgio_wait(void);
32 void init_kgio_read_write(void);
33 void init_kgio_accept(void);
34 void init_kgio_connect(void);
35 void init_kgio_autopush(void);
36 void init_kgio_poll(void);
37 void init_kgio_tryopen(void);
39 void kgio_autopush_accept(VALUE, VALUE);
40 void kgio_autopush_recv(VALUE);
41 void kgio_autopush_send(VALUE);
43 VALUE kgio_call_wait_writable(VALUE io);
44 VALUE kgio_call_wait_readable(VALUE io);
45 #if defined(HAVE_RB_THREAD_BLOCKING_REGION) && defined(HAVE_POLL)
46 # define USE_KGIO_POLL
47 #endif /* USE_KGIO_POLL */
49 #ifndef HAVE_RB_UPDATE_MAX_FD
50 # define rb_update_max_fd(fd) for (;0;)
51 #endif
54 * 2012/12/13 - Linux 3.7 was released on 2012/12/10 with TFO.
55 * Headers distributed with glibc will take some time to catch up and
56 * be officially released. Most GNU/Linux distros will take a few months
57 * to a year longer. "Enterprise" distros will probably take 5-7 years.
58 * So keep these until 2017 at least...
60 #ifdef __linux__
61 # ifndef MSG_FASTOPEN
62 # define MSG_FASTOPEN 0x20000000 /* for clients */
63 # endif
64 # ifndef TCP_FASTOPEN
65 # define TCP_FASTOPEN 23 /* for listeners */
66 # endif
67 /* we _may_ have TFO support */
68 # define KGIO_TFO_MAYBE (1)
69 #else /* rely entirely on standard system headers */
70 # define KGIO_TFO_MAYBE (0)
71 #endif
73 extern unsigned kgio_tfo;
75 #endif /* KGIO_H */