#include "nsd.h"Data Structures | |
| struct | PollData |
| struct | ServerMap |
| struct | QueWait |
Defines | |
| #define | DRIVER_STARTED 1 |
| #define | DRIVER_STOPPED 2 |
| #define | DRIVER_SHUTDOWN 4 |
| #define | DRIVER_FAILED 8 |
| #define | DRIVER_QUERY 16 |
| #define | DRIVER_DEBUG 32 |
| #define | PollIn(ppd, i) ((ppd)->pfds[(i)].revents & POLLIN) |
| #define | SockPush(s, sp) ((s)->nextPtr = *(sp), *(sp) = (s)) |
Enumerations | |
| enum | { SOCK_READWAIT, SOCK_PREQUE, SOCK_QUEWAIT, SOCK_RUNWAIT, SOCK_RUNNING, SOCK_CLOSEWAIT, SOCK_DROPPED, SOCK_TIMEOUT, SOCK_OVERFLOW, SOCK_ERROR } |
| enum | ReadErr { E_NOERROR = 0, E_CLOSE, E_RECV, E_FDAGAIN, E_FDWRITE, E_FDTRUNC, E_FDSEEK, E_NOHOST, E_NOSERV, E_HINVAL, E_RINVAL, E_NINVAL, E_LRANGE, E_RRANGE, E_CRANGE } |
Functions | |
| void | NsInitDrivers (void) |
| int | Ns_DriverInit (char *server, char *module, Ns_DriverInitData *init) |
| void * | Ns_RegisterDriver (char *server, char *label, void *procs, void *drvData) |
| void * | Ns_GetDriverContext (Ns_Driver drv) |
| void | Ns_QueueWait (Ns_Conn *conn, SOCKET sock, Ns_QueueWaitProc *proc, void *arg, int when, Ns_Time *timePtr) |
| int | NsStartDrivers (void) |
| void | NsStopDrivers (void) |
| void | NsWaitDriversShutdown (Ns_Time *toPtr) |
| int | NsTclDriverObjCmd (ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj **objv) |
| int | NsConnSend (Ns_Conn *conn, struct iovec *bufs, int nbufs) |
| void | NsSockClose (Sock *sockPtr, int keep) |
| void | NsFreeConn (Conn *connPtr) |
| char * | NsConnContent (Ns_Conn *conn, char **nextPtr, int *availPtr) |
| void | NsConnSeek (Ns_Conn *conn, int count) |
Variables | |
| char * | states [] |
| #define DRIVER_DEBUG 32 |
| #define DRIVER_FAILED 8 |
| #define DRIVER_QUERY 16 |
| #define DRIVER_SHUTDOWN 4 |
| #define DRIVER_STARTED 1 |
The following are valid driver state flags.
| #define DRIVER_STOPPED 2 |
| #define PollIn | ( | ppd, | |||
| i | ) | ((ppd)->pfds[(i)].revents & POLLIN) |
| #define SockPush | ( | s, | |||
| sp | ) | ((s)->nextPtr = *(sp), *(sp) = (s)) |
| anonymous enum |
The following are valid Sock states.
| SOCK_READWAIT | |
| SOCK_PREQUE | Waiting for request or content from client. |
| SOCK_QUEWAIT | Ready to invoke pre-queue filters. |
| SOCK_RUNWAIT | Running pre-queue filters and event callbacks. |
| SOCK_RUNNING | Ready to run when allowed by connection limits. |
| SOCK_CLOSEWAIT | Running in a connection queue. |
| SOCK_DROPPED | Graceful close wait draining remaining bytes . |
| SOCK_TIMEOUT | Client dropped connection. |
| SOCK_OVERFLOW | Request timeout waiting to be queued. |
| SOCK_ERROR | Sock read error or invalid request. |
| enum ReadErr |
| int Ns_DriverInit | ( | char * | server, | |
| char * | module, | |||
| Ns_DriverInitData * | init | |||
| ) |
----------------------------------------------------------------------
Ns_DriverInit --
Initialize a driver.
Results: NS_OK if initialized, NS_ERROR if config or other error.
Side effects: Listen socket will be opened later in NsStartDrivers.
----------------------------------------------------------------------
Determine the hostname used for the local address to bind to and/or the HTTP location string.
If the listen address was not specified, attempt to determine it through a DNS lookup of the specified hostname or the server's primary hostname.
If the lookup suceeded but the resulting hostname does not appear to be fully qualified, attempt a reverse lookup on the address which often returns the fully qualified name.
NB: This is a common but sloppy configuration for a Unix network.
If the lookup suceeded, use the first address in host entry list.
Finally, if no hostname was specified, set it to the hostname derived from the lookup(s) above.
If the hostname was not specified and not determined by the lookup above, set it to the specified or derived IP address string.
Set the protocol and port defaults.
Allocate a new driver instance and set configurable parameters.
~16k
Use OS default.
Use OS default.
30 seconds.
Use previous socktimeout option.
Use previous socktimeout option.
5 pending connections.
100 total open sockets.
4k per-line limit.
32k total header limit.
1m in-memory limit including request & headers.
2 second wait for graceful client close.
NB: 0 for no graceful close.
30 seconds wait for more data in keep-alive.
NB: 0 for no keepalive.
Max of 10 threads for non-event driven I/O.
Minimum of 1 reader thread.
Pre-allocate Sock structures.
Determine the port and then set the HTTP location string either as specified in the config file or constructed from the hostname and port.
Map Host headers for drivers not bound to servers.
| void* Ns_GetDriverContext | ( | Ns_Driver | drv | ) |
----------------------------------------------------------------------
Ns_GetDriverContext --
Return the driver's context (no longer supported)
Results: NULL.
Side effects: None
----------------------------------------------------------------------
| void Ns_QueueWait | ( | Ns_Conn * | conn, | |
| SOCKET | sock, | |||
| Ns_QueueWaitProc * | proc, | |||
| void * | arg, | |||
| int | when, | |||
| Ns_Time * | timePtr | |||
| ) |
----------------------------------------------------------------------
Ns_QueueWait --
Arrange for connection to wait for requested I/O on given socket.
Results: None.
Side effects: Proc will be called with given arg and sock as arguements when the requested I/O condition is met or the given timeout has expired. The connection will not be queued until all such callbacks are processed.
----------------------------------------------------------------------
| void* Ns_RegisterDriver | ( | char * | server, | |
| char * | label, | |||
| void * | procs, | |||
| void * | drvData | |||
| ) |
----------------------------------------------------------------------
Ns_RegisterDriver --
Register a set of communications driver procs (no longer supported).
Results: NULL.
Side effects: None.
----------------------------------------------------------------------
| char* NsConnContent | ( | Ns_Conn * | conn, | |
| char ** | nextPtr, | |||
| int * | availPtr | |||
| ) |
----------------------------------------------------------------------
NsConnContent --
Return the connction content buffer, mapping the temp file if necessary.
NB: It may make better sense to update the various content reading/parsing code to handle true incremental reads from an open file instead of risking a potential mapping failure. The current approach keeps the code simple and flexible.
Results: Pointer to start of content or NULL if mapping failed.
Side effects: If nextPtr and/or availPtr are not NULL, they are updated with the next byte to read and remaining content available.
----------------------------------------------------------------------
| void NsConnSeek | ( | Ns_Conn * | conn, | |
| int | count | |||
| ) |
----------------------------------------------------------------------
NsConnSeek --
Update the next read and available content counter.
Results: None.
Side effects: None.
----------------------------------------------------------------------
| int NsConnSend | ( | Ns_Conn * | conn, | |
| struct iovec * | bufs, | |||
| int | nbufs | |||
| ) |
----------------------------------------------------------------------
NsConnSend --
Send buffers via the connection's driver callback.
Results: # of bytes sent or -1 on error.
Side effects: Depends on driver proc.
----------------------------------------------------------------------
| void NsFreeConn | ( | Conn * | connPtr | ) |
----------------------------------------------------------------------
NsFreeConn --
Return a Conn structure to the free list after processing.
Results: None.
Side effects: Will close Sock structure if still open.
----------------------------------------------------------------------
Return the Conn to the driver.
| void NsInitDrivers | ( | void | ) |
----------------------------------------------------------------------
NsInitDrivers --
Init communication drivers data structures.
Results: None.
Side effects: None.
----------------------------------------------------------------------
| void NsSockClose | ( | Sock * | sockPtr, | |
| int | keep | |||
| ) |
----------------------------------------------------------------------
NsSockClose --
Return a Sock to its DriverThread for closing or keepalive. Note the connection may continue to run after releasing the Sock (traces, etc.).
Results: None.
Side effects: Socket may be reused by a keepalive connection.
----------------------------------------------------------------------
If keepalive is requested and enabled, set the read wait state. Otherwise, set close wait which simply drains any remaining bytes to read.
| int NsStartDrivers | ( | void | ) |
----------------------------------------------------------------------
NsStartDrivers --
Start all driver threads.
Results: NS_OK if all drivers started, NS_ERROR otherwise.
Side effects: See DriverThread.
----------------------------------------------------------------------
Signal and wait for each driver to start.
| void NsStopDrivers | ( | void | ) |
----------------------------------------------------------------------
NsStopDrivers --
Trigger driver threads to begin shutdown.
Results: None.
Side effects: Driver threads will close listen sockets and exit after all outstanding connections are complete and closed.
----------------------------------------------------------------------
| int NsTclDriverObjCmd | ( | ClientData | dummy, | |
| Tcl_Interp * | interp, | |||
| int | objc, | |||
| Tcl_Obj ** | objv | |||
| ) |
----------------------------------------------------------------------
NsTclDriverObjCmd --
Implements ns_driver command.
Results: Standard Tcl result..
Side effects: None.
----------------------------------------------------------------------
| void NsWaitDriversShutdown | ( | Ns_Time * | toPtr | ) |
----------------------------------------------------------------------
NsWaitDriversShutdown --
Wait for exit of all driver threads.
Results: None.
Side effects: Driver threads are joined.
----------------------------------------------------------------------
| char* states[] |
Initial value:
{
"readwait",
"preque",
"quewait",
"runwait",
"running",
"closewait",
"dropped",
"timeout",
"overflow",
"error"
}
1.5.1