Re: Userspace module return value?
Ingo Molnar <[email protected]> Tue, 20 Jul 2004 16:00:21 +0200
| Newsgroups | gmane.network.tux |
|---|---|
| Message-ID | <[email protected]> |
* Marek Habersack <[email protected]> wrote: > if (rval == REQ_STATIC) { > req->event = 1; > do_syslog("Static request, getting the object (%s)", req->objectname); > rval = tux(TUX_ACTION_GET_OBJECT, req); > if (rval < 0 || req->error) { > req->event = 2; > if (content_type(req) == CONTENT_NOTIFY) > return send_failure(req, LOG_ERR_OBJECT_NOT_FOUND); > > goto abort; > } > return rval; > } This code doesnt handle events properly. When tux() returns there might be another request active (with a different ->priv value) - you need to return so that your event loop can be re-called with the proper request pointer. the req->event code can be used to distinguish between the various phases a particular request is in. (you can also track your request's state via the ->priv pointer) demo2.c shows a 3-phase request. (for simplicity the demo code uses write() but a truly atomic module should use TUX_ACTION_SEND_BUFFER to write to the socket. A write(), if the send buffers are set to be small on your system, might block your thread and hence all requests might be blocked by the remote client.) it all looks a bit complex but that is how event-based programming is ... Ingo