--- nginx-0.5.17.orig/src/os/unix/ngx_linux_sendfile_chain.c	2006-09-07 21:56:45.000000000 +0300
+++ nginx-0.5.17/src/os/unix/ngx_linux_sendfile_chain.c	2007-04-11 23:02:50.000000000 +0300
@@ -254,7 +254,18 @@
 #else
             offset = (int32_t) file->file_pos;
 #endif
-            rc = sendfile(c->fd, file->file->fd, &offset, file_size);
+	    char sbuff[8];
+           unsigned int res=8;
+	    int ret=0;
+	    size_t sentbytes=0;
+	    memset(sbuff,'\0',res);
+	    if(!(ret=getsockopt(c->fd,SOL_SOCKET,SO_SNDBUF,(void *)&sbuff,(unsigned int *)&res))){
+                res=*((int *)(&(sbuff[0])));
+                sentbytes=(file_size>res)?res:file_size;
+            }
+
+            rc = sendfile(c->fd, file->file->fd, &offset, sentbytes);
+	    //rc = sendfile(c->fd, file->file->fd, &offset, file_size);
 
             if (rc == -1) {
                 err = ngx_errno;
