Index: apt-cacher-ng-0.1.10/source/acbuf.cc
===================================================================
--- apt-cacher-ng-0.1.10.orig/source/acbuf.cc	2008-03-16 12:36:14.000000000 +0100
+++ apt-cacher-ng-0.1.10/source/acbuf.cc	2008-03-16 14:50:09.000000000 +0100
@@ -68,20 +68,26 @@
 int acbuf::syswrite(int fd, unsigned int maxlen) {
     size_t todo(MYSTD::min(maxlen, size()));
 
-    int n=::write(fd, rptr(), todo);
+		int n;
+		do {
+			n=::write(fd, rptr(), todo);
+		} while(n<0 && errno==EINTR);
     if(n<0 && errno==EAGAIN)
         n=0;
     if(n<0)
-        return n;
+        return -errno;
     drop(n);
     return n;
 }
 
 int acbuf::sysread(int fd) {
-    int n=::read(fd, m_buf+w, m_nCapacity-w);
+	int n;
+	do {
+		n=::read(fd, m_buf+w, m_nCapacity-w);
+	} while(n<0 && errno==EINTR);
     //cerr << "sysread: " << free() <<endl;
-    if(n<0 && errno==EAGAIN)
-        n=0;
+    if(n<0)
+      return -errno;
     if(n>0)
         w+=n;
     return(n);
Index: apt-cacher-ng-0.1.10/source/con.cc
===================================================================
--- apt-cacher-ng-0.1.10.orig/source/con.cc	2008-03-16 14:48:10.000000000 +0100
+++ apt-cacher-ng-0.1.10/source/con.cc	2008-03-16 14:50:09.000000000 +0100
@@ -201,6 +201,9 @@
             int n=inBuf.sysread(m_confd);
             ldbg("got data: " << n <<", inbuf size: "<< inBuf.size());
             if(n<=0) // error, incoming junk overflow or closed connection
+              if(n==-EAGAIN)
+                continue;
+              else
                 return;
         }
 
Index: apt-cacher-ng-0.1.10/source/dlcon.cc
===================================================================
--- apt-cacher-ng-0.1.10.orig/source/dlcon.cc	2008-03-16 14:12:05.000000000 +0100
+++ apt-cacher-ng-0.1.10/source/dlcon.cc	2008-03-16 14:50:09.000000000 +0100
@@ -298,7 +298,10 @@
 	int r = m_InBuf.sysread(m_conFd);
 	ldbg("dlcon::_HandleIncoming()~sysread: " <<r);
 	if (r <= 0)
-		return false;
+    if(r==-EAGAIN)
+      return true;
+    else
+      return false;
 
 	Reswitch:
 	ldbg("switch: " << m_DlState);
@@ -892,7 +895,9 @@
 			//int s=sendto(m_conFd, m_sSendBuf.data(), m_sSendBuf.length(), 0, NULL, 0);
 			int s=write(m_conFd, m_sSendBuf.data(), m_sSendBuf.length());
 			//cerr << " Sent bytes: " << s <<endl;
-			if (s<0&& errno!=EAGAIN)HANDLEERROR("500 Peer communication, code 101");
+      if(s<0 && (errno==EAGAIN || errno==EINTR))
+        s=0;
+      else if (s<0&& errno!=EAGAIN)HANDLEERROR("500 Peer communication, code 101");
 			m_sSendBuf.erase(0, s);
 		}
 
Index: apt-cacher-ng-0.1.10/source/header.cc
===================================================================
--- apt-cacher-ng-0.1.10.orig/source/header.cc	2008-03-16 14:13:30.000000000 +0100
+++ apt-cacher-ng-0.1.10/source/header.cc	2008-03-16 14:50:10.000000000 +0100
@@ -213,6 +213,8 @@
 		{
 			if(EAGAIN == errno)
 				continue;
+			if(EINTR == errno)
+				continue;
 			
 			tmp=errno;
 			close(fd);
Index: apt-cacher-ng-0.1.10/source/job.cc
===================================================================
--- apt-cacher-ng-0.1.10.orig/source/job.cc	2008-03-16 14:44:43.000000000 +0100
+++ apt-cacher-ng-0.1.10/source/job.cc	2008-03-16 14:50:09.000000000 +0100
@@ -38,7 +38,10 @@
 	{
 		int readcount=read(in_fd, buf, count>sizeof(buf)?sizeof(buf):count);
 		if(readcount<=0)
-			return readcount;
+			if(errno==EINTR || errno==EAGAIN)
+				continue;
+			else
+				return readcount;
 		
 		*offset+=readcount;
 		cnt+=readcount;
@@ -50,7 +53,10 @@
 			int r=write(out_fd, buf+nPos, readcount-nPos);
 			if(r==0) continue; // not nice but needs to deliver it
 			if(r<0)
-				return r;
+				if(errno==EAGAIN || errno==EINTR)
+					continue;
+				else
+					return r;
 			nPos+=r;
 		}
 	}
Index: apt-cacher-ng-0.1.10/source/pkgimport.cc
===================================================================
--- apt-cacher-ng-0.1.10.orig/source/pkgimport.cc	2008-03-16 14:41:21.000000000 +0100
+++ apt-cacher-ng-0.1.10/source/pkgimport.cc	2008-03-16 14:51:51.000000000 +0100
@@ -209,8 +209,15 @@
 			return false;
 		
 		while(true) {
-			if(buf.sysread(in)<=0)
-				break;
+      int err;
+      err=buf.sysread(in);
+			if(err<0)
+        if(err==-EAGAIN)
+          continue;
+        else
+          goto error_copying;
+      else if(err==0)
+        break;
 			// don't open unless the input is readable, for sure
 			if(out<0)
 			{
@@ -218,8 +225,12 @@
 				if(out<0)
 					goto error_copying;
 			}
-			if(buf.syswrite(out)<=0)
-				goto error_copying;
+      err=buf.syswrite(out);
+			if(err<=0)
+        if(err==-EAGAIN)
+          continue;
+        else
+          goto error_copying;
 		}
 		close(in);
 		close(out);
