28 VALUE rb_cSOCKSSocket;
49 if (
fstat(fd, &sbuf) < 0)
52 if (!S_ISSOCK(sbuf.st_mode))
126 arg.
alen = (socklen_t)
sizeof(arg.
buf);
129 klass =
RBASIC(str)->klass;
143 RBASIC(str)->klass = klass;
153 if (arg.
alen !=
sizeof(
struct sockaddr_in)) {
169 rb_bug(
"rsock_s_recvfrom called with bad value");
179 socklen_t alen = (socklen_t)
sizeof buf;
188 if (flg ==
Qnil) flags = 0;
195 flags |= MSG_DONTWAIT;
208 slen = recvfrom(fd,
RSTRING_PTR(str), buflen, flags, (
struct sockaddr*)&buf, &alen);
213 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
229 if (alen && alen !=
sizeof(buf))
238 rb_bug(
"rsock_s_recvfrom_nonblock called with bad value");
249 static int try_sock_cloexec = 1;
250 if (try_sock_cloexec) {
251 ret = socket(domain, type|SOCK_CLOEXEC, proto);
252 if (ret == -1 &&
errno == EINVAL) {
254 ret = socket(domain, type, proto);
256 try_sock_cloexec = 0;
261 ret = socket(domain, type, proto);
264 ret = socket(domain, type, proto);
296 socklen_t sockerrlen;
308 sockerrlen = (socklen_t)
sizeof(sockerr);
309 ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, (
void *)&sockerr, &sockerrlen);
336 #define WAIT_IN_PROGRESS 10
339 #define WAIT_IN_PROGRESS 10
343 #define WAIT_IN_PROGRESS 0
345 #ifndef WAIT_IN_PROGRESS
347 #define WAIT_IN_PROGRESS 1
363 #if defined(SOCKS) && !defined(SOCKS5)
365 socks_connect_blocking(
void *data)
378 #if WAIT_IN_PROGRESS > 0
379 int wait_in_progress = -1;
381 socklen_t sockerrlen;
387 #if defined(SOCKS) && !defined(SOCKS5)
388 if (socks) func = socks_connect_blocking;
395 #if defined(ERESTART)
404 #if WAIT_IN_PROGRESS > 0
405 sockerrlen = (socklen_t)
sizeof(sockerr);
406 status = getsockopt(fd, SOL_SOCKET, SO_ERROR, (
void *)&sockerr, &sockerrlen);
417 #if WAIT_IN_PROGRESS > 0
427 #if WAIT_IN_PROGRESS > 0
429 if (wait_in_progress-- > 0) {
435 sockerrlen = (socklen_t)
sizeof(sockerr);
436 status = getsockopt(fd, SOL_SOCKET, SO_ERROR, (
void *)&sockerr, &sockerrlen);
437 if (!status && !sockerr) {
438 struct timeval tv = {0, 100000};
467 flags =
fcntl(fd, F_GETFL);
486 static int try_accept4 = 1;
488 if (address_len) len0 = *address_len;
491 ret = accept4(socket, address, address_len, SOCK_CLOEXEC);
496 if (address_len && len0 < *address_len) *address_len = len0;
499 if (
errno != ENOSYS) {
505 ret = accept(socket, address, address_len);
506 if (ret == -1)
return -1;
507 if (address_len && len0 < *address_len) *address_len = len0;
524 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
583 if (!klass)
return INT2NUM(fd2);
591 socklen_t sslen = (socklen_t)
sizeof(ss);
594 if (getsockname(sockfd, (
struct sockaddr*)&ss, &sslen) < 0)