Skip to content

Commit b9a16b9

Browse files
committed
Update: Improved debug logging for connection and socket handling
1 parent ababd1c commit b9a16b9

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/client.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,11 @@ int client_create(client_t **c_ptr, connection_t *con, http_parser_t *parser)
175175

176176
listener_real = listensocket_get_listener(con->listensocket_real);
177177
listener_effective = listensocket_get_listener(con->listensocket_effective);
178-
ICECAST_LOG_DEBUG("Client %p created on connection %p (connection ID: %llu, socket real: %p \"%H\", socket effective: %p \"%H\")",
179-
client, con, (long long unsigned int)con->id,
178+
ICECAST_LOG_DEBUG("Client %p created on connection %p (connection ID: %llu, sock=%R, socket real: %p (%#H), socket effective: %p (%#H); global: %d of %d)",
179+
client, con, (long long unsigned int)con->id, con->sock,
180180
con->listensocket_real, con->listensocket_real ? listener_real->id : NULL,
181-
con->listensocket_effective, con->listensocket_effective ? listener_effective->id : NULL
181+
con->listensocket_effective, con->listensocket_effective ? listener_effective->id : NULL,
182+
global.clients, config->client_limit
182183
);
183184
listensocket_release_listener(con->listensocket_effective);
184185
listensocket_release_listener(con->listensocket_real);
@@ -260,8 +261,9 @@ static inline void client_reuseconnection(client_t *client) {
260261
return;
261262
}
262263

264+
ICECAST_LOG_DEBUG("Reusing connection %p (connection ID: %llu, sock=%R) of old client %p", con, (long long unsigned int)con->id, con->sock, client);
263265
con = connection_create(con->sock, con->listensocket_real, con->listensocket_effective, strdup(con->ip));
264-
client->con->sock = -1; /* TODO: do not use magic */
266+
client->con->sock = SOCK_ERROR;
265267

266268
/* handle to keep the TLS connection */
267269
if (client->con->tls) {
@@ -294,9 +296,12 @@ static inline void client_reuseconnection(client_t *client) {
294296

295297
void client_destroy(client_t *client)
296298
{
297-
ICECAST_LOG_DEBUG("Called to destory client %p", client);
298-
if (client == NULL)
299+
if (client == NULL) {
300+
ICECAST_LOG_ERROR("Called with client=NULL. This is a BUG.");
299301
return;
302+
}
303+
304+
ICECAST_LOG_DEBUG("Called to destory client %p on connection %p (connection ID: %llu, sock=%R)", client, client->con, (long long unsigned int)client->con->id, client->con->sock);
300305

301306
fastevent_emit(FASTEVENT_TYPE_CLIENT_DESTROY, FASTEVENT_FLAG_MODIFICATION_ALLOWED, FASTEVENT_DATATYPE_CLIENT, client);
302307

src/connection.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1767,10 +1767,12 @@ void connection_close(connection_t *con)
17671767
if (!con)
17681768
return;
17691769

1770+
ICECAST_LOG_DEBUG("Closing connection %p (connection ID: %llu, sock=%R)", con, (long long unsigned int)con->id, con->sock);
1771+
17701772
fastevent_emit(FASTEVENT_TYPE_CONNECTION_DESTROY, FASTEVENT_FLAG_MODIFICATION_ALLOWED, FASTEVENT_DATATYPE_CONNECTION, con);
17711773

17721774
tls_unref(con->tls);
1773-
if (con->sock != -1) /* TODO: do not use magic */
1775+
if (con->sock != SOCK_ERROR)
17741776
sock_close(con->sock);
17751777
if (con->ip)
17761778
free(con->ip);

src/listensocket.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -774,17 +774,17 @@ connection_t * listensocket_accept(listensocket_t *self, listensock
774774
return NULL;
775775
}
776776

777+
ICECAST_LOG_DEBUG("Client (sock=%R, ip=%#H) on socket %p (%#H).", sock, ip, self, self->listener->id);
778+
777779
if (strncmp(ip, "::ffff:", 7) == 0) {
778780
memmove(ip, ip+7, strlen(ip+7)+1);
779781
}
780782

781-
ICECAST_LOG_DEBUG("Client on socket %p \"%H\".", self, self->listener->id);
782-
783783
if (self->listener->on_behalf_of) {
784-
ICECAST_LOG_DEBUG("This socket is acting on behalf of \"%H\"", self->listener->on_behalf_of);
784+
ICECAST_LOG_DEBUG("This socket is acting on behalf of %#H", self->listener->on_behalf_of);
785785
effective = listensocket_container_get_by_id(container, self->listener->on_behalf_of);
786786
if (!effective) {
787-
ICECAST_LOG_ERROR("Can not find listen socket with ID \"%H\". Will continue on behalf of myself.", self->listener->on_behalf_of);
787+
ICECAST_LOG_ERROR("Can not find listen socket with ID %#H. Will continue on behalf of myself.", self->listener->on_behalf_of);
788788
}
789789
}
790790

0 commit comments

Comments
 (0)