Re: [as-devel] read() on a socket in *BSD

Frederick Bruckman (fb@enteract.com)
Fri, 18 Jun 1999 16:21:32 -0500 (CDT)


On Wed, 16 Jun 1999, Ethan wrote:

> True, it doesn't, but as you say, I do add the null terminator.  How 
> could this affect the transfer?  I don't try to read the null terminator 
> from the pipe.  Also, how could Wharf and Pager step on each other's 
> toes?  They use different sockets and have separate input buffers...

Never mind.

> I'm attaching the new patch.  It's intended to be applied over the old 
> 1.7.111-04-allanon-socket.patch.

I had time to look over the whole thing today. The only problem I see,
is that if you do get errno=EAGAIN on a read() (or EINTR), that means
that you actually read zero bytes, so it's wrong to add -1 to "done".
I haven't thought too hard about exactly the effect that has. I've been
running with the following patch to 1.7.111-04a and it seems to be OK.

--- src/afterstep/module.c.orig	Fri Jun 18 06:45:06 1999
+++ src/afterstep/module.c	Fri Jun 18 07:13:20 1999
@@ -332,7 +332,9 @@
   if (done < len)
     {
       int n = read (Module[channel].fd, ptr + done, len - done);
-      if (n == -1 && errno != EINTR && errno != EAGAIN)
+      if (n == -1 && (errno == EINTR || errno == EAGAIN))
+	return 0;
+      else if (n == -1)
 	{
 	  KillModule (channel, 100);
 	  return -1;
@@ -352,7 +354,9 @@
   if (done < len)
     {
       int n = read (Module[channel].fd, ptr + done, len - done);
-      if (n == -1 && errno != EINTR && errno != EAGAIN)
+      if (n == -1 && (errno == EINTR || errno == EAGAIN))
+	return 0;
+      else if (n == -1)
 	{
 	  KillModule (channel, 100);
 	  return -1;
@@ -383,7 +387,9 @@
   if (done < len)
     {
       int n = read (Module[channel].fd, ptr + done, len - done);
-      if (n == -1 && errno != EINTR && errno != EAGAIN)
+      if (n == -1 && (errno == EINTR || errno == EAGAIN))
+	return 0;
+      else if (n == -1)
 	{
 	  KillModule (channel, 100);
 	  return -1;
@@ -400,7 +406,9 @@
   if (done < len)
     {
       int n = read (Module[channel].fd, ptr + done, len - done);
-      if (n == -1 && errno != EINTR && errno != EAGAIN)
+      if (n == -1 && (errno == EINTR || errno == EAGAIN))
+	return 0;
+      else if (n == -1)
 	{
 	  KillModule (channel, 100);
 	  return -1;