Ruby 2.1.5p273(2014-11-13revision48405)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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