03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

whose settings have not yet been properly initialized. This allows the GSDP server to hold<br />

packets for:<br />

� a new game that hasn't been started,<br />

� an existing game that has been closed temporarily and should be reopened.<br />

This applies until the game has been started or reopened.<br />

Queue management<br />

The receive queue is a scarce resource – or, more precisely, the free slots on the receive<br />

queue are a scarce resource. They are preallocated so that a receive operation cannot fail<br />

because of an out-of-memory error. Precisely because they are preallocated there are not<br />

many of them.<br />

Important<br />

The receive queue should manage itself carefully to ensure that<br />

message slots are not allocated and then never freed.<br />

This means that:<br />

� messages that cannot match any existing client should be dropped before they are<br />

added to the queue;<br />

� when a client is terminated, any messages for that client should be deleted from the<br />

queue;<br />

� if a client fails to clear a message after a reasonable period – say, 20 s or more – then<br />

the client is 'not responding' in the sense that users of Windows applications are familiar<br />

with. The server should drop packets for it and should arguably panic the client.<br />

The receive-queue management in the GSDP server follows the specification of GSDP in<br />

Appendix 3 closely. But on reflection, that specification is incomplete and may need to be<br />

improved to support quicker deletion of nonreceived packets. The fact that the current<br />

specification is to keep received packets on the queue, before a game has started that can<br />

accept them is the key item of contention here.<br />

19.3.6 Startup and Shutdown<br />

Earlier, we made the point that connection to a transient server was a delicate affair. We<br />

need to connect reliably in the sense that either we succeed in connecting to the one GSDP<br />

server, or we fail and report it to the client program. We mustn't fail silently, and we mustn't<br />

get into any situation in which there are two GSDP servers. Part of the responsibility for this<br />

lies with the client interface, in RGsdpSession::ConnectL() – the remainder lies with the<br />

server startup code, which we'll now describe.<br />

Additionally, server startup has to set up the server environment that will be used to deliver<br />

the GSDP server's services. That means, at a minimum<br />

� a new thread, with a cleanup stack, active scheduler, and CServer object ready to<br />

receive connection requests from clients via the kernel;<br />

� anything specific that the server needs to do its job – in the case of the GSDP server,<br />

that means the receive queue, GDP adapters, port number allocator, shutdown timer,<br />

and so on.<br />

If the server can't construct all this, then launch is considered to have failed. If it can<br />

construct all this, then it's ready to receive client connect requests. Client connect requests<br />

may fail too – but that's a different matter from server launch.<br />

Server startup is a kind of bootstrap process involving the following general steps:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!