summaryrefslogtreecommitdiff
path: root/os-posix.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-09-08 19:16:37 -0400
committerpommicket <pommicket@gmail.com>2023-09-08 19:16:37 -0400
commitf86b0aa1e843646056c08a91fcc759aa0d8a57ba (patch)
tree49a48c14c167df8614996d0c5b8d026fc99fc627 /os-posix.c
parent100859239a28c2709bb3e2cdce347300a2b763e2 (diff)
better LSP over TCP
Diffstat (limited to 'os-posix.c')
-rw-r--r--os-posix.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/os-posix.c b/os-posix.c
index 0c408a5..34a7f7b 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -456,9 +456,8 @@ Socket *socket_connect_tcp(const char *address, u16 port) {
}
if (connect(fd, &addr, sizeof addr) < 0) {
- strbuf_printf(s->error, "couldn't connect to %u.%u.%u.%u:%u (%s)",
- address[0], address[1], address[2], address[3], port,
- strerror(errno));
+ strbuf_printf(s->error, "couldn't connect to %s:%u (%s)",
+ address, port, strerror(errno));
}
set_nonblocking(fd);
@@ -487,3 +486,11 @@ long long socket_write(Socket *s, const char *data, size_t size) {
}
return write_fd(s->fd, s->error, sizeof s->error, data, size);
}
+
+void socket_close(Socket **psocket) {
+ Socket *s = *psocket;
+ if (!s) return;
+ if (s->fd > 0)
+ close(s->fd);
+ *psocket = NULL;
+}