X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libi3%2Fipc_send_message.c;h=a9ba31653e07cacc1b86ed030075eccccc509a52;hb=884214f14fdbd0a4a368d2a36d5e50324fa1d52a;hp=c5560c0de9789aef20e27ec667cfd36c7ce0464a;hpb=fcdfab4d280cf469f339ce7168082658b9b76c8c;p=i3%2Fi3 diff --git a/libi3/ipc_send_message.c b/libi3/ipc_send_message.c index c5560c0d..a9ba3165 100644 --- a/libi3/ipc_send_message.c +++ b/libi3/ipc_send_message.c @@ -2,7 +2,7 @@ * vim:ts=4:sw=4:expandtab * * i3 - an improved dynamic tiling window manager - * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE) + * © 2009 Michael Stapelberg and contributors (see also: LICENSE) * */ #include @@ -28,38 +28,15 @@ int ipc_send_message(int sockfd, const uint32_t message_size, const uint32_t message_type, const uint8_t *payload) { const i3_ipc_header_t header = { /* We don’t use I3_IPC_MAGIC because it’s a 0-terminated C string. */ - .magic = { 'i', '3', '-', 'i', 'p', 'c' }, + .magic = {'i', '3', '-', 'i', 'p', 'c'}, .size = message_size, - .type = message_type - }; + .type = message_type}; - int sent_bytes = 0; - int n = 0; + if (writeall(sockfd, ((void *)&header), sizeof(i3_ipc_header_t)) == -1) + return -1; - /* This first loop is basically unnecessary. No operating system has - * buffers which cannot fit 14 bytes into them, so the write() will only be - * called once. */ - while (sent_bytes < sizeof(i3_ipc_header_t)) { - if ((n = write(sockfd, ((void*)&header) + sent_bytes, sizeof(i3_ipc_header_t) - sent_bytes)) == -1) { - if (errno == EAGAIN) - continue; - return -1; - } - - sent_bytes += n; - } - - sent_bytes = 0; - - while (sent_bytes < message_size) { - if ((n = write(sockfd, payload + sent_bytes, message_size - sent_bytes)) == -1) { - if (errno == EAGAIN) - continue; - return -1; - } - - sent_bytes += n; - } + if (writeall(sockfd, payload, message_size) == -1) + return -1; return 0; }