diff options
author | pommicket <pommicket@gmail.com> | 2023-09-08 19:16:37 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-09-08 19:16:37 -0400 |
commit | f86b0aa1e843646056c08a91fcc759aa0d8a57ba (patch) | |
tree | 49a48c14c167df8614996d0c5b8d026fc99fc627 /os-posix.c | |
parent | 100859239a28c2709bb3e2cdce347300a2b763e2 (diff) |
better LSP over TCP
Diffstat (limited to 'os-posix.c')
-rw-r--r-- | os-posix.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -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; +} |