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