28 VALUE rb_cSOCKSSocket;
46 #define is_socket(fd) rb_w32_is_socket(fd) 53 if (
fstat(fd, &sbuf) < 0)
55 return S_ISSOCK(sbuf.st_mode);
114 if (ret != -1 && len0 < arg->
alen)
188 if (arg.
alen !=
sizeof(
struct sockaddr_in)) {
204 rb_bug(
"rsock_s_recvfrom called with bad value");
228 flags |= MSG_DONTWAIT;
243 slen = recvfrom(fd,
RSTRING_PTR(str), buflen, flags, &buf.
addr, &alen);
244 if (slen != -1 && len0 < alen)
251 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN 269 if (alen && alen !=
sizeof(buf))
278 rb_bug(
"rsock_s_recvfrom_nonblock called with bad value");
303 static int cloexec_state = -1;
305 if (cloexec_state > 0) {
306 ret = socket(domain, type|SOCK_CLOEXEC, proto);
313 else if (cloexec_state < 0) {
314 ret = socket(domain, type|SOCK_CLOEXEC, proto);
317 if (cloexec_state == 0 || ret <= 2)
321 else if (ret == -1 &&
errno == EINVAL) {
323 ret = socket(domain, type, proto);
331 ret = socket(domain, type, proto);
346 int ret = socket(domain, type, proto);
376 int sockerr, revents;
381 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (
void *)&sockerr, &sockerrlen) < 0)
398 if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (
void *)&sockerr, &sockerrlen) < 0)
444 #if defined(SOCKS) && !defined(SOCKS5) 446 socks_connect_blocking(
void *data)
463 #if defined(SOCKS) && !defined(SOCKS5) 464 if (socks) func = socks_connect_blocking;
489 flags =
fcntl(fd, F_GETFL);
509 static int try_accept4 = 1;
511 if (address_len) len0 = *address_len;
516 flags |= SOCK_CLOEXEC;
520 flags |= SOCK_NONBLOCK;
523 ret = accept4(socket, address, address_len, flags);
528 #ifndef SOCK_NONBLOCK 533 if (address_len && len0 < *address_len) *address_len = len0;
536 if (
errno != ENOSYS) {
542 ret = accept(socket, address, address_len);
543 if (ret == -1)
return -1;
544 if (address_len && len0 < *address_len) *address_len = len0;
564 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN 625 if (!klass)
return INT2NUM(fd2);
647 if (getsockname(fptr->
fd, &ss.
addr, &sslen) < 0)
650 switch (ss.
addr.sa_family) {
658 return ss.
addr.sa_family;
struct sockaddr * sockaddr
void rb_bug(const char *fmt,...)
VALUE rsock_sendto_blocking(void *data)
void rb_update_max_fd(int fd)
void rb_io_set_nonblock(rb_io_t *fptr)
void rb_io_synchronized(rb_io_t *)
void rb_syserr_fail(int e, const char *mesg)
static VALUE rsock_strbuf(VALUE str, long buflen)
VALUE rsock_init_sock(VALUE sock, int fd)
SSL_METHOD *(* func)(void)
void rsock_init_unixsocket(void)
VALUE rb_str_locktmp_ensure(VALUE str, VALUE(*func)(VALUE), VALUE arg)
void rb_str_set_len(VALUE, long)
void rsock_init_tcpserver(void)
int rb_gc_for_fd(int err)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
#define FMODE_NOREVLOOKUP
void rsock_init_sockifaddr(void)
VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd)
void rsock_init_socket_constants(void)
static void make_fd_nonblock(int fd)
VALUE rsock_ipaddr(struct sockaddr *sockaddr, socklen_t sockaddrlen, int norevlookup)
VALUE rsock_s_recvfrom_nonblock(VALUE sock, VALUE len, VALUE flg, VALUE str, VALUE ex, enum sock_recv_type from)
#define GetOpenFile(obj, fp)
void rsock_init_addrinfo(void)
VALUE rsock_io_socket_addrinfo(VALUE io, struct sockaddr *addr, socklen_t len)
VALUE rsock_s_accept_nonblock(VALUE klass, VALUE ex, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
void rsock_init_tcpsocket(void)
VALUE rb_obj_taint(VALUE)
void rsock_init_sockssocket(void)
static int is_socket(int fd)
VALUE rsock_send_blocking(void *data)
int rsock_getfamily(rb_io_t *fptr)
int rsock_socket(int domain, int type, int proto)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
void rsock_init_ancdata(void)
static int wait_connectable(int fd)
VALUE rb_obj_alloc(VALUE)
char * gai_strerror(int ecode)
static int cloexec_accept(int socket, struct sockaddr *address, socklen_t *address_len, int nonblock)
VALUE rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
static int rsock_socket0(int domain, int type, int proto)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
void rb_str_modify_expand(VALUE, long)
VALUE rb_assoc_new(VALUE car, VALUE cdr)
void rsock_init_udpsocket(void)
int rsock_do_not_reverse_lookup
void rb_readwrite_syserr_fail(enum rb_io_wait_readwrite writable, int n, const char *mesg)
int rsock_detect_cloexec(int fd)
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv)
VALUE rb_blocking_function_t(void *)
void rb_sys_fail(const char *mesg)
int rb_reserved_fd_p(int fd)
register unsigned int len
const struct sockaddr * sockaddr
void rb_str_modify(VALUE)
int rb_io_read_pending(rb_io_t *)
void rb_fd_fix_cloexec(int fd)
void rsock_raise_socket_error(const char *reason, int error)
#define rsock_maybe_wait_fd(fd)
VALUE rb_io_ascii8bit_binmode(VALUE)
int rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks)
RUBY_EXTERN char * strerror(int)
static VALUE recvfrom_locktmp(VALUE v)
static VALUE connect_blocking(void *data)
static VALUE sym_wait_readable
static VALUE accept_blocking(void *data)
void rsock_init_ipsocket(void)
void rsock_init_unixserver(void)
#define MSG_DONTWAIT_RELIABLE
RUBY_EXTERN VALUE rb_eIOError
#define MakeOpenFile(obj, fp)
static VALUE recvfrom_blocking(void *data)
void rsock_init_sockopt(void)
VALUE rb_tainted_str_new(const char *, long)
int rb_io_wait_readable(int)
void rsock_init_socket_init(void)
void rb_io_check_closed(rb_io_t *)
#define BLOCKING_REGION_FD(func, arg)
void rb_maygvl_fd_fix_cloexec(int fd)