Switch to LOG macro
This commit is contained in:
@@ -33,13 +33,15 @@ struct outgoing {
|
||||
|
||||
static struct list_head outgoing_head = LIST_HEAD_INIT(outgoing_head);
|
||||
|
||||
static char log_module = 'O';
|
||||
|
||||
static void outgoing_connect_result(struct outgoing *, int);
|
||||
static void outgoing_resolve(struct outgoing *);
|
||||
static void outgoing_resolve_wrapper(struct peer *);
|
||||
|
||||
static void outgoing_retry(struct outgoing *outgoing) {
|
||||
uint32_t delay = wakeup_get_retry_delay_ms(++outgoing->attempt);
|
||||
log_write('O', outgoing->id, "Will retry in %ds", delay / 1000);
|
||||
LOG(outgoing->id, "Will retry in %ds", delay / 1000);
|
||||
outgoing->peer.event_handler = outgoing_resolve_wrapper;
|
||||
wakeup_add((struct peer *) outgoing, delay);
|
||||
}
|
||||
@@ -47,14 +49,14 @@ static void outgoing_retry(struct outgoing *outgoing) {
|
||||
static void outgoing_connect_next(struct outgoing *outgoing) {
|
||||
if (outgoing->addr == NULL) {
|
||||
freeaddrinfo(outgoing->addrs);
|
||||
log_write('O', outgoing->id, "Can't connect to any addresses of %s/%s", outgoing->node, outgoing->service);
|
||||
LOG(outgoing->id, "Can't connect to any addresses of %s/%s", outgoing->node, outgoing->service);
|
||||
outgoing_retry(outgoing);
|
||||
return;
|
||||
}
|
||||
|
||||
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
||||
assert(getnameinfo(outgoing->addr->ai_addr, outgoing->addr->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0);
|
||||
log_write('O', outgoing->id, "Connecting to %s/%s...", hbuf, sbuf);
|
||||
LOG(outgoing->id, "Connecting to %s/%s...", hbuf, sbuf);
|
||||
|
||||
outgoing->peer.fd = socket(outgoing->addr->ai_family, outgoing->addr->ai_socktype | SOCK_NONBLOCK | SOCK_CLOEXEC, outgoing->addr->ai_protocol);
|
||||
assert(outgoing->peer.fd >= 0);
|
||||
@@ -81,7 +83,7 @@ static void outgoing_disconnect_handler(struct peer *peer) {
|
||||
if (outgoing->peer.fd != -1) {
|
||||
assert(!close(outgoing->peer.fd));
|
||||
}
|
||||
log_write('O', outgoing->id, "Peer disconnected; reconnecting...");
|
||||
LOG(outgoing->id, "Peer disconnected; reconnecting...");
|
||||
outgoing_retry(outgoing);
|
||||
}
|
||||
|
||||
@@ -90,7 +92,7 @@ static void outgoing_connect_result(struct outgoing *outgoing, int result) {
|
||||
assert(getnameinfo(outgoing->addr->ai_addr, outgoing->addr->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0);
|
||||
switch (result) {
|
||||
case 0:
|
||||
log_write('O', outgoing->id, "Connected to %s/%s", hbuf, sbuf);
|
||||
LOG(outgoing->id, "Connected to %s/%s", hbuf, sbuf);
|
||||
freeaddrinfo(outgoing->addrs);
|
||||
outgoing->attempt = 0;
|
||||
int fd = outgoing->peer.fd;
|
||||
@@ -107,7 +109,7 @@ static void outgoing_connect_result(struct outgoing *outgoing, int result) {
|
||||
break;
|
||||
|
||||
default:
|
||||
log_write('O', outgoing->id, "Can't connect to %s/%s: %s", hbuf, sbuf, strerror(result));
|
||||
LOG(outgoing->id, "Can't connect to %s/%s: %s", hbuf, sbuf, strerror(result));
|
||||
assert(!close(outgoing->peer.fd));
|
||||
outgoing->peer.fd = -1;
|
||||
outgoing->addr = outgoing->addr->ai_next;
|
||||
@@ -121,7 +123,7 @@ static void outgoing_resolve_handler(struct peer *peer) {
|
||||
struct outgoing *outgoing = (struct outgoing *) peer;
|
||||
int err = resolve_result(peer, &outgoing->addrs);
|
||||
if (err) {
|
||||
log_write('O', outgoing->id, "Failed to resolve %s/%s: %s", outgoing->node, outgoing->service, gai_strerror(err));
|
||||
LOG(outgoing->id, "Failed to resolve %s/%s: %s", outgoing->node, outgoing->service, gai_strerror(err));
|
||||
outgoing_retry(outgoing);
|
||||
} else {
|
||||
outgoing->addr = outgoing->addrs;
|
||||
@@ -130,7 +132,7 @@ static void outgoing_resolve_handler(struct peer *peer) {
|
||||
}
|
||||
|
||||
static void outgoing_resolve(struct outgoing *outgoing) {
|
||||
log_write('O', outgoing->id, "Resolving %s/%s...", outgoing->node, outgoing->service);
|
||||
LOG(outgoing->id, "Resolving %s/%s...", outgoing->node, outgoing->service);
|
||||
outgoing->peer.event_handler = outgoing_resolve_handler;
|
||||
resolve((struct peer *) outgoing, outgoing->node, outgoing->service, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user