select: gather statistics for TCP connections

osmocom applications are deployed in a variety of different situations.
Dependung on the medium that interconnects the network components
unexpected behaviour may occur. To debug problems with the
interconnection between network components it might help to monitor the
health of the related TCP connections.

Change-Id: I1416f95aff2adcf13689646b7574845de169fa3d
Related: SYS#5701
diff --git a/src/select.c b/src/select.c
index 590c3db..b48d13e 100644
--- a/src/select.c
+++ b/src/select.c
@@ -33,6 +33,8 @@
 #include <osmocom/core/logging.h>
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/utils.h>
+#include <osmocom/core/stat_item.h>
+#include <osmocom/core/stats_tcp.h>
 
 #include "../config.h"
 
@@ -181,6 +183,9 @@
 #ifndef FORCE_IO_SELECT
 	g_poll.num_registered--;
 #endif /* FORCE_IO_SELECT */
+
+	/* If existent, free any statistical data */
+	osmo_stats_tcp_osmo_fd_unregister(fd);
 }
 
 /*! Close a file descriptor, mark it as closed + unregister from select loop abstraction