Ruby
2.7.2p137(2020-10-01revision5445e0435260b449decf2ac16f9d09bae3cafe72)
|
Go to the documentation of this file.
32 VALUE rb_cSOCKSSocket;
36 static VALUE sym_wait_readable;
58 #define is_socket(fd) rb_w32_is_socket(fd)
65 if (
fstat(fd, &sbuf) < 0)
72 # define do_write_retry(code) do {ret = code;} while (ret == -1 && errno == EPROTOTYPE)
74 # define do_write_retry(code) ret = code
130 recvfrom_blocking(
void *data)
137 if (ret != -1 && len0 < arg->
alen)
144 rsock_strbuf(
VALUE str,
long buflen)
180 if (flg ==
Qnil)
arg.flags = 0;
183 str = rsock_strbuf(
str, buflen);
210 if (
arg.alen !=
sizeof(
struct sockaddr_in)) {
214 if (
arg.alen &&
arg.alen !=
sizeof(
arg.buf))
226 rb_bug(
"rsock_s_recvfrom called with bad value");
245 str = rsock_strbuf(
str, buflen);
250 flags |= MSG_DONTWAIT;
266 if (slen != -1 && len0 <
alen)
273 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
277 return sym_wait_readable;
299 rb_bug(
"rsock_s_recvfrom_nonblock called with bad value");
304 #if MSG_DONTWAIT_RELIABLE
305 static VALUE sym_wait_writable;
311 int n = fptr->
rbuf.len;
313 if (
n <= 0)
return 0;
339 n = read_buffered_data(
ptr,
len, fptr);
345 if (ex ==
Qfalse)
return sym_wait_readable;
347 e,
"read would block");
383 if (fptr->
wbuf.len > 0) {
400 if (ex ==
Qfalse)
return sym_wait_writable;
402 "write would block");
428 rsock_socket0(
int domain,
int type,
int proto)
431 static int cloexec_state = -1;
433 if (cloexec_state > 0) {
441 else if (cloexec_state < 0) {
445 if (cloexec_state == 0 || ret <= 2)
475 rsock_socket0(
int domain,
int type,
int proto)
508 wait_connectable(
int fd)
510 int sockerr, revents;
514 if (getsockopt(
fd, SOL_SOCKET, SO_ERROR, (
void *)&sockerr, &sockerrlen) < 0)
551 if (getsockopt(
fd, SOL_SOCKET, SO_ERROR, (
void *)&sockerr, &sockerrlen) < 0)
591 connect_blocking(
void *data)
597 #if defined(SOCKS) && !defined(SOCKS5)
599 socks_connect_blocking(
void *data)
616 #if defined(SOCKS) && !defined(SOCKS5)
617 if (socks) func = socks_connect_blocking;
631 return wait_connectable(
fd);
662 static int try_accept4 = 1;
667 if (address_len) len0 = *address_len;
672 flags |= SOCK_CLOEXEC;
676 flags |= SOCK_NONBLOCK;
679 ret = accept4(socket, address, address_len, flags);
684 #ifndef SOCK_NONBLOCK
689 if (address_len && len0 < *address_len) *address_len = len0;
698 ret = accept(socket, address, address_len);
699 if (ret == -1)
return -1;
700 if (address_len && len0 < *address_len) *address_len = len0;
720 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
728 return sym_wait_readable;
744 accept_blocking(
void *data)
747 return (
VALUE)cloexec_accept(
arg->fd,
arg->sockaddr,
arg->len, 0);
803 if (getsockname(fptr->
fd, &ss.
addr, &sslen) < 0)
806 switch (ss.
addr.sa_family) {
814 return ss.
addr.sa_family;
840 #if MSG_DONTWAIT_RELIABLE
VALUE rb_str_concat(VALUE, VALUE)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
#define RSOCK_NONBLOCK_DEFAULT
VALUE rsock_read_nonblock(VALUE sock, VALUE length, VALUE buf, VALUE ex)
VALUE rb_assoc_new(VALUE car, VALUE cdr)
int rb_gc_for_fd(int err)
void rsock_init_unixserver(void)
VALUE rb_exc_new_str(VALUE etype, VALUE str)
void rsock_init_unixsocket(void)
void rsock_init_socket_init(void)
VALUE rsock_init_sock(VALUE sock, int fd)
#define RB_IO_WAIT_WRITABLE
VALUE rsock_s_recvfrom_nonblock(VALUE sock, VALUE len, VALUE flg, VALUE str, VALUE ex, enum sock_recv_type from)
VALUE rb_obj_as_string(VALUE)
#define RB_TYPE_P(obj, type)
VALUE rsock_s_accept_nonblock(VALUE klass, VALUE ex, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
void rb_fd_fix_cloexec(int fd)
void rb_io_check_closed(rb_io_t *)
VALUE rsock_sendto_blocking(void *data)
void rb_str_modify(VALUE)
RUBY_EXTERN VALUE rb_eIOError
int rsock_getfamily(rb_io_t *fptr)
const struct sockaddr * sockaddr
VALUE rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
void rb_readwrite_syserr_fail(enum rb_io_wait_readwrite writable, int n, const char *mesg)
VALUE rb_blocking_function_t(void *)
VALUE rb_str_locktmp_ensure(VALUE str, VALUE(*func)(VALUE), VALUE arg)
void rsock_make_fd_nonblock(int fd)
int rsock_socket(int domain, int type, int proto)
void rb_raise(VALUE exc, const char *fmt,...)
struct sockaddr * sockaddr
void rb_syserr_fail(int e, const char *mesg)
RUBY_EXTERN char * strerror(int)
void rsock_init_udpsocket(void)
VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd)
int rsock_do_not_reverse_lookup
VALUE rsock_send_blocking(void *data)
void rsock_init_tcpserver(void)
#define BLOCKING_REGION_FD(func, arg)
VALUE rb_io_ascii8bit_binmode(VALUE)
#define MSG_DONTWAIT_RELIABLE
void rb_update_max_fd(int fd)
VALUE rsock_write_nonblock(VALUE sock, VALUE buf, VALUE ex)
void rsock_init_sockopt(void)
void rb_sys_fail(const char *mesg)
void rsock_init_ancdata(void)
VALUE rb_io_get_write_io(VALUE io)
void rsock_init_socket_constants(void)
void rsock_init_addrinfo(void)
VALUE rsock_ipaddr(struct sockaddr *sockaddr, socklen_t sockaddrlen, int norevlookup)
void rb_str_set_len(VALUE, long)
rb_encoding * rb_default_internal_encoding(void)
#define rsock_maybe_wait_fd(fd)
int rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks)
unsigned char buf[MIME_BUF_SIZE]
void rsock_init_ipsocket(void)
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
#define rb_syserr_fail_path(err, path)
void rsock_init_tcpsocket(void)
void rb_bug(const char *fmt,...)
#define FMODE_NOREVLOOKUP
VALUE rb_sprintf(const char *format,...)
VALUE rb_obj_alloc(VALUE)
Allocates an instance of klass.
char str[HTML_ESCAPE_MAX_LEN+1]
VALUE rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv)
void rb_io_check_writable(rb_io_t *)
void rb_str_modify_expand(VALUE, long)
#define do_write_retry(code)
int rsock_detect_cloexec(int fd)
VALUE rsock_io_socket_addrinfo(VALUE io, struct sockaddr *addr, socklen_t len)
void rb_io_set_nonblock(rb_io_t *fptr)
#define MakeOpenFile(obj, fp)
#define GetOpenFile(obj, fp)
int rb_io_wait_readable(int)
void rsock_raise_socket_error(const char *reason, int error)
#define RB_IO_WAIT_READABLE
char * gai_strerror(int ecode)
#define MEMMOVE(p1, p2, type, n)
int rb_io_read_pending(rb_io_t *)
void rsock_init_sockifaddr(void)
int rb_reserved_fd_p(int fd)
void rsock_init_sockssocket(void)
VALUE type(ANYARGS)
ANYARGS-ed function type.
void rb_io_synchronized(rb_io_t *)
void rb_maygvl_fd_fix_cloexec(int fd)
VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc)
#define is_socket(fd, path)