Teemu <teemu@easy.com> wrote:
> Hi,
>
> I'm trying to make a file transfer server that transfers files very fast.
> The problem is that for some reason it takes very long for the server to
> notice if the connection to the client is (fysically) down, mean while it
> keeps sending those packages until the tcp stacks send buf fills. Sometimes
> this might tak as long as 15 minutes. I have set the following:
That's standard behaivour for TCP. You will only get a fast notification
of failure if the service (not the host offering the server) is shut
down. You should then get something like a Broken Pipe message.
It seems that you want to be able to meddle with the timeouts, which you
shouldn't really do (they are engineered the way they are for a reason).
15 minutes does seem a bit excessive however.
If you really wanted (and I'm not sure this is the best solution
either), is to make a version of read/write that you impose a timeout
on. I'm not sure is recvmsg or sendmsg can deal with TCP.
The basics of this are the following (see Unix Network Programming, by
Stevens for a more complete rundown)
int timedread( int fd, void *buf, size_t count, unsigned int seconds )
{
int res;
alarm( seconds );
/* set SIGALARM handler to an empty function, its only purpose is to
* interrupt the read */
res = read( int buf, count );
/* reset SIGALARM to whatever it was */
}
Be a bit careful with this though, you really should read Stevens to see
the advice he gives on the matter wrt race conditions.
On second thought, it would be preferable (for me at least, if I were
doing this) to use select instead of signals. This is tidier, and with
less undesired side effects.
> I've also tried to set KEEPALIVE on but it seems linux doesn't send
> keepalives too often.
This is probably because its blocked in a read or write, and therefore
shouldn't be sending a KEEPALIVE.
> ==============================
> problems with windows: reboot,
> problems with unix: be root.
> ==============================
Nice sig, but preface it with a line saying "-- ", so client software
knows its a sig and can remove it.
--
Cameron Kerr
cameron.kerr@paradise.net.nz :
http://nzgeeks.org/cameron/
Empowered by Perl!