28 VALUE rb_cSOCKSSocket;
49 if (
fstat(fd, &sbuf) < 0)
108 if (ret != -1 && len0 < arg->
alen)
161 if (arg.
alen !=
sizeof(
struct sockaddr_in)) {
177 rb_bug(
"rsock_s_recvfrom called with bad value");
204 flags |= MSG_DONTWAIT;
219 if (slen != -1 && len0 <
alen)
225 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN 250 rb_bug(
"rsock_s_recvfrom_nonblock called with bad value");
261 static int try_sock_cloexec = 1;
262 if (try_sock_cloexec) {
263 ret = socket(domain,
type|SOCK_CLOEXEC,
proto);
264 if (ret == -1 &&
errno == EINVAL) {
268 try_sock_cloexec = 0;
321 ret = getsockopt(
fd, SOL_SOCKET, SO_ERROR, (
void *)&sockerr, &sockerrlen);
352 #define WAIT_IN_PROGRESS 10 355 #define WAIT_IN_PROGRESS 10 359 #define WAIT_IN_PROGRESS 0 361 #ifndef WAIT_IN_PROGRESS 363 #define WAIT_IN_PROGRESS 1 379 #if defined(SOCKS) && !defined(SOCKS5) 381 socks_connect_blocking(
void *data)
394 #if WAIT_IN_PROGRESS > 0 395 int wait_in_progress = -1;
403 #if defined(SOCKS) && !defined(SOCKS5) 404 if (socks)
func = socks_connect_blocking;
411 #if defined(ERESTART) 420 #if WAIT_IN_PROGRESS > 0 422 status = getsockopt(
fd, SOL_SOCKET, SO_ERROR, (
void *)&sockerr, &sockerrlen);
433 #if WAIT_IN_PROGRESS > 0 443 #if WAIT_IN_PROGRESS > 0 445 if (wait_in_progress-- > 0) {
452 status = getsockopt(
fd, SOL_SOCKET, SO_ERROR, (
void *)&sockerr, &sockerrlen);
453 if (!status && !sockerr) {
454 struct timeval tv = {0, 100000};
483 flags =
fcntl(fd, F_GETFL);
502 static int try_accept4 = 1;
504 if (address_len) len0 = *address_len;
509 flags |= SOCK_CLOEXEC;
511 ret = accept4(socket, address, address_len, flags);
516 if (address_len && len0 < *address_len) *address_len = len0;
519 if (
errno != ENOSYS) {
525 ret = accept(socket, address, address_len);
526 if (ret == -1)
return -1;
527 if (address_len && len0 < *address_len) *address_len = len0;
544 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN 603 if (!klass)
return INT2NUM(fd2);
614 if (getsockname(sockfd, &ss.
addr, &sslen) < 0)
617 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 *)
VALUE rsock_init_sock(VALUE sock, int fd)
SSL_METHOD *(* func)(void)
void rsock_init_unixsocket(void)
void rb_str_set_len(VALUE, long)
void rsock_init_tcpserver(void)
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)
void rsock_init_socket_constants(void)
static void make_fd_nonblock(int fd)
VALUE rsock_ipaddr(struct sockaddr *sockaddr, socklen_t sockaddrlen, int norevlookup)
int rsock_getfamily(int sockfd)
#define GetOpenFile(obj, fp)
void rsock_init_addrinfo(void)
VALUE rsock_io_socket_addrinfo(VALUE io, struct sockaddr *addr, socklen_t len)
int rb_w32_is_socket(int)
void rsock_init_tcpsocket(void)
VALUE rb_obj_taint(VALUE)
void rsock_init_sockssocket(void)
VALUE rsock_send_blocking(void *data)
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)
void rsock_init_socket_init()
VALUE rb_obj_reveal(VALUE obj, VALUE klass)
char * gai_strerror(int ecode)
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)
static int cloexec_accept(int socket, struct sockaddr *address, socklen_t *address_len)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
unsigned char buf[MIME_BUF_SIZE]
VALUE rb_assoc_new(VALUE car, VALUE cdr)
void rb_thread_wait_fd(int)
void rsock_init_udpsocket(void)
int rsock_do_not_reverse_lookup
void rb_readwrite_sys_fail(int writable, const char *mesg)
VALUE rb_obj_hide(VALUE obj)
#define RB_IO_WAIT_READABLE
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)
const struct sockaddr * sockaddr
void rb_thread_wait_for(struct timeval)
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)
VALUE rb_io_ascii8bit_binmode(VALUE)
int rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks)
static VALUE connect_blocking(void *data)
VALUE rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
static VALUE accept_blocking(void *data)
void rsock_init_ipsocket(void)
void rsock_init_unixserver(void)
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)
VALUE rsock_s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
int rb_io_wait_readable(int)
void rb_io_check_closed(rb_io_t *)
#define BLOCKING_REGION_FD(func, arg)
void rb_maygvl_fd_fix_cloexec(int fd)