commit a8445ba3cd5c5b00fd161f2a946badb0a2a8c19c
parent a78b697325cbbd8080252d615c1f4414d5668245
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:
sacc.c | | | 21 | +++++++++++++++------ |
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/sacc.c b/sacc.c
@@ -285,15 +285,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