dispatch revision 9c3531d72aeaad6c5f01efe6a1c82023e1379e4d
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian WellingtonCopyright (C) 2000 Internet Software Consortium.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark AndrewsSee COPYRIGHT in the source root or http://www.isc.org/copyright for terms.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews$Id: dispatch,v 1.3 2000/06/22 21:53:51 tale Exp $
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark AndrewsUDP receive:
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington/*
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington * General flow:
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington *
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington * If I/O result == CANCELED, free the buffer and notify everyone as
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * the various queues drain.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews *
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * If I/O is error (not canceled and not success) log it, free the buffer,
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * and restart.
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews *
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * If query:
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * if no listeners: free the buffer, restart.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * if listener: allocate event, fill in details.
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * If cannot allocate, free buffer, restart.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * if rq event queue is not empty, queue. else, send.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * restart.
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson *
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson * If response:
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * Allocate event, fill in details.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * If cannot allocate, free buffer, restart.
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson * find target. If not found, free buffer, restart.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * if event queue is not empty, queue. else, send.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington * restart.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews */
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark AndrewsUDP restart:
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews/*
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * If too many recv()'s are already running, just return.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews *
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * If noone is attached to us, just return.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews *
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * Allocate a new buffer to receive into.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * If no more buffers:
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * If there are buffers handed out: wait for one to come back.
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson * If there are no buffers handed out:
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * If there are responses attached to us, just return.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * If there are queries only, send one an error event.
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson *
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews *
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * start recv() on socket. If this fails:
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson * Free buffer.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * Set dispatch state to "shutting down" and why to "socket error"
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington * Start failsafe shutdown.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews */
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark AndrewsAdding a response:
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews
09ab886382ad9e7149d9b72b4cf9a03ae4a1cddfDavid Lawrence/*
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * If shutting down, return error.
d4ef65050feac78554addf6e16a06c6e2e0bd331Brian Wellington *
09ab886382ad9e7149d9b72b4cf9a03ae4a1cddfDavid Lawrence * Allocate an unique messageid and return it. If none can be allocated,
09ab886382ad9e7149d9b72b4cf9a03ae4a1cddfDavid Lawrence * return that.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews *
d4ef65050feac78554addf6e16a06c6e2e0bd331Brian Wellington * Allocate a new structure and fill it in. If no memory, return that.
09ab886382ad9e7149d9b72b4cf9a03ae4a1cddfDavid Lawrence *
09ab886382ad9e7149d9b72b4cf9a03ae4a1cddfDavid Lawrence * Insert into the correct linked list.
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews *
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * If the receiver is not running, try to start it.
09ab886382ad9e7149d9b72b4cf9a03ae4a1cddfDavid Lawrence */
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian WellingtonAdding a request:
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson/*
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson * If shutting down, return error.
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson *
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson * Allocate new structure and fill it in. If no memory, return that.
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson *
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson * Insert it into the linked list.
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson *
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson * If the incoming query packet queue is not empty, pull an item off and
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson * send that event to this task.
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson *
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson * If the receiver is not running, try to start it.
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson */
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian WellingtonDetaching a response:
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews/*
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * decrement dispatch reference count by one. If zero, remember to kill it
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * later.
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews *
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * unlink the response from the hashed list.
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews *
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington * Free any buffers and events attached to the response structure.
17453368fa0136f6287c56d6600bee58809334bcAndreas Gustafsson *
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * Free the response structure.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews *
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * If an event is also being returned, jump to "internal event free" below.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews *
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * If the ref count became zero above, destroy this dispatch fully, and return.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington *
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * If the receiver is not running, try to start it.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington */
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian WellingtonDetaching a request:
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington/*
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * decrement dispatch ref count by one. If zero, remember to kill it later.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington *
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * unlink from the request list.
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews *
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington * Free the response structure.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington *
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington * If an event is also being returned, jump to "internal event free" below.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington *
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington * If the ref count became zero above, destroy the dispatch fully, and return.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington *
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * If the receiver is not running, try to start it.
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews */
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark AndrewsInternal event free (from library space):
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington/*
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington * If it is the failsafe event, send it to the next response/request on the
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington * dispatcher, and return.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington *
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * Free buffer.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington *
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington * Free event.
622df0afb82c1b711b5f3c272db4c4b83d09bc4aBob Halley */
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews
622df0afb82c1b711b5f3c272db4c4b83d09bc4aBob HalleyReturning an event (from application space):
622df0afb82c1b711b5f3c272db4c4b83d09bc4aBob Halley
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington/*
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * If it is the failsafe event, die.
622df0afb82c1b711b5f3c272db4c4b83d09bc4aBob Halley *
622df0afb82c1b711b5f3c272db4c4b83d09bc4aBob Halley * Free associated buffer.
622df0afb82c1b711b5f3c272db4c4b83d09bc4aBob Halley *
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews * Free event.
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews *
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * If response: do next response on this response's queue, if any.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington * If request: do next request on this dispatcher's queue, if any.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington *
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington * If the receiver is not running, try to start it.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington */
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington
5bf504f5534eab29c9e52f6e8b75c73b3901743fMark Andrews