summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c49
1 files changed, 24 insertions, 25 deletions
diff --git a/utils.c b/utils.c
index 5830dfc..c36d18a 100644
--- a/utils.c
+++ b/utils.c
@@ -125,21 +125,21 @@ debug_resource_usage()
ssize_t r;
unsigned file_count = 0;
- fprintf(stderr, "Still malloced %i (total %u)\n",
- malloc_count, total_malloc_count);
+ debug(DBG_MALLOC, "Still malloced %i (total %u)\n",
+ malloc_count, total_malloc_count);
list_for_each_entry(a, &malloc_list, list) {
- fprintf(stderr, "* Lost allocation - %s:%i - ptr: %p, size: %zu\n",
- a->callerfn, a->line, a->ptr, a->size);
+ debug(DBG_MALLOC, "* Lost allocation - %s:%i - ptr: %p, size: %zu\n",
+ a->callerfn, a->line, a->ptr, a->size);
}
dir = opendir("/proc/self/fd");
if (!dir) {
- fprintf(stderr, "Failed to open fd dir\n");
+ error("failed to open fd dir\n");
return;
}
- fprintf(stderr, "Open files:\n");
+ debug(DBG_MALLOC, "Open files:\n");
while ((dent = readdir(dir)) != NULL) {
if (!strcmp(dent->d_name, ".") ||
!strcmp(dent->d_name, ".."))
@@ -147,22 +147,20 @@ debug_resource_usage()
r = readlinkat(dirfd(dir), dent->d_name, buf, sizeof(buf));
if (r < 0) {
- fprintf(stderr, "Failed to readlink %s\n", dent->d_name);
+ debug(DBG_MALLOC, "Failed to readlink %s\n", dent->d_name);
continue;
}
buf[r] = '\0';
- fprintf(stderr, " * %s -> %s\n", dent->d_name, buf);
+ debug(DBG_MALLOC, " * %s -> %s\n", dent->d_name, buf);
file_count++;
}
closedir(dir);
- if (file_count > 4) {
- fprintf(stderr, "Lost file descriptor(s)\n");
- exit(EXIT_FAILURE);
- }
+ if (file_count > 4)
+ debug(DBG_MALLOC, "Lost file descriptor(s)\n");
- fprintf(stderr, "CQEs used: %" PRIu64 ", SQEs used: %" PRIu64 "\n",
- cqe_count, sqe_count);
+ debug(DBG_MALLOC, "CQEs used: %" PRIu64 ", SQEs used: %" PRIu64 "\n",
+ cqe_count, sqe_count);
}
void
@@ -176,17 +174,17 @@ socket_set_low_latency(struct cfg *cfg, int sfd)
/* FIXME: could make this configurable */
option = true;
if (setsockopt(sfd, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option)) < 0)
- perror("setsockopt");
+ error("setsockopt: %m");
/* Doubtful if it has much effect, but can't hurt */
option = IPTOS_LOWDELAY;
if (setsockopt(sfd, IPPROTO_IP, IP_TOS, &option, sizeof(option)) < 0)
- perror("setsockopt");
+ error("setsockopt: %m");
/* Nagle's algorithm is a poor fit for gaming */
option = true;
if (setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, &option, sizeof(option)) < 0)
- perror("setsockopt");
+ error("setsockopt: %m");
}
void
@@ -215,8 +213,8 @@ connect_cb(struct cfg *cfg, struct uring_task *task, int res)
struct connection *conn = task->priv;
if (res < 0) {
- fprintf(stderr, "%s: connection to %s failed\n",
- __func__, conn->remotestr);
+ debug(DBG_UR, "%s: connection to %s failed\n",
+ task->name, conn->remotestr);
uring_task_close_fd(cfg, task);
connect_next(cfg, task, conn);
return;
@@ -224,8 +222,8 @@ connect_cb(struct cfg *cfg, struct uring_task *task, int res)
connection_set_local(cfg, conn, task->fd);
- fprintf(stderr, "%s: (%s) connection established %s -> %s\n",
- __func__, task->name, conn->localstr, conn->remotestr);
+ debug(DBG_UR, "%s: connection established %s -> %s\n",
+ task->name, conn->localstr, conn->remotestr);
conn->callback(cfg, conn, true);
}
@@ -249,15 +247,16 @@ again:
}
if (!remote) {
- fprintf(stderr, "%s: no more remote addresses to attempt\n", __func__);
+ debug(DBG_UR, "%s: no more remote addresses to attempt\n",
+ task->name);
conn->callback(cfg, conn, false);
return;
}
conn->next_addr++;
connection_set_remote(cfg, conn, remote);
- fprintf(stderr, "%s: attempting to connect to %s\n",
- task->name, conn->remotestr);
+ debug(DBG_MALLOC, "%s: attempting to connect to %s\n",
+ task->name, conn->remotestr);
sfd = socket(conn->remote.storage.ss_family, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (sfd < 0) {
@@ -278,7 +277,7 @@ connect_any(struct cfg *cfg, struct uring_task *task,
void (*callback)(struct cfg *, struct connection *, bool res))
{
if (!cfg || !task || !addrs || !conn || !callback) {
- fprintf(stderr, "%s: invalid arguments\n", __func__);
+ error("invalid arguments\n");
return;
}