From b56b003fc13a4e12f97c6cfd5dd650e928d6e016 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Sun, 12 Jul 2020 00:00:26 +0200 Subject: Teach minecctl to split things into data and cfg dir, also read config variables from the server.properties file --- minecctl/rcon-commands.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) (limited to 'minecctl/rcon-commands.c') diff --git a/minecctl/rcon-commands.c b/minecctl/rcon-commands.c index 44bb286..cb6ea45 100644 --- a/minecctl/rcon-commands.c +++ b/minecctl/rcon-commands.c @@ -21,18 +21,13 @@ static void send_packet(int sfd, const char *buf, size_t len) size_t off = 0; ssize_t r; - while (true) { + for (off = 0; off < len; off += r) { r = write(sfd, buf + off, len - off); if (r < 0) { - if (errno == EINTR) + if (errno == EAGAIN || errno == EINTR) continue; - else - die("Failed to write packet: %m"); + die("Failed to write packet: %m"); } - - off += r; - if (off == len) - break; } } @@ -40,31 +35,26 @@ static void send_packet(int sfd, const char *buf, size_t len) static void read_packet(int sfd, char *buf, size_t len, int32_t *id, int32_t *type, const char **msg) { - size_t off = 0; + size_t off; ssize_t r; const char *error; - while (true) { + for (off = 0; off < len; off += r) { + if (rcon_protocol_packet_complete(buf, off)) + break; + r = read(sfd, buf + off, len - off); if (r < 0) { if (errno == EINTR) continue; - else - die("Failed to read reply: %m"); - } - - if (r == 0) + die("Failed to read reply: %m"); + } else if (r == 0) die("Failed, connection closed"); - - off += r; - if (rcon_protocol_packet_complete(buf, off)) - break; - - if (off >= len) - die("Reply too large %zu and %zu", off, len); } - if (!rcon_protocol_read_packet(buf, off, id, type, msg, &error)) + if (off >= len) + die("Reply too large %zu and %zu", off, len); + else if (!rcon_protocol_read_packet(buf, off, id, type, msg, &error)) die("Failed to parse response: %s", error); } -- cgit v1.2.3