Freak wrote:So there should be no case where you cannot know if the ID is valid.
This does not seem to be true to me.
On the contrary: you almost never know if the connection is still valid.
It is not in the programmers influence (running a server), if or when a client disconnects.
You can only know about disconnects at the moment of polling NetworkServerEvent().
As this can bring up all kinds of events, not just for the one client connection,
I am wanting to close, this polling must take place in a part of the code
that is more general, not in a part handling one specific client request.
That general part can be made to make information about disconnects
available for the client request handling part (probably a thread),
but there is always a possibility that the disconnect takes place
after the last check for a NetworkServerEvent()!
In that case the program does not know, the client disconnected in the mean time,
tries to close the allready closed connection:
-> the program crashes (more or less silently)
-> your server is not running anymore!
My conclusion therefore is:
CloseNetworkConnection() should be safe to be called,
even if the client disconnected.
So should SendNetworkData().
(=program should never crash in such a case.)
I stumbled upon that problem,
running a http server, having the client download a larger file,
and than cancelling the download.
This scenario does not seem to be a big problem with windows,
where SendNetworkData() swallows even larger amounts of data
and returns immediately.
I can then free the buffer memory at once and even call
CloseNetworkConnection().
The Sending of the response with the file data is somehow
handled in the background and so is cancels by the client
or closing the connection at the right time.
It appears instant to the PB application and
it never finds out when the download is finished
or if the client canceled it.
With Linux, I have to call SendNetworkData() once in a while,
to get another chunk of data sent.
This does not like closed connections to much
(maybe it does get along with one attempt).
Here I see a risk of crash, if the clients aborts the download
at the wrong moment!
(If the server wants to close the connection as well)
The idea of a webserver going offline, because a client canceled
a download at the wrong moment, seems somewhat nasty to me.
Have I overlooked anything?