summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorm <m@bitsnbites.eu>2019-03-31 18:10:34 +0200
committerMarcus Geelnard <marcus.geelnard@smarteye.se>2019-04-01 11:52:24 +0200
commit1d092a235aae92cb9a4fe260c385a850eadfc611 (patch)
treee561a2738ee0a1a5566a7c1e92f608bb629910a1
parente84086cb92bfcab88e7dfd7760351e3d2a65950d (diff)
Use recv/send instead of read/write
The recv/send calls are more portable than read/write, since unlike the latter, the former work with Windows sockets. We also check for EWOULDBLOCK instead of EAGAIN. On most Unices, EAGAIN and EWOULDBLBOCK are the same thing. However, on Windows they are different, and send/recv are expected to give EWOULDBLOCK for non-blocking sockets.
-rw-r--r--net.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/net.c b/net.c
index 87b7fbb..0c8f5b3 100644
--- a/net.c
+++ b/net.c
@@ -65,9 +65,9 @@ void redisNetClose(redisContext *c) {
}
int redisNetRead(redisContext *c, char *buf, size_t bufcap) {
- int nread = read(c->fd, buf, bufcap);
+ int nread = recv(c->fd, buf, bufcap, 0);
if (nread == -1) {
- if ((errno == EAGAIN && !(c->flags & REDIS_BLOCK)) || (errno == EINTR)) {
+ if ((errno == EWOULDBLOCK && !(c->flags & REDIS_BLOCK)) || (errno == EINTR)) {
/* Try again later */
return 0;
} else {
@@ -83,9 +83,9 @@ int redisNetRead(redisContext *c, char *buf, size_t bufcap) {
}
int redisNetWrite(redisContext *c) {
- int nwritten = write(c->fd, c->obuf, sdslen(c->obuf));
+ int nwritten = send(c->fd, c->obuf, sdslen(c->obuf), 0);
if (nwritten < 0) {
- if ((errno == EAGAIN && !(c->flags & REDIS_BLOCK)) || (errno == EINTR)) {
+ if ((errno == EWOULDBLOCK && !(c->flags & REDIS_BLOCK)) || (errno == EINTR)) {
/* Try again later */
} else {
__redisSetError(c, REDIS_ERR_IO, NULL);