diff options
author | David Härdeman <david@hardeman.nu> | 2020-07-12 00:00:26 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-07-12 00:00:26 +0200 |
commit | b56b003fc13a4e12f97c6cfd5dd650e928d6e016 (patch) | |
tree | a68b48604bccd9a96225bf1c3be21fc05a022b6b /minecctl/rcon-commands.c | |
parent | e6fdfd4c4c753fe3a06edc4ae3b767c57c10d3f7 (diff) |
Teach minecctl to split things into data and cfg dir, also read config variables from the server.properties file
Diffstat (limited to 'minecctl/rcon-commands.c')
-rw-r--r-- | minecctl/rcon-commands.c | 36 |
1 files changed, 13 insertions, 23 deletions
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); } |