Issue #20: improve socket set-up logging

This commit is contained in:
Andrew Bettison 2013-09-19 04:13:06 +09:30
parent 259834a4c1
commit d64d9487c1
3 changed files with 9 additions and 10 deletions

View File

@ -78,10 +78,8 @@ struct profile_total client_stats;
int monitor_setup_sockets()
{
int sock = -1;
if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
WHYF_perror("socket(AF_UNIX, SOCK_STREAM, 0)");
if ((sock = esocket(AF_UNIX, SOCK_STREAM, 0)) == -1)
goto error;
}
struct sockaddr_un addr;
socklen_t addrlen;
if (socket_setname(&addr, config.monitor.socket, &addrlen) == -1)
@ -93,14 +91,13 @@ int monitor_setup_sockets()
if (socket_set_reuseaddr(sock, 1) == -1)
WHY("Could not indicate reuse addresses. Not necessarily a problem (yet)");
socket_set_rcvbufsize(sock, 64 * 1024);
if (config.debug.io || config.debug.verbose_io)
DEBUGF("Monitor server socket bound to %s", alloca_sockaddr(&addr, addrlen));
named_socket.function=monitor_poll;
named_stats.name="monitor_poll";
named_socket.stats=&named_stats;
named_socket.poll.fd=sock;
named_socket.poll.events=POLLIN;
watch(&named_socket);
INFOF("Monitor socket: fd=%d %s", sock, alloca_sockaddr(&addr, addrlen));
return 0;
error:

View File

@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "conf.h"
#include "str.h"
#include "strbuf.h"
#include "strbuf_helpers.h"
#include "overlay_buffer.h"
#include "overlay_address.h"
#include "overlay_packet.h"
@ -89,15 +90,16 @@ int overlay_mdp_setup_sockets()
return -1;
}
socket_set_rcvbufsize(mdp_sock.poll.fd, 64 * 1024);
/*
#if 0
int buffer_size = 64 * 1024;
if (setsockopt(mdp_sock.poll.fd, SOL_SOCKET, SO_SNDBUF, &buffer_size, sizeof(buffer_size)) == -1)
WARNF_perror("setsockopt(%d,SOL_SOCKET,SO_SNDBUF,&%d,%d)", mdp_sock.poll.fd, buffer_size, sizeof buffer_size);
*/
#endif
mdp_sock.function = overlay_mdp_poll;
mdp_sock.stats = &mdp_stats;
mdp_sock.poll.events = POLLIN;
watch(&mdp_sock);
INFOF("MDP socket: fd=%d %s", mdp_sock.poll.fd, alloca_sockaddr(&addr, addrlen));
}
return 0;
}

View File

@ -319,7 +319,7 @@ strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t
strbuf_toprint_quoted_len(sb, "\"\"", addr->sa_data, len);
if (len < 2)
strbuf_sprintf(sb, " (addrlen=%d too short)", (int)addrlen);
if (len && addr->sa_data[len - 1] != '\0')
if (len == 0 || addr->sa_data[len - 1] != '\0')
strbuf_sprintf(sb, " (addrlen=%d, no nul terminator)", (int)addrlen);
} else {
strbuf_puts(sb, "abstract ");
@ -330,8 +330,6 @@ strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t
}
break;
case AF_INET: {
if (addrlen != sizeof(struct sockaddr_in))
strbuf_sprintf(sb, " (addrlen=%d should be %d)", (int)addrlen, sizeof(struct sockaddr_in));
const struct sockaddr_in *addr_in = (const struct sockaddr_in *) addr;
strbuf_sprintf(sb, " %u.%u.%u.%u:%u",
((unsigned char *) &addr_in->sin_addr.s_addr)[0],
@ -340,6 +338,8 @@ strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t
((unsigned char *) &addr_in->sin_addr.s_addr)[3],
ntohs(addr_in->sin_port)
);
if (addrlen != sizeof(struct sockaddr_in))
strbuf_sprintf(sb, " (addrlen=%d should be %d)", (int)addrlen, sizeof(struct sockaddr_in));
}
break;
default: {