[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ns] delay
At 10:36 04/04/00 -0400, you wrote:
>Hi,all:
>
> suppose I have an application ,say Application/Server, it will receive
>all kinds of requests from clients, then it will process every request in
>5ms, to simulate this kind of activity, I can just let server delay 5ms to
>simulate the processing. However, in the real world, the server should be
>multi-threads,it can process many requests at the same time.so how can I
>do?
Process each request as soon as you get it but use the scheduler
to post the reply so that it is sent 5 ms later than the current
simulation time.
psuedo-code:
void Server::recv(Packet *p, Handler *h)
{
// Response packet (you could possibly reuse p here)
Packet *reply = allocpkt();
// Do whatever you need to process the request (p)
// Fill header fields as needed in the response packet,
// (e.g. dst address and so on)
// Schedule it (5ms from now on) and return
Scheduler::instance().schedule(target_, reply, 0.005);
return;
}
Hope this helps.
Regards,
G.
--
Guillermo Rodriguez Garcia
<[email protected]>