36static 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
130recvfrom_blocking(
void *data)
137 if (ret != -1 && len0 < arg->
alen)
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
305static 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");
428rsock_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)
475rsock_socket0(
int domain,
int type,
int proto)
508wait_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)
591connect_blocking(
void *data)
597#if defined(SOCKS) && !defined(SOCKS5)
599socks_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);
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;
744accept_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
void rsock_init_ancdata(void)
void rsock_init_socket_constants(void)
rb_encoding * rb_default_internal_encoding(void)
char str[HTML_ESCAPE_MAX_LEN+1]
char * gai_strerror(int ecode)
VALUE rb_define_class(const char *, VALUE)
Defines a top-level class.
void rb_syserr_fail(int e, const char *mesg)
void rb_raise(VALUE exc, const char *fmt,...)
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_bug(const char *fmt,...)
VALUE rb_exc_new_str(VALUE, VALUE)
void rb_sys_fail(const char *mesg)
VALUE rb_obj_alloc(VALUE)
Allocates an instance of klass.
void rsock_init_sockifaddr(void)
void rb_readwrite_syserr_fail(enum rb_io_wait_readwrite writable, int n, const char *mesg)
#define is_socket(fd, path)
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv)
void rb_io_check_closed(rb_io_t *)
void rb_io_check_writable(rb_io_t *)
#define MakeOpenFile(obj, fp)
int rb_io_read_pending(rb_io_t *)
#define GetOpenFile(obj, fp)
VALUE rb_io_get_write_io(VALUE io)
void rb_io_set_nonblock(rb_io_t *fptr)
void rb_io_synchronized(rb_io_t *)
int rb_io_wait_readable(int)
void rsock_init_ipsocket(void)
VALUE type(ANYARGS)
ANYARGS-ed function type.
void rsock_init_sockopt(void)
void rsock_init_addrinfo(void)
VALUE rsock_ipaddr(struct sockaddr *sockaddr, socklen_t sockaddrlen, int norevlookup)
VALUE rsock_io_socket_addrinfo(VALUE io, struct sockaddr *addr, socklen_t len)
void rsock_init_udpsocket(void)
void rsock_init_tcpserver(void)
#define RSOCK_NONBLOCK_DEFAULT
void rsock_init_sockssocket(void)
VALUE rsock_write_nonblock(VALUE sock, VALUE buf, VALUE ex)
void rsock_init_tcpsocket(void)
#define MSG_DONTWAIT_RELIABLE
void rsock_init_unixsocket(void)
VALUE rsock_read_nonblock(VALUE sock, VALUE length, VALUE buf, VALUE ex)
#define BLOCKING_REGION_FD(func, arg)
#define rsock_maybe_wait_fd(fd)
void rsock_init_unixserver(void)
#define FMODE_NOREVLOOKUP
void rsock_raise_socket_error(const char *reason, int error)
void rsock_make_fd_nonblock(int fd)
VALUE rsock_sendto_blocking(void *data)
#define do_write_retry(code)
VALUE rsock_s_recvfrom_nonblock(VALUE sock, VALUE len, VALUE flg, VALUE str, VALUE ex, enum sock_recv_type from)
int rsock_getfamily(rb_io_t *fptr)
VALUE rsock_s_accept_nonblock(VALUE klass, VALUE ex, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
VALUE rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
int rsock_socket(int domain, int type, int proto)
int rsock_detect_cloexec(int fd)
VALUE rsock_init_sock(VALUE sock, int fd)
int rsock_do_not_reverse_lookup
VALUE rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
VALUE rsock_send_blocking(void *data)
void rsock_init_socket_init(void)
int rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks)
struct sockaddr * sockaddr
const struct sockaddr * sockaddr
VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc)