summaryrefslogtreecommitdiff
path: root/ext/socket/socket.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-04 10:13:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-04 10:13:36 +0000
commita3f2fe4e4def0d9e616b0107bf619e3eaf0d788a (patch)
tree61419650bcf504baf8383e62f6b9dae7e7df3dc6 /ext/socket/socket.c
parentde7e488b08ab980db10d21d32b12899f614baf75 (diff)
socket.c: use rb_syserr_fail
* ext/socket/socket.c (rsock_syserr_fail_host_port): add errno argument version anduse rb_syserr_fail_str() instead of rb_sys_fail_str() with restoring errno. * ext/socket/socket.c (rsock_syserr_fail_path): ditto, and rb_syserr_fail(). * ext/socket/socket.c (rsock_sys_fail_sockaddr): ditto, use rsock_syserr_fail_raddrinfo(). * ext/socket/socket.c (rsock_sys_fail_raddrinfo): ditto. * ext/socket/socket.c (setup_domain_and_type): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/socket.c')
-rw-r--r--ext/socket/socket.c53
1 files changed, 36 insertions, 17 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index c968598..c7fc5b7 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -15,23 +15,32 @@ static VALUE sock_s_unpack_sockaddr_in(VALUE, VALUE);
void
rsock_sys_fail_host_port(const char *mesg, VALUE host, VALUE port)
{
+ rsock_syserr_fail_host_port(errno, mesg, host, port);
+}
+
+void
+rsock_syserr_fail_host_port(int err, const char *mesg, VALUE host, VALUE port)
+{
VALUE message;
- int err = errno;
port = rb_String(port);
message = rb_sprintf("%s for \"%s\" port %s",
mesg, StringValueCStr(host), StringValueCStr(port));
- errno = err;
- rb_sys_fail_str(message);
+ rb_syserr_fail_str(err, message);
}
void
rsock_sys_fail_path(const char *mesg, VALUE path)
{
+ rsock_syserr_fail_path(errno, mesg, path);
+}
+
+void
+rsock_syserr_fail_path(int err, const char *mesg, VALUE path)
+{
VALUE message;
- int err = errno;
if (RB_TYPE_P(path, T_STRING)) {
if (memchr(RSTRING_PTR(path), '\0', RSTRING_LEN(path))) {
@@ -43,54 +52,64 @@ rsock_sys_fail_path(const char *mesg, VALUE path)
message = rb_sprintf("%s for \"%s\"", mesg,
StringValueCStr(path));
}
- errno = err;
- rb_sys_fail_str(message);
+ rb_syserr_fail_str(err, message);
}
else {
- rb_sys_fail(mesg);
+ rb_syserr_fail(err, mesg);
}
}
void
rsock_sys_fail_sockaddr(const char *mesg, struct sockaddr *addr, socklen_t len)
{
+ rsock_syserr_fail_sockaddr(errno, mesg, addr, len);
+}
+
+void
+rsock_syserr_fail_sockaddr(int err, const char *mesg, struct sockaddr *addr, socklen_t len)
+{
VALUE rai;
- int err = errno;
rai = rsock_addrinfo_new(addr, len, PF_UNSPEC, 0, 0, Qnil, Qnil);
- errno = err;
- rsock_sys_fail_raddrinfo(mesg, rai);
+ rsock_syserr_fail_raddrinfo(err, mesg, rai);
}
void
rsock_sys_fail_raddrinfo(const char *mesg, VALUE rai)
{
+ rsock_syserr_fail_raddrinfo(errno, mesg, rai);
+}
+
+void
+rsock_syserr_fail_raddrinfo(int err, const char *mesg, VALUE rai)
+{
VALUE str, message;
- int err = errno;
str = rsock_addrinfo_inspect_sockaddr(rai);
message = rb_sprintf("%s for %s", mesg, StringValueCStr(str));
- errno = err;
- rb_sys_fail_str(message);
+ rb_syserr_fail_str(err, message);
}
void
rsock_sys_fail_raddrinfo_or_sockaddr(const char *mesg, VALUE addr, VALUE rai)
{
- int err = errno;
+ rsock_syserr_fail_raddrinfo_or_sockaddr(errno, mesg, addr, rai);
+}
+void
+rsock_syserr_fail_raddrinfo_or_sockaddr(int err, const char *mesg, VALUE addr, VALUE rai)
+{
if (NIL_P(rai)) {
StringValue(addr);
- errno = err;
- rsock_sys_fail_sockaddr(mesg,
+ rsock_syserr_fail_sockaddr(err, mesg,
(struct sockaddr *)RSTRING_PTR(addr),
(socklen_t)RSTRING_LEN(addr)); /* overflow should be checked already */
}
else
- rsock_sys_fail_raddrinfo(mesg, rai);
+ rsock_syserr_fail_raddrinfo(err, mesg, rai);
}
static void