#include "nsd.h"Data Structures | |
| struct | TaskQueue |
| struct | Task |
Defines | |
| #define | NAME_SIZE 31 |
| #define | TASK_INIT 0x01 |
| #define | TASK_CANCEL 0x02 |
| #define | TASK_WAIT 0x04 |
| #define | TASK_TIMEOUT 0x08 |
| #define | TASK_DONE 0x10 |
| #define | TASK_PENDING 0x20 |
| #define | Call(tp, w) ((*((tp)->proc))((Ns_Task *)(tp),(tp)->sock,(tp)->arg,(w))) |
Functions | |
| Ns_TaskQueue * | Ns_CreateTaskQueue (char *name) |
| void | Ns_DestroyTaskQueue (Ns_TaskQueue *queue) |
| Ns_Task * | Ns_TaskCreate (SOCKET sock, Ns_TaskProc *proc, void *arg) |
| int | Ns_TaskEnqueue (Ns_Task *task, Ns_TaskQueue *queue) |
| void | Ns_TaskRun (Ns_Task *task) |
| int | Ns_TaskCancel (Ns_Task *task) |
| int | Ns_TaskWait (Ns_Task *task, Ns_Time *timeoutPtr) |
| void | Ns_TaskCallback (Ns_Task *task, int when, Ns_Time *timeoutPtr) |
| void | Ns_TaskDone (Ns_Task *event) |
| SOCKET | Ns_TaskFree (Ns_Task *task) |
| void | NsStartQueueShutdown (void) |
| void | NsWaitQueueShutdown (Ns_Time *toPtr) |
| #define Call | ( | tp, | |||
| w | ) | ((*((tp)->proc))((Ns_Task *)(tp),(tp)->sock,(tp)->arg,(w))) |
| #define NAME_SIZE 31 |
The following defines a task queue.
| #define TASK_CANCEL 0x02 |
| #define TASK_DONE 0x10 |
| #define TASK_INIT 0x01 |
The following bits are used to send signals to a task queue and manage the state tasks.
| #define TASK_PENDING 0x20 |
| #define TASK_TIMEOUT 0x08 |
| #define TASK_WAIT 0x04 |
| Ns_TaskQueue* Ns_CreateTaskQueue | ( | char * | name | ) |
----------------------------------------------------------------------
Ns_CreateTaskQueue --
Create a new task queue.
Results: Handle to task queue..
Side effects: None.
----------------------------------------------------------------------
| void Ns_DestroyTaskQueue | ( | Ns_TaskQueue * | queue | ) |
----------------------------------------------------------------------
Ns_DestoryTaskQueue --
Stop and join a task queue.
Results: None.
Side effects: Pending tasks callbacks, if any, are cancelled.
----------------------------------------------------------------------
Remove queue from list of all queues.
Signal stop and wait for join.
| void Ns_TaskCallback | ( | Ns_Task * | task, | |
| int | when, | |||
| Ns_Time * | timeoutPtr | |||
| ) |
----------------------------------------------------------------------
Ns_TaskCallback --
Update pending conditions and timeout for a task. This routine is expected to be called from within the task callback proc including to set the initial wait conditions from within the NS_SOCK_INIT callback.
Results: None.
Side effects: Task callback will be invoked when ready or on timeout.
----------------------------------------------------------------------
Map from AOLserver when bits to poll event bits.
Copy timeout, if any.
Mark as waiting if there are events or a timeout.
| int Ns_TaskCancel | ( | Ns_Task * | task | ) |
----------------------------------------------------------------------
Ns_TaskCancel --
Signal a task queue to stop running a task.
Results: NS_OK if cancel sent, NS_ERROR otherwise.
Side effects: Task callback will be invoke with NS_SOCK_CANCEL and is expected to call Ns_TaskDone to indicate completion.
----------------------------------------------------------------------
| Ns_Task* Ns_TaskCreate | ( | SOCKET | sock, | |
| Ns_TaskProc * | proc, | |||
| void * | arg | |||
| ) |
----------------------------------------------------------------------
Ns_TaskCreate --
Create a new task.
Results: Handle to task.
Side effects: None
----------------------------------------------------------------------
| void Ns_TaskDone | ( | Ns_Task * | event | ) |
----------------------------------------------------------------------
Ns_TaskDone --
Mark a task as done. This routine should be called from within the task callback. The task queue thread will signal other waiting threads, if any, on next spin.
Results: None.
Side effects: Task queue will signal this task is done on next spin.
----------------------------------------------------------------------
| int Ns_TaskEnqueue | ( | Ns_Task * | task, | |
| Ns_TaskQueue * | queue | |||
| ) |
----------------------------------------------------------------------
Ns_TaskEnqueue --
Add a task to a queue.
Results: NS_OK if task sent, NS_ERROR otherwise.
Side effects: Queue will begin running the task.
----------------------------------------------------------------------
| SOCKET Ns_TaskFree | ( | Ns_Task * | task | ) |
----------------------------------------------------------------------
Ns_TaskFree --
Free task structure. The caller is responsible for ensuring the task is no longer being run or monitored a task queue.
Results: The task SOCKET which the caller is responsible for closing or reusing.
Side effects: None.
----------------------------------------------------------------------
| void Ns_TaskRun | ( | Ns_Task * | task | ) |
----------------------------------------------------------------------
Ns_TaskRun --
Run a task directly, waiting for completion.
Results: None.
Side effects: Depends on task callback.
----------------------------------------------------------------------
| int Ns_TaskWait | ( | Ns_Task * | task, | |
| Ns_Time * | timeoutPtr | |||
| ) |
----------------------------------------------------------------------
Ns_TaskWait --
Wait for a task to complete. Infinite wait is indicated by a NULL timeoutPtr.
Results: NS_TIMEOUT if task did not complete by absolute time, NS_OK otherwise.
Side effects: May wait up to specified timeout.
----------------------------------------------------------------------
| void NsStartQueueShutdown | ( | void | ) |
----------------------------------------------------------------------
NsStartQueueShutdown --
Trigger all task queues to begin shutdown.
Results: None.
Side effects: None.
----------------------------------------------------------------------
Trigger all queues to shutdown.
| void NsWaitQueueShutdown | ( | Ns_Time * | toPtr | ) |
----------------------------------------------------------------------
NsWaitQueueShutdown --
Wait for all task queues to shutdown.
Results: None.
Side effects: May timeout waiting for shutdown.
----------------------------------------------------------------------
Clear out list of any remaining task queues.
Join all queues possible within total allowed time.
| int event |
AOLserver when bit.
| int when |
1.5.1