mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/socket: Improve socket exception message to show socket address.
[ruby-core:45617] [Feature #6583] proposed Eric Hodel. * ext/socket/rubysocket.h (rsock_sys_fail_host_port): Declared. (rsock_sys_fail_path): Ditto. (rsock_sys_fail_sockaddr): Ditto. * ext/socket/udpsocket.c (udp_connect): Use rsock_sys_fail_host_port. (udp_bind): Ditto. (udp_send): Ditto. * ext/socket/init.c (rsock_init_sock): Specify a string for rb_sys_fail argument. (make_fd_nonblock): Ditto. (rsock_s_accept): Ditto. * ext/socket/ipsocket.c (init_inetsock_internal): Use rsock_sys_fail_host_port. * ext/socket/socket.c (rsock_sys_fail_host_port): Defined. (rsock_sys_fail_path): Ditto. (rsock_sys_fail_sockaddr): Ditto. (setup_domain_and_type): Use rsock_sys_fail_sockaddr. (sock_connect_nonblock): Ditto. (sock_bind): Ditto. (sock_gethostname): Specify a string for rb_sys_fail argument. (socket_s_ip_address_list): Ditto. * ext/socket/basicsocket.c (bsock_shutdown): Specify a string for rb_sys_fail argument. (bsock_setsockopt): Use rsock_sys_fail_path. (bsock_getsockopt): Ditto. (bsock_getpeereid): Refine the argument for rb_sys_fail. * ext/socket/unixsocket.c (rsock_init_unixsock): Use rsock_sys_fail_path. (unix_path): Ditto. (unix_send_io): Ditto. (unix_recv_io): Ditto. (unix_addr): Ditto. (unix_peeraddr): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40149 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e4283fd39d
commit
d933fb2296
11 changed files with 182 additions and 28 deletions
|
@ -43,7 +43,7 @@ init_inetsock_internal(struct inetsock_arg *arg)
|
|||
{
|
||||
int type = arg->type;
|
||||
struct addrinfo *res;
|
||||
int fd, status = 0;
|
||||
int fd, status = 0, local = 0;
|
||||
const char *syscall = 0;
|
||||
|
||||
arg->remote.res = rsock_addrinfo(arg->remote.host, arg->remote.serv, SOCK_STREAM,
|
||||
|
@ -81,6 +81,7 @@ init_inetsock_internal(struct inetsock_arg *arg)
|
|||
else {
|
||||
if (arg->local.res) {
|
||||
status = bind(fd, arg->local.res->ai_addr, arg->local.res->ai_addrlen);
|
||||
local = status;
|
||||
syscall = "bind(2)";
|
||||
}
|
||||
|
||||
|
@ -99,7 +100,17 @@ init_inetsock_internal(struct inetsock_arg *arg)
|
|||
break;
|
||||
}
|
||||
if (status < 0) {
|
||||
rb_sys_fail(syscall);
|
||||
VALUE host, port;
|
||||
|
||||
if (local < 0) {
|
||||
host = arg->local.host;
|
||||
port = arg->local.serv;
|
||||
} else {
|
||||
host = arg->remote.host;
|
||||
port = arg->remote.serv;
|
||||
}
|
||||
|
||||
rsock_sys_fail_host_port(syscall, host, port);
|
||||
}
|
||||
|
||||
arg->fd = -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue