sendfile() not detecting closed connections.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Ian FREISLICH
Date: Friday, November 2, 2007 - 2:45 am

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

_______________________________________________
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
sendfile() not detecting closed connections., Ian FREISLICH, (Fri Nov 2, 2:45 am)
Re: sendfile() not detecting closed connections., Robert Watson, (Fri Nov 2, 8:26 am)
Re: sendfile() not detecting closed connections., Andre Oppermann, (Fri Nov 2, 11:36 am)
RE: sendfile() not detecting closed connections., David Schwartz, (Fri Nov 2, 1:57 pm)
Re: sendfile() not detecting closed connections. , Ian FREISLICH, (Sun Nov 4, 10:00 pm)
Re: sendfile() not detecting closed connections. , Ian FREISLICH, (Sun Nov 4, 10:01 pm)
Re: sendfile() not detecting closed connections., Andre Oppermann, (Mon Nov 5, 1:05 pm)
Re: sendfile() not detecting closed connections. , Ian FREISLICH, (Tue Nov 6, 4:52 am)