mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
de7e488b08
commit
a3f2fe4e4d
3 changed files with 58 additions and 17 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
Sat Jan 4 19:13:34 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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.
|
||||
|
||||
Sat Jan 4 17:18:58 2014 Kazuki Tsujimoto <kazuki@callcc.net>
|
||||
|
||||
* vm.c (RubyVM::OPTS): get rid of a garbage character.
|
||||
|
|
|
@ -374,6 +374,12 @@ void rsock_init_sockopt(void);
|
|||
void rsock_init_sockifaddr(void);
|
||||
void rsock_init_socket_init(void);
|
||||
|
||||
NORETURN(void rsock_syserr_fail_host_port(int err, const char *, VALUE, VALUE));
|
||||
NORETURN(void rsock_syserr_fail_path(int err, const char *, VALUE));
|
||||
NORETURN(void rsock_syserr_fail_sockaddr(int err, const char *mesg, struct sockaddr *addr, socklen_t len));
|
||||
NORETURN(void rsock_syserr_fail_raddrinfo(int err, const char *mesg, VALUE rai));
|
||||
NORETURN(void rsock_syserr_fail_raddrinfo_or_sockaddr(int err, const char *mesg, VALUE addr, VALUE rai));
|
||||
|
||||
NORETURN(void rsock_sys_fail_host_port(const char *, VALUE, VALUE));
|
||||
NORETURN(void rsock_sys_fail_path(const char *, VALUE));
|
||||
NORETURN(void rsock_sys_fail_sockaddr(const char *, struct sockaddr *addr, socklen_t len));
|
||||
|
|
|
@ -14,24 +14,33 @@ 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
|
||||
|
|
Loading…
Add table
Reference in a new issue