[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Closing idle connections, recovering memory

From: Simon Goldschmidt
Subject: Re: [lwip-users] Closing idle connections, recovering memory
Date: Thu, 22 Apr 2010 12:46:14 +0200

Mike Kleshov wrote:
> I am implementing an embedded http server using the raw API. I have 2
> questions I'm not sure how to answer yet.

There's already a working (raw-API-)httpd in the contrib module in CVS, so 
unless you have specific needs, there's no need to write your own. And even if 
you do, its source is a good example to write your own.

> 1) [..] It
> appears that the only way to do it is to periodically scan all my
> active http connections and clean up as necessary. Am I right?

No: set tcp_arg() to your private structure where you buffer the pbufs. This 
arg is then passed to the err callback function.

> 2) I want to prevent TCP connections from staying idle too long (say,
> 1 minute). If I understand correctly, TCP tolerates much longer
> periods of inactivity (no packets in or out). How do I detect idle
> connections? The raw API provides the poll callback. But how do I know
> if there has been any activity? Would it be sensible to close the
> connection if neither recved() not sent() callback has been called in
> the last 1 minute?

Exactly. Keep an internal idle counter, reset it in recved/sent, increase it in 
the poll function, and close the connection if it gets too high. This is what 
the CVS contrib httpd does, too.

GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

reply via email to

[Prev in Thread] Current Thread [Next in Thread]