summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7b0d0d7)
raw | patch | inline | side by side (parent: 7b0d0d7)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 6 Feb 2014 08:19:31 +0000 (09:19 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 6 Feb 2014 08:19:31 +0000 (09:19 +0100) |
In a lot of cases, a client is passed through a couple of functions in order
to handle I/O. Adding the flag will make it easier to access the information
in the right location without having to worry about 0 return codes (which mean
different things in some cases anyway, e.g. in sdb_client_recv() which returns
zero if an empty message (header only) has been received).
to handle I/O. Adding the flag will make it easier to access the information
in the right location without having to worry about 0 return codes (which mean
different things in some cases anyway, e.g. in sdb_client_recv() which returns
zero if an empty message (header only) has been received).
src/client/sock.c | patch | blob | history | |
src/include/client/sock.h | patch | blob | history |
diff --git a/src/client/sock.c b/src/client/sock.c
index 59c77873e08411b22a9c1e5a6a857a8e269210f5..042dd63bd99a353764b8176289de65f5276730f8 100644 (file)
--- a/src/client/sock.c
+++ b/src/client/sock.c
struct sdb_client {
char *address;
int fd;
+ _Bool eof;
};
/*
}
memset(client, 0, sizeof(*client));
client->fd = -1;
+ client->eof = 1;
client->address = strdup(address);
if (! client->address) {
if (client->fd < 0)
return -1;
+ client->eof = 0;
/* XXX */
if (! username)
close(client->fd);
client->fd = -1;
+ client->eof = 1;
} /* sdb_client_close */
ssize_t
continue;
return status;
}
- else if (! status) /* EOF */
+ else if (! status) {
+ client->eof = 1;
break;
+ }
total += (size_t)status;
return (ssize_t)total;
} /* sdb_client_recv */
+_Bool
+sdb_client_eof(sdb_client_t *client)
+{
+ if ((! client) || (client->fd < 0))
+ return 1;
+ return client->eof;
+} /* sdb_client_eof */
+
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
index 39e7622f3b1959fd1fbb1de11301adc25a1b842b..4fd54baa1c5fa7ac99c3c0f46bbf2e2d8f8f2cd6 100644 (file)
sdb_client_recv(sdb_client_t *client,
uint32_t *code, sdb_strbuf_t *buf);
+/*
+ * sdb_client_eof:
+ * Returns true if end of file on the client connection was reached, that is,
+ * if the remote side closed the connection.
+ */
+_Bool
+sdb_client_eof(sdb_client_t *client);
+
#ifdef __cplusplus
} /* extern "C" */
#endif