28 VALUE rb_cSOCKSSocket;
49 if (
fstat(fd, &sbuf) < 0)
52 if (!S_ISSOCK(sbuf.st_mode))
105 if (ret != -1 && len0 < arg->
alen)
134 klass =
RBASIC(str)->klass;
158 if (arg.
alen !=
sizeof(
struct sockaddr_in)) {
174 rb_bug(
"rsock_s_recvfrom called with bad value");
194 if (flg ==
Qnil) flags = 0;
201 flags |= MSG_DONTWAIT;
215 slen = recvfrom(fd,
RSTRING_PTR(str), buflen, flags, &buf.
addr, &alen);
216 if (slen != -1 && len0 < alen)
222 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
238 if (alen && alen !=
sizeof(buf))
247 rb_bug(
"rsock_s_recvfrom_nonblock called with bad value");
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) {
263 ret = socket(domain, type, proto);
265 try_sock_cloexec = 0;
270 ret = socket(domain, type, proto);
273 ret = socket(domain, type, proto);
318 ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, (
void *)&sockerr, &sockerrlen);
349 #define WAIT_IN_PROGRESS 10
352 #define WAIT_IN_PROGRESS 10
356 #define WAIT_IN_PROGRESS 0
358 #ifndef WAIT_IN_PROGRESS
360 #define WAIT_IN_PROGRESS 1
376 #if defined(SOCKS) && !defined(SOCKS5)
378 socks_connect_blocking(
void *data)
391 #if WAIT_IN_PROGRESS > 0
392 int wait_in_progress = -1;
400 #if defined(SOCKS) && !defined(SOCKS5)
401 if (socks) func = socks_connect_blocking;
408 #if defined(ERESTART)
417 #if WAIT_IN_PROGRESS > 0
419 status = getsockopt(fd, SOL_SOCKET, SO_ERROR, (
void *)&sockerr, &sockerrlen);
430 #if WAIT_IN_PROGRESS > 0
440 #if WAIT_IN_PROGRESS > 0
442 if (wait_in_progress-- > 0) {
449 status = getsockopt(fd, SOL_SOCKET, SO_ERROR, (
void *)&sockerr, &sockerrlen);
450 if (!status && !sockerr) {
451 struct timeval tv = {0, 100000};
480 flags =
fcntl(fd, F_GETFL);
499 static int try_accept4 = 1;
501 if (address_len) len0 = *address_len;
506 flags |= SOCK_CLOEXEC;
508 ret = accept4(socket, address, address_len, flags);
513 if (address_len && len0 < *address_len) *address_len = len0;
516 if (
errno != ENOSYS) {
522 ret = accept(socket, address, address_len);
523 if (ret == -1)
return -1;
524 if (address_len && len0 < *address_len) *address_len = len0;
541 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
600 if (!klass)
return INT2NUM(fd2);
611 if (getsockname(sockfd, &ss.
addr, &sslen) < 0)
614 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)
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)
SSL_METHOD *(* func)(void)
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)
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)