Ruby 2.0.0p353(2013-11-22revision43784)

- 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(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;
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 struct sockaddr_storage buf;
95 };
96
97 static VALUE
98 recvfrom_blocking(void *data)
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
106 rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
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
174 rsock_s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
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
293 wait_connectable(int fd)
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 */
305 revents = rb_wait_for_single_fd(fd, RB_WAITFD_IN|RB_WAITFD_OUT, NULL);
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
357 connect_blocking(void *data)
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;
376 rb_blocking_function_t *func = connect_blocking;
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
463 make_fd_nonblock(int fd)
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 int flags = 0;
492 #ifdef SOCK_CLOEXEC
493 flags |= SOCK_CLOEXEC;
494 #endif
495 ret = accept4(socket, address, address_len, flags);
496 /* accept4 is available since Linux 2.6.28, glibc 2.10. */
497 if (ret != -1) {
498 if (ret <= 2)
499 rb_maygvl_fd_fix_cloexec(ret);
500 if (address_len && len0 < *address_len) *address_len = len0;
501 return ret;
502 }
503 if (errno != ENOSYS) {
504 return -1;
505 }
506 try_accept4 = 0;
507 }
508 #endif
509 ret = accept(socket, address, address_len);
510 if (ret == -1) return -1;
511 if (address_len && len0 < *address_len) *address_len = len0;
512 rb_maygvl_fd_fix_cloexec(ret);
513 return ret;
514 }
515
516
517 VALUE
518 rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
519 {
520 int fd2;
521
522 rb_secure(3);
523 rb_io_set_nonblock(fptr);
524 fd2 = cloexec_accept(fptr->fd, (struct sockaddr*)sockaddr, len);
525 if (fd2 < 0) {
526 switch (errno) {
527 case EAGAIN:
528 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
529 case EWOULDBLOCK:
530 #endif
531 case ECONNABORTED:
532 #if defined EPROTO
533 case EPROTO:
534 #endif
535 rb_mod_sys_fail(rb_mWaitReadable, "accept(2) would block");
536 }
537 rb_sys_fail("accept(2)");
538 }
539 rb_update_max_fd(fd2);
540 make_fd_nonblock(fd2);
541 return rsock_init_sock(rb_obj_alloc(klass), fd2);
542 }
543
544 struct accept_arg {
545 int fd;
546 struct sockaddr *sockaddr;
547 socklen_t *len;
548 };
549
550 static VALUE
551 accept_blocking(void *data)
552 {
553 struct accept_arg *arg = data;
554 return (VALUE)cloexec_accept(arg->fd, arg->sockaddr, arg->len);
555 }
556
557 VALUE
558 rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
559 {
560 int fd2;
561 int retry = 0;
562 struct accept_arg arg;
563
564 rb_secure(3);
565 arg.fd = fd;
566 arg.sockaddr = sockaddr;
567 arg.len = len;
568 retry:
569 rb_thread_wait_fd(fd);
570 fd2 = (int)BLOCKING_REGION_FD(accept_blocking, &arg);
571 if (fd2 < 0) {
572 switch (errno) {
573 case EMFILE:
574 case ENFILE:
575 if (retry) break;
576 rb_gc();
577 retry = 1;
578 goto retry;
579 default:
580 if (!rb_io_wait_readable(fd)) break;
581 retry = 0;
582 goto retry;
583 }
584 rb_sys_fail(0);
585 }
586 rb_update_max_fd(fd2);
587 if (!klass) return INT2NUM(fd2);
588 return rsock_init_sock(rb_obj_alloc(klass), fd2);
589 }
590
591 int
592 rsock_getfamily(int sockfd)
593 {
594 struct sockaddr_storage ss;
595 socklen_t sslen = (socklen_t)sizeof(ss);
596
597 ss.ss_family = AF_UNSPEC;
598 if (getsockname(sockfd, (struct sockaddr*)&ss, &sslen) < 0)
599 return AF_UNSPEC;
600
601 return ss.ss_family;
602 }
603
604 void
605 rsock_init_socket_init()
606 {
607 /*
608 * SocketError is the error class for socket.
609 */
610 rb_eSocket = rb_define_class("SocketError", rb_eStandardError);
611 rsock_init_ipsocket();
612 rsock_init_tcpsocket();
613 rsock_init_tcpserver();
614 rsock_init_sockssocket();
615 rsock_init_udpsocket();
616 rsock_init_unixsocket();
617 rsock_init_unixserver();
618 rsock_init_sockopt();
619 rsock_init_ancdata();
620 rsock_init_addrinfo();
621 rsock_init_socket_constants();
622 }
data
VALUE data
Definition: tcltklib.c:3368
rb_eStandardError
VALUE rb_eStandardError
Definition: error.c:509
int
VP_EXPORT int
Definition: bigdecimal.c:5050
accept_arg::sockaddr
struct sockaddr * sockaddr
Definition: init.c:546
rb_bug
void rb_bug(const char *fmt,...)
Definition: error.c:290
rsock_send_arg::tolen
socklen_t tolen
Definition: rubysocket.h:256
FMODE_READWRITE
#define FMODE_READWRITE
Definition: io.h:105
rsock_sendto_blocking
VALUE rsock_sendto_blocking(void *data)
Definition: init.c:73
rb_io_set_nonblock
void rb_io_set_nonblock(rb_io_t *fptr)
Definition: io.c:2338
rb_thread_wait_fd
void rb_thread_wait_fd(int)
Definition: thread.c:3431
rb_io_synchronized
void rb_io_synchronized(rb_io_t *)
Definition: io.c:5544
rb_cBasicSocket
VALUE rb_cBasicSocket
Definition: init.c:13
accept_arg::len
socklen_t * len
Definition: init.c:547
rb_blocking_function_t
VALUE rb_blocking_function_t(void *)
Definition: ripper.y:836
func
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:108
rb_mWaitReadable
RUBY_EXTERN VALUE rb_mWaitReadable
Definition: ripper.y:1422
rb_secure
void rb_secure(int)
Definition: safe.c:79
rb_io_t
Definition: io.h:63
ret
int ret
Definition: tcltklib.c:280
rsock_ipaddr
VALUE rsock_ipaddr(struct sockaddr *sockaddr, int norevlookup)
Definition: raddrinfo.c:383
status
int status
Definition: tcltklib.c:2197
rb_eTypeError
VALUE rb_eTypeError
Definition: error.c:511
rb_update_max_fd
void rb_update_max_fd(int fd)
Definition: io.c:164
rsock_init_sock
VALUE rsock_init_sock(VALUE sock, int fd)
Definition: init.c:43
fcntl
int fcntl(int, int,...)
Definition: win32.c:3835
rsock_init_unixsocket
void rsock_init_unixsocket(void)
Definition: unixsocket.c:507
recvfrom_arg::str
VALUE str
Definition: init.c:92
RSTRING_PTR
#define RSTRING_PTR(str)
RECV_RECV
Definition: rubysocket.h:264
rsock_init_tcpserver
void rsock_init_tcpserver(void)
Definition: tcpserver.c:132
rb_cIPSocket
VALUE rb_cIPSocket
Definition: init.c:14
accept_arg
Definition: init.c:544
rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1780
rsock_send_arg::to
struct sockaddr * to
Definition: rubysocket.h:255
rsock_s_accept
VALUE rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
Definition: init.c:558
sock_recv_type
sock_recv_type
Definition: rubysocket.h:263
FMODE_DUPLEX
#define FMODE_DUPLEX
Definition: io.h:109
rb_eIOError
RUBY_EXTERN VALUE rb_eIOError
Definition: ripper.y:1476
rsock_send_arg::mesg
VALUE mesg
Definition: rubysocket.h:254
FMODE_NOREVLOOKUP
#define FMODE_NOREVLOOKUP
Definition: rubysocket.h:176
rsock_init_socket_constants
void rsock_init_socket_constants(void)
Definition: constants.c:141
rsock_send_arg::fd
int fd
Definition: rubysocket.h:253
make_fd_nonblock
static void make_fd_nonblock(int fd)
Definition: init.c:463
rsock_getfamily
int rsock_getfamily(int sockfd)
Definition: init.c:592
EINPROGRESS
#define EINPROGRESS
Definition: win32.h:477
GetOpenFile
#define GetOpenFile(obj, fp)
Definition: io.h:120
rsock_init_addrinfo
void rsock_init_addrinfo(void)
Definition: raddrinfo.c:2201
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:2175
rb_fd_fix_cloexec
void rb_fd_fix_cloexec(int fd)
Definition: io.c:202
rb_w32_is_socket
int rb_w32_is_socket(int)
Definition: win32.c:2309
RB_WAITFD_OUT
#define RB_WAITFD_OUT
Definition: io.h:49
rb_io_t::mode
int mode
Definition: io.h:66
accept_arg::fd
int fd
Definition: init.c:545
rb_gc
void rb_gc(void)
Definition: gc.c:3108
rsock_send_arg
Definition: rubysocket.h:252
rsock_init_tcpsocket
void rsock_init_tcpsocket(void)
Definition: tcpsocket.c:59
F_SETFL
#define F_SETFL
Definition: win32.h:587
Qnil
#define Qnil
Definition: tcltklib.c:1896
rb_eRuntimeError
VALUE rb_eRuntimeError
Definition: error.c:510
rsock_init_sockssocket
void rsock_init_sockssocket(void)
Definition: sockssocket.c:55
ECONNABORTED
#define ECONNABORTED
Definition: win32.h:528
connect_arg::len
socklen_t len
Definition: init.c:353
str
static VALUE char * str
Definition: tcltklib.c:3547
rsock_send_blocking
VALUE rsock_send_blocking(void *data)
Definition: init.c:82
flags
int flags
Definition: tcltklib.c:3023
EALREADY
#define EALREADY
Definition: win32.h:480
rsock_socket
int rsock_socket(int domain, int type, int proto)
Definition: init.c:276
WAIT_IN_PROGRESS
#define WAIT_IN_PROGRESS
Definition: init.c:347
rb_define_class
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:499
recvfrom_arg
Definition: init.c:90
RSTRING_LEN
#define RSTRING_LEN(str)
rb_io_t::fd
int fd
Definition: io.h:64
rsock_init_ancdata
void rsock_init_ancdata(void)
Definition: ancdata.c:1792
wait_connectable
static int wait_connectable(int fd)
Definition: init.c:293
rb_maygvl_fd_fix_cloexec
void rb_maygvl_fd_fix_cloexec(int fd)
Definition: io.c:179
EAI_SYSTEM
#define EAI_SYSTEM
Definition: addrinfo.h:88
rsock_init_socket_init
void rsock_init_socket_init()
Definition: init.c:605
sockaddr_storage::ss_family
unsigned short ss_family
Definition: rubysocket.h:139
rb_cSocket
VALUE rb_cSocket
Definition: init.c:22
gai_strerror
char * gai_strerror(int ecode)
Definition: getaddrinfo.c:202
argv
VALUE * argv
Definition: tcltklib.c:1971
rb_tainted_str_new
VALUE rb_tainted_str_new(const char *, long)
timeval
Definition: ossl_asn1.c:16
errno
int errno
rsock_s_recvfrom
VALUE rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
Definition: init.c:106
rsock_socket0
static int rsock_socket0(int domain, int type, int proto)
Definition: init.c:244
cloexec_accept
static int cloexec_accept(int socket, struct sockaddr *address, socklen_t *address_len)
Definition: init.c:481
rb_scan_args
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1570
rb_assoc_new
VALUE rb_assoc_new(VALUE car, VALUE cdr)
Definition: array.c:545
rsock_init_udpsocket
void rsock_init_udpsocket(void)
Definition: udpsocket.c:250
sockaddr_storage
Definition: rubysocket.h:134
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:111
rb_io_ascii8bit_binmode
VALUE rb_io_ascii8bit_binmode(VALUE)
Definition: io.c:4623
argc
int argc
Definition: tcltklib.c:1970
rb_wait_for_single_fd
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv)
Definition: thread.c:3687
recvfrom_arg::fd
int fd
Definition: init.c:91
connect_arg
Definition: init.c:350
rb_sys_fail
void rb_sys_fail(const char *mesg)
Definition: error.c:1899
connect_arg::sockaddr
struct sockaddr * sockaddr
Definition: init.c:352
rb_obj_taint
VALUE rb_obj_taint(VALUE)
Definition: object.c:878
rb_eSocket
VALUE rb_eSocket
Definition: init.c:25
arg
arg
Definition: ripper.y:1315
rb_io_read_pending
int rb_io_read_pending(rb_io_t *)
Definition: io.c:817
rubysocket.h
rb_thread_wait_for
void rb_thread_wait_for(struct timeval)
Definition: thread.c:1066
EISCONN
#define EISCONN
Definition: win32.h:537
recvfrom_arg::buf
struct sockaddr_storage buf
Definition: init.c:94
rb_mod_sys_fail
void rb_mod_sys_fail(VALUE mod, const char *mesg)
Definition: error.c:1911
RECV_IP
Definition: rubysocket.h:265
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
RBASIC
#define RBASIC(obj)
rsock_connect
int rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks)
Definition: init.c:373
rb_cAddrinfo
VALUE rb_cAddrinfo
Definition: init.c:23
O_NONBLOCK
#define O_NONBLOCK
Definition: win32.h:591
RECV_UNIX
Definition: rubysocket.h:266
AF_UNSPEC
#define AF_UNSPEC
Definition: sockport.h:69
klass
klass
Definition: tcltklib.c:3504
INT2NUM
#define INT2NUM(x)
EWOULDBLOCK
#define EWOULDBLOCK
Definition: rubysocket.h:90
connect_blocking
static VALUE connect_blocking(void *data)
Definition: init.c:357
rsock_s_accept_nonblock
VALUE rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
Definition: init.c:518
rsock_send_arg::flags
int flags
Definition: rubysocket.h:253
accept_blocking
static VALUE accept_blocking(void *data)
Definition: init.c:551
rsock_init_ipsocket
void rsock_init_ipsocket(void)
Definition: ipsocket.c:292
recvfrom_arg::alen
socklen_t alen
Definition: init.c:93
rsock_init_unixserver
void rsock_init_unixserver(void)
Definition: unixserver.c:139
NUM2INT
#define NUM2INT(x)
rb_obj_alloc
VALUE rb_obj_alloc(VALUE)
Definition: object.c:1721
MakeOpenFile
#define MakeOpenFile(obj, fp)
Definition: io.h:129
RECV_SOCKET
Definition: rubysocket.h:267
recvfrom_blocking
static VALUE recvfrom_blocking(void *data)
Definition: init.c:98
VALUE
unsigned long VALUE
Definition: ripper.y:104
rsock_init_sockopt
void rsock_init_sockopt(void)
Definition: option.c:893
RB_WAITFD_IN
#define RB_WAITFD_IN
Definition: io.h:47
fstat
#define fstat(fd, st)
Definition: win32.h:194
stat
#define stat(path, st)
Definition: win32.h:193
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:174
recvfrom_arg::flags
int flags
Definition: init.c:91
rb_io_wait_readable
int rb_io_wait_readable(int)
Definition: io.c:1064
retry
int retry
Definition: tcltklib.c:10151
rb_io_check_closed
void rb_io_check_closed(rb_io_t *)
Definition: io.c:604
rb_eArgError
VALUE rb_eArgError
Definition: error.c:512
BLOCKING_REGION_FD
#define BLOCKING_REGION_FD(func, arg)
Definition: rubysocket.h:206
connect_arg::fd
int fd
Definition: init.c:351
rb_cUDPSocket
VALUE rb_cUDPSocket
Definition: init.c:17
len
size_t len
Definition: tcltklib.c:3568
rb_str_set_len
void rb_str_set_len(VALUE, long)
Definition: string.c:1837