Ruby  2.5.0dev(2017-10-22revision60238)
init.c
Go to the documentation of this file.
1 /************************************************
2 
3  init.c -
4 
5  created at: Thu Mar 31 12:21:29 JST 1994
6 
7  Copyright (C) 1993-2007 Yukihiro Matsumoto
8 
9 ************************************************/
10 
11 #include "rubysocket.h"
12 
18 #ifdef AF_UNIX
19 VALUE rb_cUNIXSocket;
20 VALUE rb_cUNIXServer;
21 #endif
24 
26 
27 #ifdef SOCKS
28 VALUE rb_cSOCKSSocket;
29 #endif
30 
32 static VALUE sym_wait_readable;
33 
34 void
35 rsock_raise_socket_error(const char *reason, int error)
36 {
37 #ifdef EAI_SYSTEM
38  int e;
39  if (error == EAI_SYSTEM && (e = errno) != 0)
40  rb_syserr_fail(e, reason);
41 #endif
42  rb_raise(rb_eSocket, "%s: %s", reason, gai_strerror(error));
43 }
44 
45 #ifdef _WIN32
46 #define is_socket(fd) rb_w32_is_socket(fd)
47 #else
48 static int
49 is_socket(int fd)
50 {
51  struct stat sbuf;
52 
53  if (fstat(fd, &sbuf) < 0)
54  rb_sys_fail("fstat(2)");
55  return S_ISSOCK(sbuf.st_mode);
56 }
57 #endif
58 
59 VALUE
60 rsock_init_sock(VALUE sock, int fd)
61 {
62  rb_io_t *fp;
63 
64  if (!is_socket(fd) || rb_reserved_fd_p(fd)) {
65  rb_syserr_fail(EBADF, "not a socket file descriptor");
66  }
67 
68  rb_update_max_fd(fd);
69  MakeOpenFile(sock, fp);
70  fp->fd = fd;
74  fp->mode |= FMODE_NOREVLOOKUP;
75  }
77 
78  return sock;
79 }
80 
81 VALUE
83 {
84  struct rsock_send_arg *arg = data;
85  VALUE mesg = arg->mesg;
86  return (VALUE)sendto(arg->fd, RSTRING_PTR(mesg), RSTRING_LEN(mesg),
87  arg->flags, arg->to, arg->tolen);
88 }
89 
90 VALUE
92 {
93  struct rsock_send_arg *arg = data;
94  VALUE mesg = arg->mesg;
95  return (VALUE)send(arg->fd, RSTRING_PTR(mesg), RSTRING_LEN(mesg),
96  arg->flags);
97 }
98 
99 struct recvfrom_arg {
100  int fd, flags;
104 };
105 
106 static VALUE
107 recvfrom_blocking(void *data)
108 {
109  struct recvfrom_arg *arg = data;
110  socklen_t len0 = arg->alen;
111  ssize_t ret;
112  ret = recvfrom(arg->fd, RSTRING_PTR(arg->str), RSTRING_LEN(arg->str),
113  arg->flags, &arg->buf.addr, &arg->alen);
114  if (ret != -1 && len0 < arg->alen)
115  arg->alen = len0;
116  return (VALUE)ret;
117 }
118 
119 static VALUE
120 rsock_strbuf(VALUE str, long buflen)
121 {
122  long len;
123 
124  if (NIL_P(str)) return rb_tainted_str_new(0, buflen);
125 
126  StringValue(str);
127  len = RSTRING_LEN(str);
128  if (len >= buflen) {
130  } else {
131  rb_str_modify_expand(str, buflen - len);
132  }
133  rb_str_set_len(str, buflen);
134  return str;
135 }
136 
137 static VALUE
138 recvfrom_locktmp(VALUE v)
139 {
140  struct recvfrom_arg *arg = (struct recvfrom_arg *)v;
141 
142  return rb_thread_io_blocking_region(recvfrom_blocking, arg, arg->fd);
143 }
144 
145 VALUE
147 {
148  rb_io_t *fptr;
149  VALUE str;
150  struct recvfrom_arg arg;
151  VALUE len, flg;
152  long buflen;
153  long slen;
154 
155  rb_scan_args(argc, argv, "12", &len, &flg, &str);
156 
157  if (flg == Qnil) arg.flags = 0;
158  else arg.flags = NUM2INT(flg);
159  buflen = NUM2INT(len);
160  str = rsock_strbuf(str, buflen);
161 
162  GetOpenFile(sock, fptr);
163  if (rb_io_read_pending(fptr)) {
164  rb_raise(rb_eIOError, "recv for buffered IO");
165  }
166  arg.fd = fptr->fd;
167  arg.alen = (socklen_t)sizeof(arg.buf);
168  arg.str = str;
169 
170  while (rb_io_check_closed(fptr),
171  rsock_maybe_wait_fd(arg.fd),
172  (slen = (long)rb_str_locktmp_ensure(str, recvfrom_locktmp,
173  (VALUE)&arg)) < 0) {
174  if (!rb_io_wait_readable(fptr->fd)) {
175  rb_sys_fail("recvfrom(2)");
176  }
177  }
178 
179  if (slen != RSTRING_LEN(str)) {
180  rb_str_set_len(str, slen);
181  }
182  rb_obj_taint(str);
183  switch (from) {
184  case RECV_RECV:
185  return str;
186  case RECV_IP:
187 #if 0
188  if (arg.alen != sizeof(struct sockaddr_in)) {
189  rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
190  }
191 #endif
192  if (arg.alen && arg.alen != sizeof(arg.buf)) /* OSX doesn't return a from result for connection-oriented sockets */
193  return rb_assoc_new(str, rsock_ipaddr(&arg.buf.addr, arg.alen, fptr->mode & FMODE_NOREVLOOKUP));
194  else
195  return rb_assoc_new(str, Qnil);
196 
197 #ifdef HAVE_SYS_UN_H
198  case RECV_UNIX:
199  return rb_assoc_new(str, rsock_unixaddr(&arg.buf.un, arg.alen));
200 #endif
201  case RECV_SOCKET:
202  return rb_assoc_new(str, rsock_io_socket_addrinfo(sock, &arg.buf.addr, arg.alen));
203  default:
204  rb_bug("rsock_s_recvfrom called with bad value");
205  }
206 }
207 
208 VALUE
210  VALUE ex, enum sock_recv_type from)
211 {
212  rb_io_t *fptr;
214  socklen_t alen = (socklen_t)sizeof buf;
215  long buflen;
216  long slen;
217  int fd, flags;
218  VALUE addr = Qnil;
219  socklen_t len0;
220 
221  flags = NUM2INT(flg);
222  buflen = NUM2INT(len);
223  str = rsock_strbuf(str, buflen);
224 
225 #ifdef MSG_DONTWAIT
226  /* MSG_DONTWAIT avoids the race condition between fcntl and recvfrom.
227  It is not portable, though. */
228  flags |= MSG_DONTWAIT;
229 #endif
230 
231  GetOpenFile(sock, fptr);
232  if (rb_io_read_pending(fptr)) {
233  rb_raise(rb_eIOError, "recvfrom for buffered IO");
234  }
235  fd = fptr->fd;
236 
237  rb_io_check_closed(fptr);
238 
240  rb_io_set_nonblock(fptr);
241 
242  len0 = alen;
243  slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, &buf.addr, &alen);
244  if (slen != -1 && len0 < alen)
245  alen = len0;
246 
247  if (slen < 0) {
248  int e = errno;
249  switch (e) {
250  case EAGAIN:
251 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
252  case EWOULDBLOCK:
253 #endif
254  if (ex == Qfalse)
255  return sym_wait_readable;
256  rb_readwrite_syserr_fail(RB_IO_WAIT_READABLE, e, "recvfrom(2) would block");
257  }
258  rb_syserr_fail(e, "recvfrom(2)");
259  }
260  if (slen != RSTRING_LEN(str)) {
261  rb_str_set_len(str, slen);
262  }
263  rb_obj_taint(str);
264  switch (from) {
265  case RECV_RECV:
266  return str;
267 
268  case RECV_IP:
269  if (alen && alen != sizeof(buf)) /* connection-oriented socket may not return a from result */
270  addr = rsock_ipaddr(&buf.addr, alen, fptr->mode & FMODE_NOREVLOOKUP);
271  break;
272 
273  case RECV_SOCKET:
274  addr = rsock_io_socket_addrinfo(sock, &buf.addr, alen);
275  break;
276 
277  default:
278  rb_bug("rsock_s_recvfrom_nonblock called with bad value");
279  }
280  return rb_assoc_new(str, addr);
281 }
282 
283 /* returns true if SOCK_CLOEXEC is supported */
285 {
286 #ifdef SOCK_CLOEXEC
287  int flags = fcntl(fd, F_GETFD);
288 
289  if (flags == -1)
290  rb_bug("rsock_detect_cloexec: fcntl(%d, F_GETFD) failed: %s", fd, strerror(errno));
291 
292  if (flags & FD_CLOEXEC)
293  return 1;
294 #endif
295  return 0;
296 }
297 
298 #ifdef SOCK_CLOEXEC
299 static int
300 rsock_socket0(int domain, int type, int proto)
301 {
302  int ret;
303  static int cloexec_state = -1; /* <0: unknown, 0: ignored, >0: working */
304 
305  if (cloexec_state > 0) { /* common path, if SOCK_CLOEXEC is defined */
306  ret = socket(domain, type|SOCK_CLOEXEC, proto);
307  if (ret >= 0) {
308  if (ret <= 2)
309  goto fix_cloexec;
310  goto update_max_fd;
311  }
312  }
313  else if (cloexec_state < 0) { /* usually runs once only for detection */
314  ret = socket(domain, type|SOCK_CLOEXEC, proto);
315  if (ret >= 0) {
316  cloexec_state = rsock_detect_cloexec(ret);
317  if (cloexec_state == 0 || ret <= 2)
318  goto fix_cloexec;
319  goto update_max_fd;
320  }
321  else if (ret == -1 && errno == EINVAL) {
322  /* SOCK_CLOEXEC is available since Linux 2.6.27. Linux 2.6.18 fails with EINVAL */
323  ret = socket(domain, type, proto);
324  if (ret != -1) {
325  cloexec_state = 0;
326  /* fall through to fix_cloexec */
327  }
328  }
329  }
330  else { /* cloexec_state == 0 */
331  ret = socket(domain, type, proto);
332  }
333  if (ret == -1)
334  return -1;
335 fix_cloexec:
337 update_max_fd:
338  rb_update_max_fd(ret);
339 
340  return ret;
341 }
342 #else /* !SOCK_CLOEXEC */
343 static int
344 rsock_socket0(int domain, int type, int proto)
345 {
346  int ret = socket(domain, type, proto);
347 
348  if (ret == -1)
349  return -1;
350  rb_fd_fix_cloexec(ret);
351 
352  return ret;
353 }
354 #endif /* !SOCK_CLOEXEC */
355 
356 int
357 rsock_socket(int domain, int type, int proto)
358 {
359  int fd;
360 
361  fd = rsock_socket0(domain, type, proto);
362  if (fd < 0) {
363  if (rb_gc_for_fd(errno)) {
364  fd = rsock_socket0(domain, type, proto);
365  }
366  }
367  if (0 <= fd)
368  rb_update_max_fd(fd);
369  return fd;
370 }
371 
372 /* emulate blocking connect behavior on EINTR or non-blocking socket */
373 static int
374 wait_connectable(int fd)
375 {
376  int sockerr, revents;
377  socklen_t sockerrlen;
378 
379  /* only to clear pending error */
380  sockerrlen = (socklen_t)sizeof(sockerr);
381  if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&sockerr, &sockerrlen) < 0)
382  return -1;
383 
384  /*
385  * Stevens book says, successful finish turn on RB_WAITFD_OUT and
386  * failure finish turn on both RB_WAITFD_IN and RB_WAITFD_OUT.
387  * So it's enough to wait only RB_WAITFD_OUT and check the pending error
388  * by getsockopt().
389  *
390  * Note: rb_wait_for_single_fd already retries on EINTR/ERESTART
391  */
393 
394  if (revents < 0)
395  return -1;
396 
397  sockerrlen = (socklen_t)sizeof(sockerr);
398  if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&sockerr, &sockerrlen) < 0)
399  return -1;
400 
401  switch (sockerr) {
402  case 0:
403  /*
404  * be defensive in case some platforms set SO_ERROR on the original,
405  * interrupted connect()
406  */
407  case EINTR:
408 #ifdef ERESTART
409  case ERESTART:
410 #endif
411  case EAGAIN:
412 #ifdef EINPROGRESS
413  case EINPROGRESS:
414 #endif
415 #ifdef EALREADY
416  case EALREADY:
417 #endif
418 #ifdef EISCONN
419  case EISCONN:
420 #endif
421  return 0; /* success */
422  default:
423  /* likely (but not limited to): ECONNREFUSED, ETIMEDOUT, EHOSTUNREACH */
424  errno = sockerr;
425  return -1;
426  }
427 
428  return 0;
429 }
430 
431 struct connect_arg {
432  int fd;
434  const struct sockaddr *sockaddr;
435 };
436 
437 static VALUE
438 connect_blocking(void *data)
439 {
440  struct connect_arg *arg = data;
441  return (VALUE)connect(arg->fd, arg->sockaddr, arg->len);
442 }
443 
444 #if defined(SOCKS) && !defined(SOCKS5)
445 static VALUE
446 socks_connect_blocking(void *data)
447 {
448  struct connect_arg *arg = data;
449  return (VALUE)Rconnect(arg->fd, arg->sockaddr, arg->len);
450 }
451 #endif
452 
453 int
454 rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks)
455 {
456  int status;
457  rb_blocking_function_t *func = connect_blocking;
458  struct connect_arg arg;
459 
460  arg.fd = fd;
461  arg.sockaddr = sockaddr;
462  arg.len = len;
463 #if defined(SOCKS) && !defined(SOCKS5)
464  if (socks) func = socks_connect_blocking;
465 #endif
466  status = (int)BLOCKING_REGION_FD(func, &arg);
467 
468  if (status < 0) {
469  switch (errno) {
470  case EINTR:
471 #ifdef ERESTART
472  case ERESTART:
473 #endif
474  case EAGAIN:
475 #ifdef EINPROGRESS
476  case EINPROGRESS:
477 #endif
478  return wait_connectable(fd);
479  }
480  }
481  return status;
482 }
483 
484 static void
485 make_fd_nonblock(int fd)
486 {
487  int flags;
488 #ifdef F_GETFL
489  flags = fcntl(fd, F_GETFL);
490  if (flags == -1) {
491  rb_sys_fail("fnctl(2)");
492  }
493 #else
494  flags = 0;
495 #endif
496  flags |= O_NONBLOCK;
497  if (fcntl(fd, F_SETFL, flags) == -1) {
498  rb_sys_fail("fnctl(2)");
499  }
500 }
501 
502 static int
503 cloexec_accept(int socket, struct sockaddr *address, socklen_t *address_len,
504  int nonblock)
505 {
506  int ret;
507  socklen_t len0 = 0;
508 #ifdef HAVE_ACCEPT4
509  static int try_accept4 = 1;
510 #endif
511  if (address_len) len0 = *address_len;
512 #ifdef HAVE_ACCEPT4
513  if (try_accept4) {
514  int flags = 0;
515 #ifdef SOCK_CLOEXEC
516  flags |= SOCK_CLOEXEC;
517 #endif
518 #ifdef SOCK_NONBLOCK
519  if (nonblock) {
520  flags |= SOCK_NONBLOCK;
521  }
522 #endif
523  ret = accept4(socket, address, address_len, flags);
524  /* accept4 is available since Linux 2.6.28, glibc 2.10. */
525  if (ret != -1) {
526  if (ret <= 2)
528 #ifndef SOCK_NONBLOCK
529  if (nonblock) {
530  make_fd_nonblock(ret);
531  }
532 #endif
533  if (address_len && len0 < *address_len) *address_len = len0;
534  return ret;
535  }
536  if (errno != ENOSYS) {
537  return -1;
538  }
539  try_accept4 = 0;
540  }
541 #endif
542  ret = accept(socket, address, address_len);
543  if (ret == -1) return -1;
544  if (address_len && len0 < *address_len) *address_len = len0;
546  if (nonblock) {
547  make_fd_nonblock(ret);
548  }
549  return ret;
550 }
551 
552 VALUE
554  struct sockaddr *sockaddr, socklen_t *len)
555 {
556  int fd2;
557 
558  rb_io_set_nonblock(fptr);
559  fd2 = cloexec_accept(fptr->fd, (struct sockaddr*)sockaddr, len, 1);
560  if (fd2 < 0) {
561  int e = errno;
562  switch (e) {
563  case EAGAIN:
564 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
565  case EWOULDBLOCK:
566 #endif
567  case ECONNABORTED:
568 #if defined EPROTO
569  case EPROTO:
570 #endif
571  if (ex == Qfalse)
572  return sym_wait_readable;
573  rb_readwrite_syserr_fail(RB_IO_WAIT_READABLE, e, "accept(2) would block");
574  }
575  rb_syserr_fail(e, "accept(2)");
576  }
577  rb_update_max_fd(fd2);
578  return rsock_init_sock(rb_obj_alloc(klass), fd2);
579 }
580 
581 struct accept_arg {
582  int fd;
583  struct sockaddr *sockaddr;
585 };
586 
587 static VALUE
588 accept_blocking(void *data)
589 {
590  struct accept_arg *arg = data;
591  return (VALUE)cloexec_accept(arg->fd, arg->sockaddr, arg->len, 0);
592 }
593 
594 VALUE
596 {
597  int fd2;
598  int retry = 0;
599  struct accept_arg arg;
600 
601  arg.fd = fd;
602  arg.sockaddr = sockaddr;
603  arg.len = len;
604  retry:
606  fd2 = (int)BLOCKING_REGION_FD(accept_blocking, &arg);
607  if (fd2 < 0) {
608  int e = errno;
609  switch (e) {
610  case EMFILE:
611  case ENFILE:
612  case ENOMEM:
613  if (retry) break;
614  rb_gc();
615  retry = 1;
616  goto retry;
617  default:
618  if (!rb_io_wait_readable(fd)) break;
619  retry = 0;
620  goto retry;
621  }
622  rb_syserr_fail(e, "accept(2)");
623  }
624  rb_update_max_fd(fd2);
625  if (!klass) return INT2NUM(fd2);
626  return rsock_init_sock(rb_obj_alloc(klass), fd2);
627 }
628 
629 int
631 {
632  union_sockaddr ss;
633  socklen_t sslen = (socklen_t)sizeof(ss);
634  int cached = fptr->mode & FMODE_SOCK;
635 
636  if (cached) {
637  switch (cached) {
638 #ifdef AF_UNIX
639  case FMODE_UNIX: return AF_UNIX;
640 #endif
641  case FMODE_INET: return AF_INET;
642  case FMODE_INET6: return AF_INET6;
643  }
644  }
645 
646  ss.addr.sa_family = AF_UNSPEC;
647  if (getsockname(fptr->fd, &ss.addr, &sslen) < 0)
648  return AF_UNSPEC;
649 
650  switch (ss.addr.sa_family) {
651 #ifdef AF_UNIX
652  case AF_UNIX: fptr->mode |= FMODE_UNIX; break;
653 #endif
654  case AF_INET: fptr->mode |= FMODE_INET; break;
655  case AF_INET6: fptr->mode |= FMODE_INET6; break;
656  }
657 
658  return ss.addr.sa_family;
659 }
660 
661 void
663 {
664  /*
665  * SocketError is the error class for socket.
666  */
667  rb_eSocket = rb_define_class("SocketError", rb_eStandardError);
680 
681 #undef rb_intern
682  sym_wait_readable = ID2SYM(rb_intern("wait_readable"));
683 }
void rb_gc(void)
Definition: gc.c:6727
void rb_bug(const char *fmt,...)
Definition: error.c:521
struct sockaddr * sockaddr
Definition: init.c:583
void rb_syserr_fail(int e, const char *mesg)
Definition: error.c:2391
socklen_t tolen
Definition: rubysocket.h:327
#define FMODE_READWRITE
Definition: io.h:104
VALUE rsock_sendto_blocking(void *data)
Definition: init.c:82
#define INT2NUM(x)
Definition: ruby.h:1538
void rb_update_max_fd(int fd)
Definition: io.c:191
void rb_io_set_nonblock(rb_io_t *fptr)
Definition: io.c:2475
void rb_io_synchronized(rb_io_t *)
Definition: io.c:5996
VALUE rb_cBasicSocket
Definition: init.c:13
#define FMODE_UNIX
Definition: rubysocket.h:230
#define NUM2INT(x)
Definition: ruby.h:684
socklen_t * len
Definition: init.c:584
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2284
Definition: io.h:62
VALUE rsock_init_sock(VALUE sock, int fd)
Definition: init.c:60
int fcntl(int, int,...)
Definition: win32.c:4297
void rsock_init_unixsocket(void)
Definition: unixsocket.c:529
VALUE str
Definition: init.c:101
VALUE rb_str_locktmp_ensure(VALUE str, VALUE(*func)(VALUE), VALUE arg)
Definition: string.c:2620
void rb_str_set_len(VALUE, long)
Definition: string.c:2627
void rsock_init_tcpserver(void)
Definition: tcpserver.c:106
int rb_gc_for_fd(int err)
Definition: io.c:878
VALUE rb_cIPSocket
Definition: init.c:14
struct sockaddr * to
Definition: rubysocket.h:326
VALUE rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
Definition: init.c:595
sock_recv_type
Definition: rubysocket.h:334
#define FMODE_DUPLEX
Definition: io.h:108
VALUE rb_obj_alloc(VALUE)
Allocates an instance of klass.
Definition: object.c:2121
#define FMODE_NOREVLOOKUP
Definition: rubysocket.h:227
void rsock_init_sockifaddr(void)
Definition: ifaddr.c:460
VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd)
Definition: thread.c:1436
void rsock_init_socket_constants(void)
Definition: constants.c:141
VALUE rsock_ipaddr(struct sockaddr *sockaddr, socklen_t sockaddrlen, int norevlookup)
Definition: raddrinfo.c:559
#define EINPROGRESS
Definition: win32.h:477
VALUE rsock_s_recvfrom_nonblock(VALUE sock, VALUE len, VALUE flg, VALUE str, VALUE ex, enum sock_recv_type from)
Definition: init.c:209
#define GetOpenFile(obj, fp)
Definition: io.h:120
void rsock_init_addrinfo(void)
Definition: raddrinfo.c:2560
VALUE rb_cTCPSocket
Definition: init.c:15
VALUE rsock_io_socket_addrinfo(VALUE io, struct sockaddr *addr, socklen_t len)
Definition: raddrinfo.c:2534
#define RB_WAITFD_OUT
Definition: io.h:49
int mode
Definition: io.h:65
int fd
Definition: init.c:582
VALUE rsock_s_accept_nonblock(VALUE klass, VALUE ex, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
Definition: init.c:553
#define FMODE_INET6
Definition: rubysocket.h:232
union_sockaddr buf
Definition: init.c:103
VALUE rb_obj_taint(VALUE)
call-seq: obj.taint -> obj
Definition: object.c:1179
void rsock_init_tcpsocket(void)
Definition: tcpsocket.c:68
#define F_SETFL
Definition: win32.h:587
void rsock_init_sockssocket(void)
Definition: sockssocket.c:52
#define ECONNABORTED
Definition: win32.h:528
socklen_t len
Definition: init.c:433
VALUE rsock_send_blocking(void *data)
Definition: init.c:91
#define EALREADY
Definition: win32.h:480
int rsock_getfamily(rb_io_t *fptr)
Definition: init.c:630
int rsock_socket(int domain, int type, int proto)
Definition: init.c:357
#define FMODE_SOCK
Definition: rubysocket.h:233
#define NIL_P(v)
Definition: ruby.h:451
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:646
int fd
Definition: io.h:64
#define FMODE_INET
Definition: rubysocket.h:231
int argc
Definition: ruby.c:187
#define Qfalse
Definition: ruby.h:436
void rsock_init_ancdata(void)
Definition: ancdata.c:1695
#define EAI_SYSTEM
Definition: addrinfo.h:88
#define F_GETFD
Definition: win32.h:582
VALUE rb_cSocket
Definition: init.c:22
void rb_sys_fail(const char *mesg)
Definition: error.c:2403
char * gai_strerror(int ecode)
Definition: getaddrinfo.c:205
#define RSTRING_LEN(str)
Definition: ruby.h:971
int errno
int socklen_t
Definition: getaddrinfo.c:83
VALUE rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
Definition: init.c:146
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1908
void rb_str_modify_expand(VALUE, long)
Definition: string.c:2054
VALUE rb_assoc_new(VALUE car, VALUE cdr)
Definition: array.c:639
void rsock_init_udpsocket(void)
Definition: udpsocket.c:227
#define Qnil
Definition: ruby.h:438
VALUE rb_cTCPServer
Definition: init.c:16
int rsock_do_not_reverse_lookup
Definition: init.c:31
VALUE rb_eStandardError
Definition: error.c:799
void rb_readwrite_syserr_fail(enum rb_io_wait_readwrite writable, int n, const char *mesg)
Definition: io.c:12453
unsigned long VALUE
Definition: ruby.h:85
int rsock_detect_cloexec(int fd)
Definition: init.c:284
VALUE rb_eTypeError
Definition: error.c:801
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv)
Definition: thread.c:3989
int fd
Definition: init.c:100
VALUE rb_blocking_function_t(void *)
Definition: intern.h:873
int rb_reserved_fd_p(int fd)
register unsigned int len
Definition: zonetab.h:51
const struct sockaddr * sockaddr
Definition: init.c:434
#define RSTRING_PTR(str)
Definition: ruby.h:975
VALUE rb_eSocket
Definition: init.c:25
void rb_str_modify(VALUE)
Definition: string.c:2046
int rb_io_read_pending(rb_io_t *)
Definition: io.c:860
#define EISCONN
Definition: win32.h:537
void rb_fd_fix_cloexec(int fd)
Definition: io.c:233
#define proto(p)
Definition: sdbm.h:60
#define FD_CLOEXEC
Definition: win32.h:589
void rsock_raise_socket_error(const char *reason, int error)
Definition: init.c:35
#define is_socket(fd, path)
Definition: io.c:605
#define rsock_maybe_wait_fd(fd)
Definition: rubysocket.h:422
VALUE rb_io_ascii8bit_binmode(VALUE)
Definition: io.c:5058
int rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks)
Definition: init.c:454
RUBY_EXTERN char * strerror(int)
Definition: strerror.c:11
VALUE rb_cAddrinfo
Definition: init.c:23
#define O_NONBLOCK
Definition: win32.h:590
#define AF_UNSPEC
Definition: sockport.h:101
#define EWOULDBLOCK
Definition: rubysocket.h:128
void rsock_init_ipsocket(void)
Definition: ipsocket.c:364
socklen_t alen
Definition: init.c:102
void rsock_init_unixserver(void)
Definition: unixserver.c:109
#define MSG_DONTWAIT_RELIABLE
Definition: rubysocket.h:430
RUBY_EXTERN VALUE rb_eIOError
Definition: ruby.h:1947
#define ID2SYM(x)
Definition: ruby.h:383
#define MakeOpenFile(obj, fp)
Definition: io.h:122
void rsock_init_sockopt(void)
Definition: option.c:1438
#define RB_WAITFD_IN
Definition: io.h:47
VALUE rb_tainted_str_new(const char *, long)
Definition: string.c:854
#define rb_intern(str)
#define fstat(fd, st)
Definition: win32.h:184
#define stat(path, st)
Definition: win32.h:183
#define NULL
Definition: _sdbm.c:102
int flags
Definition: init.c:100
int rb_io_wait_readable(int)
Definition: io.c:1106
void rsock_init_socket_init(void)
Definition: init.c:662
void rb_io_check_closed(rb_io_t *)
Definition: io.c:641
#define BLOCKING_REGION_FD(func, arg)
Definition: rubysocket.h:262
void rb_maygvl_fd_fix_cloexec(int fd)
Definition: io.c:210
int fd
Definition: init.c:432
char ** argv
Definition: ruby.c:188
#define StringValue(v)
Definition: ruby.h:569
struct sockaddr addr
Definition: rubysocket.h:187
VALUE rb_cUDPSocket
Definition: init.c:17