summaryrefslogtreecommitdiff
path: root/ext/socket/unixsocket.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-06 02:39:44 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-06 02:39:44 +0000
commitd933fb2296e4ace25c5eb558be56cd23a8fcc88f (patch)
tree597f59b7faf29ed9e5b83692495338a3cb7576fe /ext/socket/unixsocket.c
parente4283fd39d9e8c508ce5ee2dc069b6f5545cd3d8 (diff)
* 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
Diffstat (limited to 'ext/socket/unixsocket.c')
-rw-r--r--ext/socket/unixsocket.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/ext/socket/unixsocket.c b/ext/socket/unixsocket.c
index 6e4e0fc..3d3fc88 100644
--- a/ext/socket/unixsocket.c
+++ b/ext/socket/unixsocket.c
@@ -36,7 +36,7 @@ rsock_init_unixsock(VALUE sock, VALUE path, int server)
SafeStringValue(path);
fd = rsock_socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
- rb_sys_fail("socket(2)");
+ rsock_sys_fail_path("socket(2)", path);
}
INIT_SOCKADDR_UN(&sockaddr, sizeof(struct sockaddr_un));
@@ -65,13 +65,13 @@ rsock_init_unixsock(VALUE sock, VALUE path, int server)
if (status < 0) {
close(fd);
- rb_sys_fail_str(rb_inspect(path));
+ rsock_sys_fail_path("connect(2)", path);
}
if (server) {
if (listen(fd, SOMAXCONN) < 0) {
close(fd);
- rb_sys_fail("listen(2)");
+ rsock_sys_fail_path("listen(2)", path);
}
}
@@ -121,7 +121,7 @@ unix_path(VALUE sock)
socklen_t len = (socklen_t)sizeof(addr);
socklen_t len0 = len;
if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
- rb_sys_fail(0);
+ rsock_sys_fail_path("getsockname(2)", fptr->pathv);
if (len0 < len) len = len0;
fptr->pathv = rb_obj_freeze(rsock_unixpath_str(&addr, len));
}
@@ -255,7 +255,7 @@ unix_send_io(VALUE sock, VALUE val)
arg.fd = fptr->fd;
while ((int)BLOCKING_REGION_FD(sendmsg_blocking, &arg) == -1) {
if (!rb_io_wait_writable(arg.fd))
- rb_sys_fail("sendmsg(2)");
+ rsock_sys_fail_path("sendmsg(2)", fptr->pathv);
}
return Qnil;
@@ -343,7 +343,7 @@ unix_recv_io(int argc, VALUE *argv, VALUE sock)
arg.fd = fptr->fd;
while ((int)BLOCKING_REGION_FD(recvmsg_blocking, &arg) == -1) {
if (!rb_io_wait_readable(arg.fd))
- rb_sys_fail("recvmsg(2)");
+ rsock_sys_fail_path("recvmsg(2)", fptr->pathv);
}
#if FD_PASSING_BY_MSG_CONTROL
@@ -430,7 +430,7 @@ unix_addr(VALUE sock)
GetOpenFile(sock, fptr);
if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
- rb_sys_fail("getsockname(2)");
+ rsock_sys_fail_path("getsockname(2)", fptr->pathv);
if (len0 < len) len = len0;
return rsock_unixaddr(&addr, len);
}
@@ -458,7 +458,7 @@ unix_peeraddr(VALUE sock)
GetOpenFile(sock, fptr);
if (getpeername(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
- rb_sys_fail("getpeername(2)");
+ rsock_sys_fail_path("getpeername(2)", fptr->pathv);
if (len0 < len) len = len0;
return rsock_unixaddr(&addr, len);
}