commit d1db3194cc1350795afe44cda9e73d916e74e71c
parent fa93a3cfbc2505d467a4c58b1faadc36ed667cea
Author: Quentin Rameau <quinq@fifth.space>
Date: Thu, 22 Jun 2017 23:38:41 +0200
Ensure we write all we want on the socket
Diffstat:
M | sacc.c | | | 21 | +++++++++++++++------ |
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/sacc.c b/sacc.c
@@ -282,15 +282,24 @@ getrawitem(int sock)
return raw;
}
-int
+void
sendselector(int sock, const char *selector)
{
- if (write(sock, selector, strlen(selector)) < 0)
- die("Can't send message: %s", strerror(errno));
- if (write(sock, "\r\n", strlen("\r\n")) < 0)
- die("Can't send message: %s", strerror(errno));
+ char *msg, *p;
+ size_t ln;
+ ssize_t n;
- return 1;
+ ln = strlen(selector) + 3;
+ msg = p = xmalloc(ln);
+ snprintf(msg, ln--, "%s\r\n", selector);
+
+ while ((n = write(sock, p, ln)) != -1 && n != 0) {
+ ln -= n;
+ p += n;
+ }
+ free(msg);
+ if (n == -1)
+ die("Can't send message: %s", strerror(errno));
}
int