From owner-freebsd-current@FreeBSD.ORG Fri Nov 2 09:46:48 2007 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 971BA16A418 for ; Fri, 2 Nov 2007 09:46:48 +0000 (UTC) (envelope-from ianf@clue.co.za) Received: from munchkin.clue.co.za (munchkin.clue.co.za [66.219.59.160]) by mx1.freebsd.org (Postfix) with ESMTP id 64F8313C48A for ; Fri, 2 Nov 2007 09:46:48 +0000 (UTC) (envelope-from ianf@clue.co.za) DomainKey-Signature: a=rsa-sha1; q=dns; c=simple; s=20070313; d=clue.co.za; h=Received:Received:Received:To:Subject:From:X-Attribution:Date:Message-Id; b=Ecf1SjzXOImgFxIEIFnvDMWn7/EhoAsolZK4XbaXxxGdIQVcLgLcNaGJOCq1/bjKWdmgaBoFKp9qU7925rBXov948PbhoJCsP9so+ZLZIaCngyU0euW3zmYyDXWJ1Gfi2fqhBMJTzZ22JTod7xQdyvkLBwHt03Np3cWhqDWUNOz2w1B43QfxHqO8cfXjZ2uUSJtoLAC9OlQ+6Ki5XIUs/JmTET9dAAXuicUrw1vig/Gd2VbR/L9XkrOwYNdNrfk6; Received: from uucp by munchkin.clue.co.za with local-rmail (Exim 4.67) (envelope-from ) id 1Int6Q-0007Zb-N0 for current@freebsd.org; Fri, 02 Nov 2007 09:46:10 +0000 Received: from ianf.clue.co.za ([10.0.0.6] helo=clue.co.za) by urchin.clue.co.za with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.66) (envelope-from ) id 1Int6C-000558-01 for current@freebsd.org; Fri, 02 Nov 2007 09:45:56 +0000 Received: from localhost ([127.0.0.1] helo=clue.co.za) by clue.co.za with esmtp (Exim 4.68 (FreeBSD)) (envelope-from ) id 1Int69-0000bA-NO for current@freebsd.org; Fri, 02 Nov 2007 11:45:53 +0200 To: current@freebsd.org From: Ian FREISLICH X-Attribution: BOFH Date: Fri, 02 Nov 2007 11:45:53 +0200 Message-Id: Cc: Subject: sendfile() not detecting closed connections. X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Nov 2007 09:46:48 -0000 Hi System is 8.0-CURRENT. I have the following piece of code: rename(path, data); stat(data, &sb); len = snprintf(buffer, MAXBUFLEN, "BYTES %lld\r\n", sb.st_size); write(connection, buffer, len); sleep(10); if ((sendfile(fd, connection, 0, sb.st_size, NULL, &sbytes, 0)) == -1 || sbytes != sb.st_size) { syslog(facility, "Problem writing data: %s, wrote %lld", strerror(errno), sbytes); respool(fd, path); unlink(data) close(fd); return(-1); } else syslog(facility, "Download successful %ld", sbytes); close(fd); unlink(data); If, during the sleep, I terminate the connection so that netstat reports: tcp4 0 0 127.0.0.1.666 127.0.0.1.58239 CLOSE_WAIT tcp4 0 0 127.0.0.1.58239 127.0.0.1.666 FIN_WAIT_2 sendfile() reports success for files less than about 64k in size, but I haven't been able to figure out where the threshold is. It erroneously reports that 41000 of the 64k were sent, but will say the whole file was transferred up to about 64k. The connection filedescriptor is blocking. Any ideas? Ian -- Ian Freislich