Ruby  2.1.10p492(2016-04-01revision54464)
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 
33 void
34 rsock_raise_socket_error(const char *reason, int error)
35 {
36 #ifdef EAI_SYSTEM
37  if (error == EAI_SYSTEM) rb_sys_fail(reason);
38 #endif
39  rb_raise(rb_eSocket, "%s: %s", reason, gai_strerror(error));
40 }
41 
42 VALUE
43 rsock_init_sock(VALUE sock, int fd)
44 {
45  rb_io_t *fp;
46 #ifndef _WIN32
47  struct stat sbuf;
48 
49  if (fstat(fd, &sbuf) < 0)
50  rb_sys_fail("fstat(2)");
51  if (!S_ISSOCK(sbuf.st_mode) || rb_reserved_fd_p(fd)) {
52  errno = EBADF;
53  rb_sys_fail("not a socket file descriptor");
54  }
55 #else
56  if (!rb_w32_is_socket(fd) || rb_reserved_fd_p(fd)) {
57  errno = EBADF;
58  rb_sys_fail("not a socket file descriptor");
59  }
60 #endif
61 
62  rb_update_max_fd(fd);
63  MakeOpenFile(sock, fp);
64  fp->fd = fd;
68  fp->mode |= FMODE_NOREVLOOKUP;
69  }
71 
72  return sock;
73 }
74 
75 VALUE
77 {
78  struct rsock_send_arg *arg = data;
79  VALUE mesg = arg->mesg;
80  return (VALUE)sendto(arg->fd, RSTRING_PTR(mesg), RSTRING_LEN(mesg),
81  arg->flags, arg->to, arg->tolen);
82 }
83 
84 VALUE
86 {
87  struct rsock_send_arg *arg = data;
88  VALUE mesg = arg->mesg;
89  return (VALUE)send(arg->fd, RSTRING_PTR(mesg), RSTRING_LEN(mesg),
90  arg->flags);
91 }
92 
93 struct recvfrom_arg {
94  int fd, flags;
98 };
99 
100 static VALUE
101 recvfrom_blocking(void *data)
102 {
103  struct recvfrom_arg *arg = data;
104  socklen_t len0 = arg->alen;
105  ssize_t ret;
106  ret = recvfrom(arg->fd, RSTRING_PTR(arg->str), RSTRING_LEN(arg->str),
107  arg->flags, &arg->buf.addr, &arg->alen);
108  if (ret != -1 && len0 < arg->alen)
109  arg->alen = len0;
110  return (VALUE)ret;
111 }
112 
113 VALUE
115 {
116  rb_io_t *fptr;
117  VALUE str, klass;
118  struct recvfrom_arg arg;
119  VALUE len, flg;
120  long buflen;
121  long slen;
122 
123  rb_scan_args(argc, argv, "11", &len, &flg);
124 
125  if (flg == Qnil) arg.flags = 0;
126  else arg.flags = NUM2INT(flg);
127  buflen = NUM2INT(len);
128 
129  GetOpenFile(sock, fptr);
130  if (rb_io_read_pending(fptr)) {
131  rb_raise(rb_eIOError, "recv for buffered IO");
132  }
133  arg.fd = fptr->fd;
134  arg.alen = (socklen_t)sizeof(arg.buf);
135 
136  arg.str = str = rb_tainted_str_new(0, buflen);
137  klass = RBASIC(str)->klass;
138  rb_obj_hide(str);
139 
140  while (rb_io_check_closed(fptr),
141  rb_thread_wait_fd(arg.fd),
142  (slen = BLOCKING_REGION_FD(recvfrom_blocking, &arg)) < 0) {
143  if (!rb_io_wait_readable(fptr->fd)) {
144  rb_sys_fail("recvfrom(2)");
145  }
146  if (RBASIC(str)->klass || RSTRING_LEN(str) != buflen) {
147  rb_raise(rb_eRuntimeError, "buffer string modified");
148  }
149  }
150 
151  rb_obj_reveal(str, klass);
152  if (slen < RSTRING_LEN(str)) {
153  rb_str_set_len(str, slen);
154  }
155  rb_obj_taint(str);
156  switch (from) {
157  case RECV_RECV:
158  return str;
159  case RECV_IP:
160 #if 0
161  if (arg.alen != sizeof(struct sockaddr_in)) {
162  rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
163  }
164 #endif
165  if (arg.alen && arg.alen != sizeof(arg.buf)) /* OSX doesn't return a from result for connection-oriented sockets */
166  return rb_assoc_new(str, rsock_ipaddr(&arg.buf.addr, arg.alen, fptr->mode & FMODE_NOREVLOOKUP));
167  else
168  return rb_assoc_new(str, Qnil);
169 
170 #ifdef HAVE_SYS_UN_H
171  case RECV_UNIX:
172  return rb_assoc_new(str, rsock_unixaddr(&arg.buf.un, arg.alen));
173 #endif
174  case RECV_SOCKET:
175  return rb_assoc_new(str, rsock_io_socket_addrinfo(sock, &arg.buf.addr, arg.alen));
176  default:
177  rb_bug("rsock_s_recvfrom called with bad value");
178  }
179 }
180 
181 VALUE
183 {
184  rb_io_t *fptr;
185  VALUE str;
187  socklen_t alen = (socklen_t)sizeof buf;
188  VALUE len, flg;
189  long buflen;
190  long slen;
191  int fd, flags;
192  VALUE addr = Qnil;
193  socklen_t len0;
194 
195  rb_scan_args(argc, argv, "11", &len, &flg);
196 
197  if (flg == Qnil) flags = 0;
198  else flags = NUM2INT(flg);
199  buflen = NUM2INT(len);
200 
201 #ifdef MSG_DONTWAIT
202  /* MSG_DONTWAIT avoids the race condition between fcntl and recvfrom.
203  It is not portable, though. */
204  flags |= MSG_DONTWAIT;
205 #endif
206 
207  GetOpenFile(sock, fptr);
208  if (rb_io_read_pending(fptr)) {
209  rb_raise(rb_eIOError, "recvfrom for buffered IO");
210  }
211  fd = fptr->fd;
212 
213  str = rb_tainted_str_new(0, buflen);
214 
215  rb_io_check_closed(fptr);
216  rb_io_set_nonblock(fptr);
217  len0 = alen;
218  slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, &buf.addr, &alen);
219  if (slen != -1 && len0 < alen)
220  alen = len0;
221 
222  if (slen < 0) {
223  switch (errno) {
224  case EAGAIN:
225 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
226  case EWOULDBLOCK:
227 #endif
228  rb_readwrite_sys_fail(RB_IO_WAIT_READABLE, "recvfrom(2) would block");
229  }
230  rb_sys_fail("recvfrom(2)");
231  }
232  if (slen < RSTRING_LEN(str)) {
233  rb_str_set_len(str, slen);
234  }
235  rb_obj_taint(str);
236  switch (from) {
237  case RECV_RECV:
238  return str;
239 
240  case RECV_IP:
241  if (alen && alen != sizeof(buf)) /* connection-oriented socket may not return a from result */
242  addr = rsock_ipaddr(&buf.addr, alen, fptr->mode & FMODE_NOREVLOOKUP);
243  break;
244 
245  case RECV_SOCKET:
246  addr = rsock_io_socket_addrinfo(sock, &buf.addr, alen);
247  break;
248 
249  default:
250  rb_bug("rsock_s_recvfrom_nonblock called with bad value");
251  }
252  return rb_assoc_new(str, addr);
253 }
254 
255 static int
256 rsock_socket0(int domain, int type, int proto)
257 {
258  int ret;
259 
260 #ifdef SOCK_CLOEXEC
261  static int try_sock_cloexec = 1;
262  if (try_sock_cloexec) {
263  ret = socket(domain, type|SOCK_CLOEXEC, proto);
264  if (ret == -1 && errno == EINVAL) {
265  /* SOCK_CLOEXEC is available since Linux 2.6.27. Linux 2.6.18 fails with EINVAL */
266  ret = socket(domain, type, proto);
267  if (ret != -1) {
268  try_sock_cloexec = 0;
269  }
270  }
271  }
272  else {
273  ret = socket(domain, type, proto);
274  }
275 #else
276  ret = socket(domain, type, proto);
277 #endif
278  if (ret == -1)
279  return -1;
280 
281  rb_fd_fix_cloexec(ret);
282 
283  return ret;
284 
285 }
286 
287 int
288 rsock_socket(int domain, int type, int proto)
289 {
290  int fd;
291 
292  fd = rsock_socket0(domain, type, proto);
293  if (fd < 0) {
294  if (errno == EMFILE || errno == ENFILE) {
295  rb_gc();
296  fd = rsock_socket0(domain, type, proto);
297  }
298  }
299  if (0 <= fd)
301  return fd;
302 }
303 
304 static int
306 {
307  int sockerr;
308  socklen_t sockerrlen;
309  int revents;
310  int ret;
311 
312  for (;;) {
313  /*
314  * Stevens book says, succuessful finish turn on RB_WAITFD_OUT and
315  * failure finish turn on both RB_WAITFD_IN and RB_WAITFD_OUT.
316  */
318 
319  if (revents & (RB_WAITFD_IN|RB_WAITFD_OUT)) {
320  sockerrlen = (socklen_t)sizeof(sockerr);
321  ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&sockerr, &sockerrlen);
322 
323  /*
324  * Solaris getsockopt(SO_ERROR) return -1 and set errno
325  * in getsockopt(). Let's return immediately.
326  */
327  if (ret < 0)
328  break;
329  if (sockerr == 0) {
330  if (revents & RB_WAITFD_OUT)
331  break;
332  else
333  continue; /* workaround for winsock */
334  }
335 
336  /* BSD and Linux use sockerr. */
337  errno = sockerr;
338  ret = -1;
339  break;
340  }
341 
342  if ((revents & (RB_WAITFD_IN|RB_WAITFD_OUT)) == RB_WAITFD_OUT) {
343  ret = 0;
344  break;
345  }
346  }
347 
348  return ret;
349 }
350 
351 #ifdef __CYGWIN__
352 #define WAIT_IN_PROGRESS 10
353 #endif
354 #ifdef __APPLE__
355 #define WAIT_IN_PROGRESS 10
356 #endif
357 #ifdef __linux__
358 /* returns correct error */
359 #define WAIT_IN_PROGRESS 0
360 #endif
361 #ifndef WAIT_IN_PROGRESS
362 /* BSD origin code apparently has a problem */
363 #define WAIT_IN_PROGRESS 1
364 #endif
365 
366 struct connect_arg {
367  int fd;
368  const struct sockaddr *sockaddr;
370 };
371 
372 static VALUE
373 connect_blocking(void *data)
374 {
375  struct connect_arg *arg = data;
376  return (VALUE)connect(arg->fd, arg->sockaddr, arg->len);
377 }
378 
379 #if defined(SOCKS) && !defined(SOCKS5)
380 static VALUE
381 socks_connect_blocking(void *data)
382 {
383  struct connect_arg *arg = data;
384  return (VALUE)Rconnect(arg->fd, arg->sockaddr, arg->len);
385 }
386 #endif
387 
388 int
389 rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks)
390 {
391  int status;
393  struct connect_arg arg;
394 #if WAIT_IN_PROGRESS > 0
395  int wait_in_progress = -1;
396  int sockerr;
397  socklen_t sockerrlen;
398 #endif
399 
400  arg.fd = fd;
401  arg.sockaddr = sockaddr;
402  arg.len = len;
403 #if defined(SOCKS) && !defined(SOCKS5)
404  if (socks) func = socks_connect_blocking;
405 #endif
406  for (;;) {
407  status = (int)BLOCKING_REGION_FD(func, &arg);
408  if (status < 0) {
409  switch (errno) {
410  case EINTR:
411 #if defined(ERESTART)
412  case ERESTART:
413 #endif
414  continue;
415 
416  case EAGAIN:
417 #ifdef EINPROGRESS
418  case EINPROGRESS:
419 #endif
420 #if WAIT_IN_PROGRESS > 0
421  sockerrlen = (socklen_t)sizeof(sockerr);
422  status = getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&sockerr, &sockerrlen);
423  if (status) break;
424  if (sockerr) {
425  status = -1;
426  errno = sockerr;
427  break;
428  }
429 #endif
430 #ifdef EALREADY
431  case EALREADY:
432 #endif
433 #if WAIT_IN_PROGRESS > 0
434  wait_in_progress = WAIT_IN_PROGRESS;
435 #endif
436  status = wait_connectable(fd);
437  if (status) {
438  break;
439  }
440  errno = 0;
441  continue;
442 
443 #if WAIT_IN_PROGRESS > 0
444  case EINVAL:
445  if (wait_in_progress-- > 0) {
446  /*
447  * connect() after EINPROGRESS returns EINVAL on
448  * some platforms, need to check true error
449  * status.
450  */
451  sockerrlen = (socklen_t)sizeof(sockerr);
452  status = getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&sockerr, &sockerrlen);
453  if (!status && !sockerr) {
454  struct timeval tv = {0, 100000};
455  rb_thread_wait_for(tv);
456  continue;
457  }
458  status = -1;
459  errno = sockerr;
460  }
461  break;
462 #endif
463 
464 #ifdef EISCONN
465  case EISCONN:
466  status = 0;
467  errno = 0;
468  break;
469 #endif
470  default:
471  break;
472  }
473  }
474  return status;
475  }
476 }
477 
478 static void
480 {
481  int flags;
482 #ifdef F_GETFL
483  flags = fcntl(fd, F_GETFL);
484  if (flags == -1) {
485  rb_sys_fail("fnctl(2)");
486  }
487 #else
488  flags = 0;
489 #endif
490  flags |= O_NONBLOCK;
491  if (fcntl(fd, F_SETFL, flags) == -1) {
492  rb_sys_fail("fnctl(2)");
493  }
494 }
495 
496 static int
497 cloexec_accept(int socket, struct sockaddr *address, socklen_t *address_len)
498 {
499  int ret;
500  socklen_t len0 = 0;
501 #ifdef HAVE_ACCEPT4
502  static int try_accept4 = 1;
503 #endif
504  if (address_len) len0 = *address_len;
505 #ifdef HAVE_ACCEPT4
506  if (try_accept4) {
507  int flags = 0;
508 #ifdef SOCK_CLOEXEC
509  flags |= SOCK_CLOEXEC;
510 #endif
511  ret = accept4(socket, address, address_len, flags);
512  /* accept4 is available since Linux 2.6.28, glibc 2.10. */
513  if (ret != -1) {
514  if (ret <= 2)
516  if (address_len && len0 < *address_len) *address_len = len0;
517  return ret;
518  }
519  if (errno != ENOSYS) {
520  return -1;
521  }
522  try_accept4 = 0;
523  }
524 #endif
525  ret = accept(socket, address, address_len);
526  if (ret == -1) return -1;
527  if (address_len && len0 < *address_len) *address_len = len0;
529  return ret;
530 }
531 
532 
533 VALUE
534 rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
535 {
536  int fd2;
537 
538  rb_secure(3);
539  rb_io_set_nonblock(fptr);
540  fd2 = cloexec_accept(fptr->fd, (struct sockaddr*)sockaddr, len);
541  if (fd2 < 0) {
542  switch (errno) {
543  case EAGAIN:
544 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
545  case EWOULDBLOCK:
546 #endif
547  case ECONNABORTED:
548 #if defined EPROTO
549  case EPROTO:
550 #endif
551  rb_readwrite_sys_fail(RB_IO_WAIT_READABLE, "accept(2) would block");
552  }
553  rb_sys_fail("accept(2)");
554  }
555  rb_update_max_fd(fd2);
556  make_fd_nonblock(fd2);
557  return rsock_init_sock(rb_obj_alloc(klass), fd2);
558 }
559 
560 struct accept_arg {
561  int fd;
564 };
565 
566 static VALUE
567 accept_blocking(void *data)
568 {
569  struct accept_arg *arg = data;
570  return (VALUE)cloexec_accept(arg->fd, arg->sockaddr, arg->len);
571 }
572 
573 VALUE
575 {
576  int fd2;
577  int retry = 0;
578  struct accept_arg arg;
579 
580  rb_secure(3);
581  arg.fd = fd;
582  arg.sockaddr = sockaddr;
583  arg.len = len;
584  retry:
586  fd2 = (int)BLOCKING_REGION_FD(accept_blocking, &arg);
587  if (fd2 < 0) {
588  switch (errno) {
589  case EMFILE:
590  case ENFILE:
591  if (retry) break;
592  rb_gc();
593  retry = 1;
594  goto retry;
595  default:
596  if (!rb_io_wait_readable(fd)) break;
597  retry = 0;
598  goto retry;
599  }
600  rb_sys_fail("accept(2)");
601  }
602  rb_update_max_fd(fd2);
603  if (!klass) return INT2NUM(fd2);
604  return rsock_init_sock(rb_obj_alloc(klass), fd2);
605 }
606 
607 int
608 rsock_getfamily(int sockfd)
609 {
610  union_sockaddr ss;
611  socklen_t sslen = (socklen_t)sizeof(ss);
612 
613  ss.addr.sa_family = AF_UNSPEC;
614  if (getsockname(sockfd, &ss.addr, &sslen) < 0)
615  return AF_UNSPEC;
616 
617  return ss.addr.sa_family;
618 }
619 
620 void
622 {
623  /*
624  * SocketError is the error class for socket.
625  */
626  rb_eSocket = rb_define_class("SocketError", rb_eStandardError);
639 }
void rb_gc(void)
Definition: gc.c:5193
VALUE rb_eStandardError
Definition: error.c:546
struct sockaddr * sockaddr
Definition: init.c:562
void rb_bug(const char *fmt,...)
Definition: error.c:327
socklen_t tolen
Definition: rubysocket.h:322
#define FMODE_READWRITE
Definition: io.h:103
VALUE rsock_sendto_blocking(void *data)
Definition: init.c:76
#define INT2NUM(x)
Definition: ruby.h:1296
void rb_update_max_fd(int fd)
Definition: io.c:183
void rb_io_set_nonblock(rb_io_t *fptr)
Definition: io.c:2378
void rb_io_synchronized(rb_io_t *)
Definition: io.c:5666
VALUE rb_cBasicSocket
Definition: init.c:13
#define NUM2INT(x)
Definition: ruby.h:630
socklen_t * len
Definition: init.c:563
Definition: io.h:61
VALUE rb_eTypeError
Definition: error.c:548
VALUE rsock_init_sock(VALUE sock, int fd)
Definition: init.c:43
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:113
int fcntl(int, int,...)
Definition: win32.c:4089
void rsock_init_unixsocket(void)
Definition: unixsocket.c:506
VALUE str
Definition: init.c:95
void rb_str_set_len(VALUE, long)
Definition: string.c:2007
void rsock_init_tcpserver(void)
Definition: tcpserver.c:139
VALUE rb_cIPSocket
Definition: init.c:14
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1857
struct sockaddr * to
Definition: rubysocket.h:321
VALUE rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
Definition: init.c:574
sock_recv_type
Definition: rubysocket.h:329
#define FMODE_DUPLEX
Definition: io.h:107
#define FMODE_NOREVLOOKUP
Definition: rubysocket.h:229
void rsock_init_sockifaddr(void)
Definition: ifaddr.c:437
void rsock_init_socket_constants(void)
Definition: constants.c:141
static void make_fd_nonblock(int fd)
Definition: init.c:479
VALUE rsock_ipaddr(struct sockaddr *sockaddr, socklen_t sockaddrlen, int norevlookup)
Definition: raddrinfo.c:505
int rsock_getfamily(int sockfd)
Definition: init.c:608
#define EINPROGRESS
Definition: win32.h:512
#define GetOpenFile(obj, fp)
Definition: io.h:118
void rsock_init_addrinfo(void)
Definition: raddrinfo.c:2509
VALUE rb_cTCPSocket
Definition: init.c:15
VALUE rsock_io_socket_addrinfo(VALUE io, struct sockaddr *addr, socklen_t len)
Definition: raddrinfo.c:2483
int rb_w32_is_socket(int)
Definition: win32.c:2415
#define RB_WAITFD_OUT
Definition: io.h:49
int mode
Definition: io.h:64
int fd
Definition: init.c:561
union_sockaddr buf
Definition: init.c:97
void rsock_init_tcpsocket(void)
Definition: tcpsocket.c:59
VALUE rb_obj_taint(VALUE)
Definition: object.c:967
#define F_SETFL
Definition: win32.h:622
VALUE rb_eRuntimeError
Definition: error.c:547
void rsock_init_sockssocket(void)
Definition: sockssocket.c:55
#define ECONNABORTED
Definition: win32.h:563
socklen_t len
Definition: init.c:369
VALUE rsock_send_blocking(void *data)
Definition: init.c:85
#define EALREADY
Definition: win32.h:515
int rsock_socket(int domain, int type, int proto)
Definition: init.c:288
#define WAIT_IN_PROGRESS
Definition: init.c:363
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:611
int fd
Definition: io.h:62
int argc
Definition: ruby.c:131
void rsock_init_ancdata(void)
Definition: ancdata.c:1800
static int wait_connectable(int fd)
Definition: init.c:305
VALUE rb_obj_alloc(VALUE)
Definition: object.c:1804
#define EAI_SYSTEM
Definition: addrinfo.h:88
void rsock_init_socket_init()
Definition: init.c:621
VALUE rb_obj_reveal(VALUE obj, VALUE klass)
Definition: object.c:62
VALUE rb_cSocket
Definition: init.c:22
char * gai_strerror(int ecode)
Definition: getaddrinfo.c:206
#define RSTRING_LEN(str)
Definition: ruby.h:841
int errno
int socklen_t
Definition: getaddrinfo.c:84
VALUE rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
Definition: init.c:114
static int rsock_socket0(int domain, int type, int proto)
Definition: init.c:256
static int cloexec_accept(int socket, struct sockaddr *address, socklen_t *address_len)
Definition: init.c:497
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1719
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4308
VALUE rb_assoc_new(VALUE car, VALUE cdr)
Definition: array.c:620
void rb_thread_wait_fd(int)
Definition: thread.c:3523
void rsock_init_udpsocket(void)
Definition: udpsocket.c:251
#define Qnil
Definition: ruby.h:427
VALUE rb_cTCPServer
Definition: init.c:16
int rsock_do_not_reverse_lookup
Definition: init.c:31
int type
Definition: tcltklib.c:112
unsigned long VALUE
Definition: ruby.h:88
#define RBASIC(obj)
Definition: ruby.h:1116
void rb_readwrite_sys_fail(int writable, const char *mesg)
Definition: io.c:11704
VALUE rb_obj_hide(VALUE obj)
Definition: object.c:53
#define RB_IO_WAIT_READABLE
Definition: ruby.h:1515
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv)
Definition: thread.c:3779
int fd
Definition: init.c:94
VALUE rb_blocking_function_t(void *)
Definition: intern.h:865
void rb_sys_fail(const char *mesg)
Definition: error.c:1976
int rb_reserved_fd_p(int fd)
const struct sockaddr * sockaddr
Definition: init.c:368
#define RSTRING_PTR(str)
Definition: ruby.h:845
VALUE rb_eSocket
Definition: init.c:25
void rb_thread_wait_for(struct timeval)
Definition: thread.c:1119
int rb_io_read_pending(rb_io_t *)
Definition: io.c:830
#define EISCONN
Definition: win32.h:572
void rb_fd_fix_cloexec(int fd)
Definition: io.c:221
#define proto(p)
Definition: sdbm.h:60
void rsock_raise_socket_error(const char *reason, int error)
Definition: init.c:34
VALUE rb_io_ascii8bit_binmode(VALUE)
Definition: io.c:4748
int rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks)
Definition: init.c:389
VALUE rb_cAddrinfo
Definition: init.c:23
#define O_NONBLOCK
Definition: win32.h:626
#define AF_UNSPEC
Definition: sockport.h:101
#define EWOULDBLOCK
Definition: rubysocket.h:126
static VALUE connect_blocking(void *data)
Definition: init.c:373
VALUE rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
Definition: init.c:534
static VALUE accept_blocking(void *data)
Definition: init.c:567
void rsock_init_ipsocket(void)
Definition: ipsocket.c:322
socklen_t alen
Definition: init.c:96
void rsock_init_unixserver(void)
Definition: unixserver.c:139
RUBY_EXTERN VALUE rb_eIOError
Definition: ruby.h:1611
#define MakeOpenFile(obj, fp)
Definition: io.h:127
static VALUE recvfrom_blocking(void *data)
Definition: init.c:101
void rb_secure(int)
Definition: safe.c:88
void rsock_init_sockopt(void)
Definition: option.c:1092
#define RB_WAITFD_IN
Definition: io.h:47
VALUE rb_tainted_str_new(const char *, long)
Definition: string.c:589
#define fstat(fd, st)
Definition: win32.h:214
#define stat(path, st)
Definition: win32.h:213
#define NULL
Definition: _sdbm.c:102
VALUE rsock_s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
Definition: init.c:182
int flags
Definition: init.c:94
int rb_io_wait_readable(int)
Definition: io.c:1077
void rb_io_check_closed(rb_io_t *)
Definition: io.c:617
#define BLOCKING_REGION_FD(func, arg)
Definition: rubysocket.h:259
void rb_maygvl_fd_fix_cloexec(int fd)
Definition: io.c:198
int fd
Definition: init.c:367
char ** argv
Definition: ruby.c:132
struct sockaddr addr
Definition: rubysocket.h:185
VALUE rb_cUDPSocket
Definition: init.c:17