Ruby
2.5.0dev(2017-10-22revision60238)
|
#include "ruby/ruby.h"
#include "ruby/io.h"
#include "ruby/thread.h"
#include "ruby/util.h"
#include "internal.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
#include "addrinfo.h"
#include "sockport.h"
#include "constdefs.h"
Go to the source code of this file.
Data Structures | |
struct | sockaddr_storage |
union | union_sockaddr |
struct | rb_addrinfo |
struct | rsock_send_arg |
Typedefs | |
typedef int | socklen_t |
Enumerations | |
enum | sock_recv_type { RECV_RECV, RECV_IP, RECV_UNIX, RECV_SOCKET } |
#define _SS_ALIGNSIZE (sizeof(double)) |
Definition at line 168 of file rubysocket.h.
#define _SS_MAXSIZE 128 |
Definition at line 167 of file rubysocket.h.
#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(unsigned char) * 2) |
Definition at line 169 of file rubysocket.h.
#define _SS_PAD2SIZE |
Definition at line 170 of file rubysocket.h.
#define BLOCKING_REGION_FD | ( | func, | |
arg | |||
) | (long)rb_thread_io_blocking_region((func), (arg), (arg)->fd) |
Definition at line 262 of file rubysocket.h.
Referenced by rsock_bsock_send(), and rsock_s_accept().
#define EWOULDBLOCK EAGAIN |
Definition at line 128 of file rubysocket.h.
Referenced by rb_w32_strerror().
#define FMODE_INET 0x00400000 |
Definition at line 231 of file rubysocket.h.
Referenced by rsock_getfamily().
#define FMODE_INET6 0x00800000 |
Definition at line 232 of file rubysocket.h.
Referenced by rsock_getfamily().
#define FMODE_NOREVLOOKUP 0x100 |
Definition at line 227 of file rubysocket.h.
Referenced by rsock_init_sock().
#define FMODE_SOCK (FMODE_UNIX|FMODE_INET|FMODE_INET6) |
Definition at line 233 of file rubysocket.h.
Referenced by rsock_getfamily().
#define FMODE_UNIX 0x00200000 |
Definition at line 230 of file rubysocket.h.
Referenced by rsock_getfamily().
#define IN6_IS_ADDR_UNIQUE_LOCAL | ( | a | ) | (((a)->s6_addr[0] == 0xfc) || ((a)->s6_addr[0] == 0xfd)) |
Definition at line 160 of file rubysocket.h.
#define INET_CLIENT 0 |
Definition at line 221 of file rubysocket.h.
#define INET_SERVER 1 |
Definition at line 222 of file rubysocket.h.
#define INET_SOCKS 2 |
Definition at line 223 of file rubysocket.h.
#define IS_IP_FAMILY | ( | af | ) | ((af) == AF_INET) |
Definition at line 156 of file rubysocket.h.
Referenced by rsock_cmsg_type_arg(), rsock_level_arg(), and rsock_optname_arg().
#define MSG_DONTWAIT_RELIABLE 0 |
Definition at line 430 of file rubysocket.h.
#define pseudo_AF_FTIP pseudo_AF_RTIP |
Definition at line 138 of file rubysocket.h.
#define rsock_bsock_recvmsg rb_f_notimplement |
Definition at line 371 of file rubysocket.h.
#define rsock_bsock_recvmsg_nonblock rb_f_notimplement |
Definition at line 372 of file rubysocket.h.
#define rsock_bsock_sendmsg rb_f_notimplement |
Definition at line 360 of file rubysocket.h.
#define rsock_bsock_sendmsg_nonblock rb_f_notimplement |
Definition at line 361 of file rubysocket.h.
#define rsock_maybe_fd_writable | ( | fd | ) | rb_thread_fd_writable((fd)) |
Definition at line 421 of file rubysocket.h.
Referenced by rsock_bsock_send().
#define rsock_maybe_wait_fd | ( | fd | ) | rb_thread_wait_fd((fd)) |
Definition at line 422 of file rubysocket.h.
Referenced by rsock_s_accept().
#define RSTRING_SOCKLEN (socklen_t)RSTRING_LENINT |
Definition at line 124 of file rubysocket.h.
Referenced by rsock_bsock_send(), and rsock_ipaddr().
#define SockAddrStringValue | ( | v | ) | rsock_sockaddr_string_value(&(v)) |
Definition at line 264 of file rubysocket.h.
Referenced by rsock_bsock_send().
#define SockAddrStringValuePtr | ( | v | ) | rsock_sockaddr_string_value_ptr(&(v)) |
Definition at line 265 of file rubysocket.h.
#define SockAddrStringValueWithAddrinfo | ( | v, | |
rai_ret | |||
) | rsock_sockaddr_string_value_with_addrinfo(&(v), &(rai_ret)) |
Definition at line 266 of file rubysocket.h.
#define SOCKLEN_MAX |
Definition at line 118 of file rubysocket.h.
Referenced by rsock_ipaddr().
typedef int socklen_t |
Definition at line 108 of file rubysocket.h.
enum sock_recv_type |
Enumerator | |
---|---|
RECV_RECV | |
RECV_IP | |
RECV_UNIX | |
RECV_SOCKET |
Definition at line 334 of file rubysocket.h.
NORETURN | ( | void | rsock_raise_socket_errorconst char *, int | ) |
NORETURN | ( | void | rsock_syserr_fail_host_portint err, const char *, VALUE, VALUE | ) |
NORETURN | ( | void | rsock_syserr_fail_pathint err, const char *, VALUE | ) |
NORETURN | ( | void | rsock_syserr_fail_sockaddrint err, const char *mesg, struct sockaddr *addr, socklen_t len | ) |
NORETURN | ( | void | rsock_syserr_fail_raddrinfoint err, const char *mesg, VALUE rai | ) |
NORETURN | ( | void | rsock_syserr_fail_raddrinfo_or_sockaddrint err, const char *mesg, VALUE addr, VALUE rai | ) |
NORETURN | ( | void | rsock_sys_fail_host_portconst char *, VALUE, VALUE | ) |
NORETURN | ( | void | rsock_sys_fail_pathconst char *, VALUE | ) |
NORETURN | ( | void | rsock_sys_fail_sockaddrconst char *, struct sockaddr *addr, socklen_t len | ) |
NORETURN | ( | void | rsock_sys_fail_raddrinfoconst char *, VALUE rai | ) |
NORETURN | ( | void | rsock_sys_fail_raddrinfo_or_sockaddrconst char *, VALUE addr, VALUE rai | ) |
Definition at line 2507 of file raddrinfo.c.
References IS_ADDRINFO.
void rb_freeaddrinfo | ( | struct rb_addrinfo * | ai | ) |
Definition at line 322 of file raddrinfo.c.
References rb_addrinfo::ai, addrinfo::ai_addr, addrinfo::ai_next, rb_addrinfo::allocated_by_malloc, freeaddrinfo(), and xfree().
Referenced by rsock_freeaddrinfo().
int rb_getaddrinfo | ( | const char * | node, |
const char * | service, | ||
const struct addrinfo * | hints, | ||
struct rb_addrinfo ** | res | ||
) |
Definition at line 288 of file raddrinfo.c.
int rb_getnameinfo | ( | const struct sockaddr * | sa, |
socklen_t | salen, | ||
char * | host, | ||
size_t | hostlen, | ||
char * | serv, | ||
size_t | servlen, | ||
int | flags | ||
) |
Definition at line 363 of file raddrinfo.c.
References getnameinfo_arg::flags, getnameinfo(), getnameinfo_arg::host, getnameinfo_arg::hostlen, rb_thread_call_without_gvl(), getnameinfo_arg::sa, getnameinfo_arg::salen, getnameinfo_arg::serv, and getnameinfo_arg::servlen.
Referenced by rsock_ipaddr().
struct rb_addrinfo* rsock_addrinfo | ( | VALUE | host, |
VALUE | port, | ||
int | family, | ||
int | socktype, | ||
int | flags | ||
) |
Definition at line 547 of file raddrinfo.c.
References addrinfo::ai_family, addrinfo::ai_flags, addrinfo::ai_socktype, MEMZERO, and rsock_getaddrinfo().
Definition at line 1517 of file raddrinfo.c.
Referenced by rsock_syserr_fail_raddrinfo().
VALUE rsock_addrinfo_new | ( | struct sockaddr * | addr, |
socklen_t | len, | ||
int | family, | ||
int | socktype, | ||
int | protocol, | ||
VALUE | canonname, | ||
VALUE | inspectname | ||
) |
Definition at line 798 of file raddrinfo.c.
Referenced by rsock_syserr_fail_sockaddr().
Definition at line 528 of file basicsocket.c.
References BLOCKING_REGION_FD, rb_io_t::fd, rsock_send_arg::fd, rsock_send_arg::flags, GetOpenFile, rsock_send_arg::mesg, NIL_P, NUM2INT, rb_io_wait_writable(), rb_scan_args(), rb_str_new4, rb_sys_fail(), rsock_maybe_fd_writable, rsock_send_blocking(), rsock_sendto_blocking(), RSTRING_PTR, RSTRING_SOCKLEN, SockAddrStringValue, SSIZET2NUM, StringValue, rsock_send_arg::to, and rsock_send_arg::tolen.
int rsock_cmsg_type_arg | ( | int | family, |
int | level, | ||
VALUE | type | ||
) |
Definition at line 100 of file constants.c.
References IS_IP_FAMILY.
int rsock_connect | ( | int | fd, |
const struct sockaddr * | sockaddr, | ||
int | len, | ||
int | socks | ||
) |
int rsock_detect_cloexec | ( | int | fd | ) |
Definition at line 284 of file init.c.
References errno, F_GETFD, fcntl(), FD_CLOEXEC, recvfrom_arg::flags, rb_bug(), and strerror().
int rsock_family_arg | ( | VALUE | domain | ) |
Definition at line 43 of file constants.c.
int rsock_fd_family | ( | int | fd | ) |
Definition at line 534 of file raddrinfo.c.
Definition at line 2515 of file raddrinfo.c.
Referenced by rsock_io_socket_addrinfo().
Definition at line 696 of file raddrinfo.c.
References Qnil, and rb_freeaddrinfo().
struct rb_addrinfo* rsock_getaddrinfo | ( | VALUE | host, |
VALUE | port, | ||
struct addrinfo * | hints, | ||
int | socktype_hack | ||
) |
Definition at line 506 of file raddrinfo.c.
References NI_MAXHOST, NI_MAXSERV, and NULL.
Referenced by rsock_addrinfo().
int rsock_getfamily | ( | rb_io_t * | fptr | ) |
Definition at line 630 of file init.c.
References union_sockaddr::addr, AF_UNSPEC, rb_io_t::fd, FMODE_INET, FMODE_INET6, FMODE_SOCK, FMODE_UNIX, and rb_io_t::mode.
void rsock_init_addrinfo | ( | void | ) |
Definition at line 2560 of file raddrinfo.c.
References rb_cAddrinfo, rb_cData, rb_define_alloc_func(), and rb_define_class().
Referenced by rsock_init_socket_init().
void rsock_init_ancdata | ( | void | ) |
Definition at line 1695 of file ancdata.c.
References rb_cObject, rb_cSocket, rb_define_class_under(), rb_define_method(), and rb_define_singleton_method().
Referenced by rsock_init_socket_init().
void rsock_init_basicsocket | ( | void | ) |
Definition at line 692 of file basicsocket.c.
References rb_cBasicSocket, rb_cIO, rb_define_class(), rb_define_singleton_method(), and rb_undef_method().
Referenced by Init_socket().
VALUE rsock_init_inetsock | ( | VALUE | sock, |
VALUE | remote_host, | ||
VALUE | remote_serv, | ||
VALUE | local_host, | ||
VALUE | local_serv, | ||
int | type | ||
) |
Definition at line 152 of file ipsocket.c.
References inetsock_arg::fd, inetsock_arg::host, inetsock_arg::local, rb_ensure(), inetsock_arg::remote, inetsock_arg::res, inetsock_arg::serv, inetsock_arg::sock, and inetsock_arg::type.
void rsock_init_ipsocket | ( | void | ) |
Definition at line 364 of file ipsocket.c.
References rb_cBasicSocket, rb_cIPSocket, rb_define_class(), and rb_define_method().
Referenced by rsock_init_socket_init().
Definition at line 60 of file init.c.
References rb_io_t::fd, FMODE_DUPLEX, FMODE_NOREVLOOKUP, FMODE_READWRITE, is_socket, MakeOpenFile, rb_io_t::mode, rb_io_ascii8bit_binmode(), rb_io_synchronized(), rb_reserved_fd_p(), rb_syserr_fail(), rb_update_max_fd(), and rsock_do_not_reverse_lookup.
void rsock_init_socket_constants | ( | void | ) |
Definition at line 141 of file constants.c.
Referenced by rsock_init_socket_init().
void rsock_init_socket_init | ( | void | ) |
Definition at line 662 of file init.c.
References rb_define_class(), rb_eSocket, rb_eStandardError, rsock_init_addrinfo(), rsock_init_ancdata(), rsock_init_ipsocket(), rsock_init_socket_constants(), rsock_init_sockifaddr(), rsock_init_sockopt(), rsock_init_sockssocket(), rsock_init_tcpserver(), rsock_init_tcpsocket(), rsock_init_udpsocket(), rsock_init_unixserver(), and rsock_init_unixsocket().
Referenced by Init_socket().
void rsock_init_sockifaddr | ( | void | ) |
Definition at line 460 of file ifaddr.c.
References rb_cData, rb_cSocket, rb_define_class_under(), rb_define_method(), rb_define_singleton_method(), and socket_s_getifaddrs.
Referenced by rsock_init_socket_init().
void rsock_init_sockopt | ( | void | ) |
Definition at line 1438 of file option.c.
References rb_cObject, rb_cSocket, rb_cSockOpt, rb_define_class_under(), and rb_define_method().
Referenced by rsock_init_socket_init().
void rsock_init_sockssocket | ( | void | ) |
Definition at line 52 of file sockssocket.c.
References rb_cTCPSocket, rb_define_class(), and rb_define_method().
Referenced by rsock_init_socket_init().
void rsock_init_tcpserver | ( | void | ) |
Definition at line 106 of file tcpserver.c.
References rb_cTCPServer, rb_cTCPSocket, rb_define_class(), and rb_define_method().
Referenced by rsock_init_socket_init().
void rsock_init_tcpsocket | ( | void | ) |
Definition at line 68 of file tcpsocket.c.
References rb_cIPSocket, rb_cTCPSocket, rb_define_class(), and rb_define_singleton_method().
Referenced by rsock_init_socket_init().
void rsock_init_udpsocket | ( | void | ) |
Definition at line 227 of file udpsocket.c.
References rb_cIPSocket, rb_cUDPSocket, rb_define_class(), and rb_define_method().
Referenced by rsock_init_socket_init().
void rsock_init_unixserver | ( | void | ) |
Definition at line 109 of file unixserver.c.
References rb_define_class(), rb_define_method(), rb_define_private_method(), and rsock_sock_listen().
Referenced by rsock_init_socket_init().
void rsock_init_unixsocket | ( | void | ) |
Definition at line 529 of file unixsocket.c.
References rb_cBasicSocket, rb_define_class(), rb_define_method(), and rb_define_singleton_method().
Referenced by rsock_init_socket_init().
Definition at line 1141 of file raddrinfo.c.
References union_sockaddr::addr, AF_UNSPEC, getnameinfo(), IFNAMSIZ, ISPRINT, ISSPACE, len, NI_NUMERICHOST, NI_NUMERICSERV, NULL, offsetof, rb_id2name(), rb_str_cat(), rb_str_cat2(), rb_str_catf(), rsock_intern_family(), and rsock_raise_socket_error().
Definition at line 2534 of file raddrinfo.c.
References rb_io_t::fd, FIX2INT, GetOpenFile, NUM2INT, rb_eTypeError, rb_raise(), rsock_fd_socket_addrinfo(), T_BIGNUM, T_FILE, T_FIXNUM, TYPE, and UNREACHABLE.
Definition at line 559 of file raddrinfo.c.
References id, INT2FIX, len, NI_NUMERICHOST, NI_NUMERICSERV, NULL, offsetof, Qnil, rb_ary_new3, rb_assoc_new(), rb_eArgError, rb_getnameinfo(), rb_id2str, rb_raise(), rb_str_dup(), rb_str_new(), rb_str_new2, rsock_intern_family(), rsock_raise_socket_error(), RSTRING_LEN, RSTRING_PTR, RSTRING_SOCKLEN, and SOCKLEN_MAX.
int rsock_level_arg | ( | int | family, |
VALUE | level | ||
) |
Definition at line 57 of file constants.c.
References IS_IP_FAMILY.
VALUE rsock_make_hostent | ( | VALUE | host, |
struct rb_addrinfo * | addr, | ||
VALUE(*)(struct sockaddr *, socklen_t) | ipaddr | ||
) |
Definition at line 704 of file raddrinfo.c.
References hostent_arg::addr, hostent_arg::host, hostent_arg::ipaddr, and rb_ensure().
Definition at line 396 of file raddrinfo.c.
int rsock_optname_arg | ( | int | family, |
int | level, | ||
VALUE | optname | ||
) |
Definition at line 69 of file constants.c.
References IS_IP_FAMILY.
int rsock_revlookup_flag | ( | VALUE | revlookup, |
int * | norevlookup | ||
) |
Definition at line 172 of file ipsocket.c.
References Check_Type, id, Qfalse, Qnil, Qtrue, return_norevlookup, SYM2ID, and T_SYMBOL.
Definition at line 595 of file init.c.
References BLOCKING_REGION_FD, recvfrom_arg::fd, accept_arg::fd, len, accept_arg::len, rsock_maybe_wait_fd, and accept_arg::sockaddr.
VALUE rsock_s_accept_nonblock | ( | VALUE | klass, |
VALUE | ex, | ||
rb_io_t * | fptr, | ||
struct sockaddr * | sockaddr, | ||
socklen_t * | len | ||
) |
Definition at line 553 of file init.c.
References rb_io_set_nonblock().
VALUE rsock_s_recvfrom | ( | VALUE | sock, |
int | argc, | ||
VALUE * | argv, | ||
enum sock_recv_type | from | ||
) |
Definition at line 146 of file init.c.
References recvfrom_arg::flags, len, NUM2INT, Qnil, rb_scan_args(), and recvfrom_arg::str.
VALUE rsock_s_recvfrom_nonblock | ( | VALUE | sock, |
VALUE | len, | ||
VALUE | flg, | ||
VALUE | str, | ||
VALUE | ex, | ||
enum sock_recv_type | from | ||
) |
Definition at line 209 of file init.c.
References recvfrom_arg::alen, recvfrom_arg::buf, recvfrom_arg::fd, recvfrom_arg::flags, NUM2INT, and Qnil.
VALUE rsock_send_blocking | ( | void * | data | ) |
Definition at line 91 of file init.c.
References rsock_send_arg::fd, rsock_send_arg::flags, rsock_send_arg::mesg, RSTRING_LEN, and RSTRING_PTR.
Referenced by rsock_bsock_send().
VALUE rsock_sendto_blocking | ( | void * | data | ) |
Definition at line 82 of file init.c.
References rsock_send_arg::fd, rsock_send_arg::flags, rsock_send_arg::mesg, RSTRING_LEN, RSTRING_PTR, rsock_send_arg::to, and rsock_send_arg::tolen.
Referenced by rsock_bsock_send().
int rsock_shutdown_how_arg | ( | VALUE | how | ) |
Definition at line 131 of file constants.c.
Definition at line 644 of file socket.c.
References rb_io_t::fd, GetOpenFile, INT2FIX, NUM2INT, and rb_sys_fail().
Referenced by rsock_init_unixserver().
socklen_t rsock_sockaddr_len | ( | struct sockaddr * | addr | ) |
Definition at line 2476 of file raddrinfo.c.
References IS_ADDRINFO, and val.
Referenced by rsock_sockaddr_string_value_ptr().
char* rsock_sockaddr_string_value_ptr | ( | volatile VALUE * | ) |
Definition at line 2500 of file raddrinfo.c.
References rsock_sockaddr_string_value(), and RSTRING_PTR.
Definition at line 2487 of file raddrinfo.c.
References IS_ADDRINFO, Qnil, and val.
int rsock_socket | ( | int | domain, |
int | type, | ||
int | proto | ||
) |
Definition at line 357 of file init.c.
References recvfrom_arg::fd.
Definition at line 107 of file option.c.
References NEWOBJ_OF, rb_cSockOpt, StringValue, and T_OBJECT.
int rsock_socktype_arg | ( | VALUE | type | ) |
Definition at line 50 of file constants.c.
VALUE rb_cAddrinfo |
Definition at line 23 of file init.c.
Referenced by rsock_init_addrinfo().
VALUE rb_cBasicSocket |
Definition at line 13 of file init.c.
Referenced by Init_socket(), rsock_init_basicsocket(), rsock_init_ipsocket(), and rsock_init_unixsocket().
VALUE rb_cIPSocket |
Definition at line 14 of file init.c.
Referenced by rsock_init_ipsocket(), rsock_init_tcpsocket(), and rsock_init_udpsocket().
VALUE rb_cSocket |
Definition at line 22 of file init.c.
Referenced by Init_socket(), rsock_init_ancdata(), rsock_init_sockifaddr(), and rsock_init_sockopt().
VALUE rb_cSockOpt |
Definition at line 3 of file option.c.
Referenced by rsock_init_sockopt(), and rsock_sockopt_new().
VALUE rb_cTCPServer |
Definition at line 16 of file init.c.
Referenced by rsock_init_tcpserver().
VALUE rb_cTCPSocket |
Definition at line 15 of file init.c.
Referenced by rsock_init_sockssocket(), rsock_init_tcpserver(), and rsock_init_tcpsocket().
VALUE rb_cUDPSocket |
Definition at line 17 of file init.c.
Referenced by rsock_init_udpsocket().
VALUE rb_eSocket |
Definition at line 25 of file init.c.
Referenced by rsock_init_socket_init(), and rsock_raise_socket_error().
int rsock_do_not_reverse_lookup |
Definition at line 31 of file init.c.
Referenced by rsock_init_sock().