summaryrefslogtreecommitdiff
path: root/ext/socket
diff options
context:
space:
mode:
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/ancdata.c82
-rw-r--r--ext/socket/basicsocket.c12
-rw-r--r--ext/socket/socket.c18
-rw-r--r--ext/socket/unixsocket.c14
4 files changed, 64 insertions, 62 deletions
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c
index b50959c8473..d30ddf6e7cb 100644
--- a/ext/socket/ancdata.c
+++ b/ext/socket/ancdata.c
@@ -176,6 +176,7 @@ ancillary_data(VALUE self)
return v;
}
+#ifdef SCM_RIGHTS
/*
* call-seq:
* Socket::AncillaryData.unix_rights(io1, io2, ...) => ancillarydata
@@ -188,7 +189,6 @@ ancillary_data(VALUE self)
static VALUE
ancillary_s_unix_rights(int argc, VALUE *argv, VALUE klass)
{
-#ifdef SCM_RIGHTS
VALUE result, str, ary;
int i;
@@ -216,11 +216,12 @@ ancillary_s_unix_rights(int argc, VALUE *argv, VALUE klass)
result = ancdata_new(AF_UNIX, SOL_SOCKET, SCM_RIGHTS, str);
rb_ivar_set(result, rb_intern("unix_rights"), ary);
return result;
+}
#else
- rb_notimplement();
+#define ancillary_s_unix_rights rb_f_notimplement
#endif
-}
+#ifdef SCM_RIGHTS
/*
* call-seq:
* ancillarydata.unix_rights => array-of-IOs or nil
@@ -253,7 +254,6 @@ ancillary_s_unix_rights(int argc, VALUE *argv, VALUE klass)
static VALUE
ancillary_unix_rights(VALUE self)
{
-#ifdef SCM_RIGHTS
int level, type;
level = ancillary_level(self);
@@ -264,11 +264,12 @@ ancillary_unix_rights(VALUE self)
VALUE v = rb_attr_get(self, rb_intern("unix_rights"));
return v;
+}
#else
- rb_notimplement();
+#define ancillary_unix_rights rb_f_notimplement
#endif
-}
+#if defined(SCM_TIMESTAMP) || defined(SCM_TIMESTAMPNS) || defined(SCM_BINTIME)
/*
* call-seq:
* ancillarydata.timestamp => time
@@ -300,7 +301,6 @@ ancillary_unix_rights(VALUE self)
static VALUE
ancillary_timestamp(VALUE self)
{
-#if defined(SCM_TIMESTAMP) || defined(SCM_TIMESTAMPNS) || defined(SCM_BINTIME)
int level, type;
VALUE data;
VALUE result = Qnil;
@@ -342,10 +342,10 @@ ancillary_timestamp(VALUE self)
rb_raise(rb_eTypeError, "timestamp ancillary data expected");
return result;
+}
#else
- rb_notimplement();
+#define ancillary_timestamp rb_f_notimplement
#endif
-}
/*
* call-seq:
@@ -391,6 +391,7 @@ ancillary_int(VALUE self)
return INT2NUM(i);
}
+#if defined(IPPROTO_IP) && defined(IP_PKTINFO) && defined(HAVE_TYPE_STRUCT_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) /* GNU/Linux */
/*
* call-seq:
* Socket::AncillaryData.ip_pktinfo(addr, ifindex) => ancdata
@@ -414,7 +415,6 @@ ancillary_int(VALUE self)
static VALUE
ancillary_s_ip_pktinfo(int argc, VALUE *argv, VALUE self)
{
-#if defined(IPPROTO_IP) && defined(IP_PKTINFO) && defined(HAVE_TYPE_STRUCT_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) /* GNU/Linux */
VALUE v_addr, v_ifindex, v_spec_dst;
unsigned int ifindex;
struct sockaddr_in sa;
@@ -450,11 +450,12 @@ ancillary_s_ip_pktinfo(int argc, VALUE *argv, VALUE self)
memcpy(&pktinfo.ipi_spec_dst, &sa.sin_addr, sizeof(pktinfo.ipi_spec_dst));
return ancdata_new(AF_INET, IPPROTO_IP, IP_PKTINFO, rb_str_new((char *)&pktinfo, sizeof(pktinfo)));
+}
#else
- rb_notimplement();
+#define ancillary_s_ip_pktinfo rb_f_notimplement
#endif
-}
+#if defined(IPPROTO_IP) && defined(IP_PKTINFO) && defined(HAVE_TYPE_STRUCT_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) /* GNU/Linux */
/*
* call-seq:
* ancdata.ip_pktinfo => [addr, ifindex, spec_dst]
@@ -477,7 +478,6 @@ ancillary_s_ip_pktinfo(int argc, VALUE *argv, VALUE self)
static VALUE
ancillary_ip_pktinfo(VALUE self)
{
-#if defined(IPPROTO_IP) && defined(IP_PKTINFO) && defined(HAVE_TYPE_STRUCT_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) /* GNU/Linux */
int level, type;
VALUE data;
struct in_pktinfo pktinfo;
@@ -505,11 +505,12 @@ ancillary_ip_pktinfo(VALUE self)
v_spec_dst = rsock_addrinfo_new((struct sockaddr *)&sa, sizeof(sa), PF_INET, 0, 0, Qnil, Qnil);
return rb_ary_new3(3, v_addr, UINT2NUM(pktinfo.ipi_ifindex), v_spec_dst);
+}
#else
- rb_notimplement();
+#define ancillary_ip_pktinfo rb_f_notimplement
#endif
-}
+#if defined(IPPROTO_IPV6) && defined(IPV6_PKTINFO) /* IPv6 RFC3542 */
/*
* call-seq:
* Socket::AncillaryData.ipv6_pktinfo(addr, ifindex) => ancdata
@@ -527,7 +528,6 @@ ancillary_ip_pktinfo(VALUE self)
static VALUE
ancillary_s_ipv6_pktinfo(VALUE self, VALUE v_addr, VALUE v_ifindex)
{
-#if defined(IPPROTO_IPV6) && defined(IPV6_PKTINFO) /* IPv6 RFC3542 */
unsigned int ifindex;
struct sockaddr_in6 sa;
struct in6_pktinfo pktinfo;
@@ -548,10 +548,10 @@ ancillary_s_ipv6_pktinfo(VALUE self, VALUE v_addr, VALUE v_ifindex)
pktinfo.ipi6_ifindex = ifindex;
return ancdata_new(AF_INET6, IPPROTO_IPV6, IPV6_PKTINFO, rb_str_new((char *)&pktinfo, sizeof(pktinfo)));
+}
#else
- rb_notimplement();
+#define ancillary_s_ipv6_pktinfo rb_f_notimplement
#endif
-}
#if defined(IPPROTO_IPV6) && defined(IPV6_PKTINFO) /* IPv6 RFC3542 */
static void
@@ -580,6 +580,7 @@ extract_ipv6_pktinfo(VALUE self, struct in6_pktinfo *pktinfo_ptr, struct sockadd
}
#endif
+#if defined(IPPROTO_IPV6) && defined(IPV6_PKTINFO) /* IPv6 RFC3542 */
/*
* call-seq:
* ancdata.ipv6_pktinfo => [addr, ifindex]
@@ -597,7 +598,6 @@ extract_ipv6_pktinfo(VALUE self, struct in6_pktinfo *pktinfo_ptr, struct sockadd
static VALUE
ancillary_ipv6_pktinfo(VALUE self)
{
-#if defined(IPPROTO_IPV6) && defined(IPV6_PKTINFO) /* IPv6 RFC3542 */
struct in6_pktinfo pktinfo;
struct sockaddr_in6 sa;
VALUE v_addr;
@@ -605,11 +605,12 @@ ancillary_ipv6_pktinfo(VALUE self)
extract_ipv6_pktinfo(self, &pktinfo, &sa);
v_addr = rsock_addrinfo_new((struct sockaddr *)&sa, sizeof(sa), PF_INET6, 0, 0, Qnil, Qnil);
return rb_ary_new3(2, v_addr, UINT2NUM(pktinfo.ipi6_ifindex));
+}
#else
- rb_notimplement();
+#define ancillary_ipv6_pktinfo rb_f_notimplement
#endif
-}
+#if defined(IPPROTO_IPV6) && defined(IPV6_PKTINFO) /* IPv6 RFC3542 */
/*
* call-seq:
* ancdata.ipv6_pktinfo_addr => addr
@@ -627,16 +628,16 @@ ancillary_ipv6_pktinfo(VALUE self)
static VALUE
ancillary_ipv6_pktinfo_addr(VALUE self)
{
-#if defined(IPPROTO_IPV6) && defined(IPV6_PKTINFO) /* IPv6 RFC3542 */
struct in6_pktinfo pktinfo;
struct sockaddr_in6 sa;
extract_ipv6_pktinfo(self, &pktinfo, &sa);
return rsock_addrinfo_new((struct sockaddr *)&sa, sizeof(sa), PF_INET6, 0, 0, Qnil, Qnil);
+}
#else
- rb_notimplement();
+#define ancillary_ipv6_pktinfo_addr rb_f_notimplement
#endif
-}
+#if defined(IPPROTO_IPV6) && defined(IPV6_PKTINFO) /* IPv6 RFC3542 */
/*
* call-seq:
* ancdata.ipv6_pktinfo_ifindex => addr
@@ -654,15 +655,14 @@ ancillary_ipv6_pktinfo_addr(VALUE self)
static VALUE
ancillary_ipv6_pktinfo_ifindex(VALUE self)
{
-#if defined(IPPROTO_IPV6) && defined(IPV6_PKTINFO) /* IPv6 RFC3542 */
struct in6_pktinfo pktinfo;
struct sockaddr_in6 sa;
extract_ipv6_pktinfo(self, &pktinfo, &sa);
return UINT2NUM(pktinfo.ipi6_ifindex);
+}
#else
- rb_notimplement();
+#define ancillary_ipv6_pktinfo_ifindex rb_f_notimplement
#endif
-}
#if defined(SOL_SOCKET) && defined(SCM_RIGHTS) /* 4.4BSD */
static int
@@ -1286,14 +1286,9 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
return SSIZET2NUM(ss);
}
-#else
-static VALUE
-bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
-{
- rb_notimplement();
-}
#endif
+#if defined(HAVE_SENDMSG)
/*
* call-seq:
* basicsocket.sendmsg(mesg, flags=0, dest_sockaddr=nil, *controls) => numbytes_sent
@@ -1331,7 +1326,11 @@ bsock_sendmsg(int argc, VALUE *argv, VALUE sock)
{
return bsock_sendmsg_internal(argc, argv, sock, 0);
}
+#else
+#define bsock_sendmsg rb_f_notimplement
+#endif
+#if defined(HAVE_SENDMSG)
/*
* call-seq:
* basicsocket.sendmsg_nonblock(mesg, flags=0, dest_sockaddr=nil, *controls) => numbytes_sent
@@ -1348,6 +1347,9 @@ bsock_sendmsg_nonblock(int argc, VALUE *argv, VALUE sock)
{
return bsock_sendmsg_internal(argc, argv, sock, 1);
}
+#else
+#define bsock_sendmsg_nonblock rb_f_notimplement
+#endif
#if defined(HAVE_RECVMSG)
struct recvmsg_args_struct {
@@ -1675,14 +1677,9 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
return ret;
}
-#else
-static VALUE
-bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
-{
- rb_notimplement();
-}
#endif
+#if defined(HAVE_RECVMSG)
/*
* call-seq:
* basicsocket.recvmsg(maxmesglen=nil, flags=0, maxcontrollen=nil, opts={}) => [mesg, sender_addrinfo, rflags, *controls]
@@ -1741,7 +1738,11 @@ bsock_recvmsg(int argc, VALUE *argv, VALUE sock)
{
return bsock_recvmsg_internal(argc, argv, sock, 0);
}
+#else
+#define bsock_recvmsg rb_f_notimplement
+#endif
+#if defined(HAVE_RECVMSG)
/*
* call-seq:
* basicsocket.recvmsg_nonblock(maxdatalen=nil, flags=0, maxcontrollen=nil, opts={}) => [data, sender_addrinfo, rflags, *controls]
@@ -1758,6 +1759,9 @@ bsock_recvmsg_nonblock(int argc, VALUE *argv, VALUE sock)
{
return bsock_recvmsg_internal(argc, argv, sock, 1);
}
+#else
+#define bsock_recvmsg_nonblock rb_f_notimplement
+#endif
void
Init_ancdata(void)
diff --git a/ext/socket/basicsocket.c b/ext/socket/basicsocket.c
index 78e675c0d3c..4ffbd497bf3 100644
--- a/ext/socket/basicsocket.c
+++ b/ext/socket/basicsocket.c
@@ -244,6 +244,7 @@ bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
return INT2FIX(0);
}
+#if !defined(__BEOS__)
/*
* Document-method: getsockopt
* call-seq: getsockopt(level, optname)
@@ -287,7 +288,6 @@ bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
static VALUE
bsock_getsockopt(VALUE sock, VALUE lev, VALUE optname)
{
-#if !defined(__BEOS__)
int level, option;
socklen_t len;
char *buf;
@@ -307,10 +307,10 @@ bsock_getsockopt(VALUE sock, VALUE lev, VALUE optname)
rb_sys_fail_path(fptr->pathv);
return rsock_sockopt_new(family, level, option, rb_str_new(buf, len));
+}
#else
- rb_notimplement();
+#define bsock_getsockopt rb_f_notimplement
#endif
-}
/*
* call-seq:
@@ -361,6 +361,7 @@ bsock_getpeername(VALUE sock)
return rb_str_new((char*)&buf, len);
}
+#if defined(HAVE_GETPEEREID) || defined(SO_PEERCRED) || defined(HAVE_GETPEERUCRED)
/*
* call-seq:
* basicsocket.getpeereid => [euid, egid]
@@ -412,10 +413,11 @@ bsock_getpeereid(VALUE self)
ret = rb_assoc_new(UIDT2NUM(ucred_geteuid(uc)), GIDT2NUM(ucred_getegid(uc)));
ucred_free(uc);
return ret;
-#else
- rb_notimplement();
#endif
}
+#else
+#define bsock_getpeereid rb_f_notimplement
+#endif
/*
* call-seq:
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 8b3d681d089..d041293a687 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -75,6 +75,7 @@ pair_yield(VALUE pair)
}
#endif
+#if defined HAVE_SOCKETPAIR
/*
* call-seq:
* Socket.pair(domain, type, protocol) => [socket1, socket2]
@@ -99,7 +100,6 @@ pair_yield(VALUE pair)
VALUE
rsock_sock_s_socketpair(int argc, VALUE *argv, VALUE klass)
{
-#if defined HAVE_SOCKETPAIR
VALUE domain, type, protocol;
int d, t, p, sp[2];
int ret;
@@ -127,10 +127,10 @@ rsock_sock_s_socketpair(int argc, VALUE *argv, VALUE klass)
return rb_ensure(pair_yield, r, io_close, s1);
}
return r;
+}
#else
- rb_notimplement();
+#define rsock_sock_s_socketpair rb_f_notimplement
#endif
-}
/*
* call-seq:
@@ -867,11 +867,7 @@ sock_gethostname(VALUE obj)
return rb_str_new2(un.nodename);
}
#else
-static VALUE
-sock_gethostname(VALUE obj)
-{
- rb_notimplement();
-}
+#define sock_gethostname rb_f_notimplement
#endif
#endif
@@ -1470,6 +1466,7 @@ sockaddr_obj(struct sockaddr *addr)
}
#endif
+#if defined(HAVE_GETIFADDRS) || (defined(SIOCGLIFCONF) && defined(SIOCGLIFNUM) && !defined(__hpux)) || defined(SIOCGIFCONF) || defined(_WIN32)
/*
* call-seq:
* Socket.ip_address_list => array
@@ -1748,10 +1745,11 @@ socket_s_ip_address_list(VALUE self)
CloseHandle(h);
return list;
-#else
- rb_notimplement();
#endif
}
+#else
+#define socket_s_ip_address_list rb_f_notimplement
+#endif
/*
* Class +Socket+ provides access to the underlying operating system
diff --git a/ext/socket/unixsocket.c b/ext/socket/unixsocket.c
index d3ebbf343d5..df1a11d0948 100644
--- a/ext/socket/unixsocket.c
+++ b/ext/socket/unixsocket.c
@@ -171,6 +171,7 @@ sendmsg_blocking(void *data)
return sendmsg(arg->fd, &arg->msg, 0);
}
+#if defined(HAVE_SENDMSG) && (FD_PASSING_BY_MSG_CONTROL || FD_PASSING_BY_MSG_ACCRIGHTS)
/*
* call-seq:
* unixsocket.send_io(io) => nil
@@ -190,7 +191,6 @@ sendmsg_blocking(void *data)
static VALUE
unix_send_io(VALUE sock, VALUE val)
{
-#if defined(HAVE_SENDMSG) && (FD_PASSING_BY_MSG_CONTROL || FD_PASSING_BY_MSG_ACCRIGHTS)
int fd;
rb_io_t *fptr;
struct iomsg_arg arg;
@@ -248,11 +248,10 @@ unix_send_io(VALUE sock, VALUE val)
rb_sys_fail("sendmsg(2)");
return Qnil;
+}
#else
- rb_notimplement();
- return Qnil; /* not reached */
+#define unix_send_io rb_f_notimplement
#endif
-}
static VALUE
recvmsg_blocking(void *data)
@@ -261,6 +260,7 @@ recvmsg_blocking(void *data)
return recvmsg(arg->fd, &arg->msg, 0);
}
+#if defined(HAVE_RECVMSG) && (FD_PASSING_BY_MSG_CONTROL || FD_PASSING_BY_MSG_ACCRIGHTS)
/*
* call-seq:
* unixsocket.recv_io([klass [, mode]]) => io
@@ -283,7 +283,6 @@ recvmsg_blocking(void *data)
static VALUE
unix_recv_io(int argc, VALUE *argv, VALUE sock)
{
-#if defined(HAVE_RECVMSG) && (FD_PASSING_BY_MSG_CONTROL || FD_PASSING_BY_MSG_ACCRIGHTS)
VALUE klass, mode;
rb_io_t *fptr;
struct iomsg_arg arg;
@@ -390,11 +389,10 @@ unix_recv_io(int argc, VALUE *argv, VALUE sock)
ff_argv[1] = mode;
return rb_funcall2(klass, for_fd, ff_argc, ff_argv);
}
+}
#else
- rb_notimplement();
- return Qnil; /* not reached */
+#define unix_recv_io rb_f_notimplement
#endif
-}
/*
* call-seq: