summaryrefslogtreecommitdiffstats
path: root/src/socket.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-07-25 15:33:17 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-07-25 15:33:17 +0200
commit5cda45defd17211375236c41d4d98dee1a534672 (patch)
treed9f0725a51f895bda400cab7b8fdecbe8c08434a /src/socket.c
parent900ac61351cabc78b5126adbe9c9936d1c3b5ca6 (diff)
downloadfastd-5cda45defd17211375236c41d4d98dee1a534672.tar
fastd-5cda45defd17211375236c41d4d98dee1a534672.zip
Move more code out of fastd.c
Diffstat (limited to 'src/socket.c')
-rw-r--r--src/socket.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/socket.c b/src/socket.c
index ca6f588..c53695b 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -199,3 +199,26 @@ fastd_socket_t* fastd_socket_open(fastd_context_t *ctx, fastd_peer_t *peer, int
return sock;
}
+
+void fastd_socket_close(fastd_context_t *ctx, fastd_socket_t *sock) {
+ if (sock->fd >= 0) {
+ if(close(sock->fd))
+ pr_error_errno(ctx, "closing socket: close");
+
+ sock->fd = -2;
+ }
+
+ if (sock->bound_addr) {
+ free(sock->bound_addr);
+ sock->bound_addr = NULL;
+ }
+}
+
+void fastd_socket_error(fastd_context_t *ctx, fastd_socket_t *sock) {
+ if (sock->addr->bindtodev)
+ pr_warn(ctx, "socket bind %I on `%s' lost", &sock->addr->addr, sock->addr->bindtodev);
+ else
+ pr_warn(ctx, "socket bind %I lost", &sock->addr->addr);
+
+ fastd_socket_close(ctx, sock);
+}