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;