On Wed, Mar 17, 2010 at 01:16:24PM +0100, Sumit Bose wrote:
> Hi,
> 
> this patch fixes some issues in the client communication code of the
> responders.
> 
> The man pages of send() and recv() tell to following:
> 
> EAGAIN or EWOULDBLOCK
> The socket is marked non-blocking and the requested operation would
> block. POSIX.1-2001 allows either error to be returned for this case,
> and does not require these constants to have the same value, so a
> portable application should check for both possibilities.
> 
> So I added a check for EWOULDBLOCK after the calls to send() and recv()
> and return EAGAIN to the caller.
> 
> The other issues are mentioned in the commit message.
> 
> bye,
> Sumit

This new version ofthe patch adds EINTR to the list of errors where we
return EAGAIN to the caller.

bye,
Sumit
From 5fafd9ae421f2413e68cb0b118a84c5f783b56c1 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sb...@redhat.com>
Date: Wed, 17 Mar 2010 12:52:54 +0100
Subject: [PATCH] Fixes for client communication

- catch all errors of send() and recv(), not only EAGAIN
- check if send() or recv() return EWOULDBLOCK or EINTR
- remove unused parameter from client_send() and client_recv()
- fix a debugging message
---
 src/responder/common/responder_common.c |   10 +++++-----
 src/responder/common/responder_packet.c |   16 ++++++++++++----
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/responder/common/responder_common.c 
b/src/responder/common/responder_common.c
index f524afb..48ec4bd 100644
--- a/src/responder/common/responder_common.c
+++ b/src/responder/common/responder_common.c
@@ -61,7 +61,7 @@ static int client_destructor(struct cli_ctx *ctx)
     return 0;
 }
 
-static void client_send(struct tevent_context *ev, struct cli_ctx *cctx)
+static void client_send(struct cli_ctx *cctx)
 {
     int ret;
 
@@ -71,7 +71,7 @@ static void client_send(struct tevent_context *ev, struct 
cli_ctx *cctx)
         return;
     }
     if (ret != EOK) {
-        DEBUG(0, ("Failed to read request, aborting client!\n"));
+        DEBUG(0, ("Failed to send data, aborting client!\n"));
         talloc_free(cctx);
         return;
     }
@@ -84,7 +84,7 @@ static void client_send(struct tevent_context *ev, struct 
cli_ctx *cctx)
     return;
 }
 
-static void client_recv(struct tevent_context *ev, struct cli_ctx *cctx)
+static void client_recv(struct cli_ctx *cctx)
 {
     int ret;
 
@@ -151,11 +151,11 @@ static void client_fd_handler(struct tevent_context *ev,
     struct cli_ctx *cctx = talloc_get_type(ptr, struct cli_ctx);
 
     if (flags & TEVENT_FD_READ) {
-        client_recv(ev, cctx);
+        client_recv(cctx);
         return;
     }
     if (flags & TEVENT_FD_WRITE) {
-        client_send(ev, cctx);
+        client_send(cctx);
         return;
     }
 }
diff --git a/src/responder/common/responder_packet.c 
b/src/responder/common/responder_packet.c
index 6e581a3..d308ecd 100644
--- a/src/responder/common/responder_packet.c
+++ b/src/responder/common/responder_packet.c
@@ -183,8 +183,12 @@ int sss_packet_recv(struct sss_packet *packet, int fd)
     errno = 0;
     rb = recv(fd, buf, len, 0);
 
-    if (rb == -1 && errno == EAGAIN) {
-        return EAGAIN;
+    if (rb == -1) {
+        if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
+            return EAGAIN;
+        } else {
+            return errno;
+        }
     }
 
     if (rb == 0) {
@@ -219,8 +223,12 @@ int sss_packet_send(struct sss_packet *packet, int fd)
     errno = 0;
     rb = send(fd, buf, len, 0);
 
-    if (rb == -1 && errno == EAGAIN) {
-        return EAGAIN;
+    if (rb == -1) {
+        if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
+            return EAGAIN;
+        } else {
+            return errno;
+        }
     }
 
     if (rb == 0) {
-- 
1.6.6.1

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to