Second part of fix for bug #8679 - recvfile code path using splice() on Linux leaves...
authorJeremy Allison <jra@samba.org>
Sat, 31 Dec 2011 04:23:00 +0000 (20:23 -0800)
committerJeremy Allison <jra@samba.org>
Sat, 31 Dec 2011 04:23:00 +0000 (20:23 -0800)
Split out the functionality of drain_socket() into a separate
function from default_sys_recvfile().

source3/lib/recvfile.c

index 5d1c0b2c55f85d6b84ec9a24ae60ebecd3c5bab1..31d9311498d2399df4318b3bdf56734c4a4b11d5 100644 (file)
@@ -242,9 +242,38 @@ ssize_t sys_recvfile(int fromfd,
 
 /*****************************************************************
  Throw away "count" bytes from the client socket.
+ Returns count or -1 on error.
 *****************************************************************/
 
 ssize_t drain_socket(int sockfd, size_t count)
 {
-       return default_sys_recvfile(sockfd, -1, (SMB_OFF_T)-1, count);
+       size_t total = 0;
+       size_t bufsize = MIN(TRANSFER_BUF_SIZE,count);
+       char *buffer = NULL;
+
+       if (count == 0) {
+               return 0;
+       }
+
+       buffer = SMB_MALLOC_ARRAY(char, bufsize);
+       if (buffer == NULL) {
+               return -1;
+       }
+
+       while (total < count) {
+               ssize_t read_ret;
+               size_t toread = MIN(bufsize,count - total);
+
+               /* Read from socket - ignore EINTR. */
+               read_ret = sys_read(sockfd, buffer, toread);
+               if (read_ret <= 0) {
+                       /* EOF or socket error. */
+                       free(buffer);
+                       return -1;
+               }
+               total += read_ret;
+       }
+
+       free(buffer);
+       return count;
 }