sacc

sacc (saccomys): simple gopher client.
Log | Files | Refs | LICENSE

commit a7cbd6c2d6b4c9d207b91532734915745c2a038f
parent 003389c2413507d55bef23954aab7ac06f260c7a
Author: Quentin Rameau <quinq@fifth.space>
Date:   Tue, 20 Jun 2017 21:02:27 +0200

Handle empty response from server

Diffstat:
sacc.c | 28++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/sacc.c b/sacc.c @@ -279,24 +279,31 @@ connectto(const char *host, const char *port) return sock; } -void +int dig(Item *entry, Item *item) { int sock; - if (item->target || /* already in cache */ - item->type > '1') /* not supported */ - return; + if (item->target) /* already in cache */ + return 1; + + item->entry = entry; + + if (item->type > '1') /* not supported */ + return 0; sock = connectto(item->host, item->port); sendselector(sock, item->selector); - item->entry = entry; item->raw = getrawitem(sock); + if (!*item->raw) /* empty read */ + return 0; + if (item->type == '0') item->target = item->raw; else if (item->type == '1') item->target = parsediritem(item->raw); + return 1; } Item * @@ -375,9 +382,14 @@ main(int argc, char *argv[]) hole = parseurl(argv[1]); for (;;) { - dig(entry, hole); - if (!(n = display(hole))) - break; + if (dig(entry, hole)) { + n = display(hole); + } else { + n = 0; + fprintf(stderr, "Couldn't get %s:%s/%c%s\n", + hole->host, hole->port, + hole->type, hole->selector); + } do { printf("%d items, visit (0: back, ^D or q: quit): ", n); if (!fgets(buf, sizeof(buf), stdin)) {