On Thu, 2007-07-05 at 08:38 +0200, Rhythmic Fistman wrote:
> We can do something like this, in felix pseudocode:
> 
> proc lingering_close(s: socket) {
>    var open = true;
> 
>    proc close {
>       if(open) then {
>           socket_close(s);
>          open = false;
>       } else {};
>    };
> 
> 
>   // timeout
>   spawn_fthread {
>       sleep(2);
>       close;
>       exit;  // exit fthread
>    };
> 
>   do{
>       // read data from s
>    } while{ open and not eof) } ;
>    close;
> };
> 
> simple boolean open flag suffices because the fthreads
> are run synchronously.

Yes, but the code already does just this: it puts a delay
before the close. Spawning an fthread to do that doesn't help,
since the connection is managed by an fthread already, and
doesn't prevent servicing a new one.

The problem is that this technique leaves the socket
resource allocated for n>=2 seconds. Don't forget,
the close fthread is competing with the reader for scheduling.
Which one goes on the fthread scheduler depends on the OS
pthread scheduler choosing between our timer thread and the
demux thread .. so the delay could be longer than 2 seconds.

We really need the OS to release the socket ASAP, and the only
way to do that is to close it ASAP, but that kills the
transmission.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to