connio.c File Reference

#include "nsd.h"

Defines

#define IOBUFSZ   2048

Functions

int Ns_ConnInit (Ns_Conn *conn)
int Ns_ConnClose (Ns_Conn *conn)
int Ns_ConnFlush (Ns_Conn *conn, char *buf, int len, int stream)
int Ns_ConnFlushDirect (Ns_Conn *conn, char *buf, int len, int stream)
int Ns_ConnSend (Ns_Conn *conn, struct iovec *bufs, int nbufs)
int Ns_ConnWrite (Ns_Conn *conn, void *vbuf, int towrite)
int Ns_WriteConn (Ns_Conn *conn, char *buf, int len)
int Ns_WriteCharConn (Ns_Conn *conn, char *buf, int len)
int Ns_ConnPuts (Ns_Conn *conn, char *string)
int Ns_ConnSendDString (Ns_Conn *conn, Ns_DString *dsPtr)
int Ns_ConnSendChannel (Ns_Conn *conn, Tcl_Channel chan, int nsend)
int Ns_ConnSendFp (Ns_Conn *conn, FILE *fp, int nsend)
int Ns_ConnSendFd (Ns_Conn *conn, int fd, int nsend)
int Ns_ConnSendFdEx (Ns_Conn *conn, int fd, off_t off, int nsend)
int Ns_ConnFlushContent (Ns_Conn *conn)
char * Ns_ConnGets (char *buf, size_t bufsize, Ns_Conn *conn)
int Ns_ConnRead (Ns_Conn *conn, void *vbuf, int toread)
int Ns_ConnReadLine (Ns_Conn *conn, Ns_DString *dsPtr, int *nreadPtr)
int Ns_ConnReadHeaders (Ns_Conn *conn, Ns_Set *set, int *nreadPtr)
int Ns_ConnCopyToDString (Ns_Conn *conn, size_t ncopy, Ns_DString *dsPtr)
int Ns_ConnCopyToChannel (Ns_Conn *conn, size_t ncopy, Tcl_Channel chan)
int Ns_ConnCopyToFile (Ns_Conn *conn, size_t ncopy, FILE *fp)
int Ns_ConnCopyToFd (Ns_Conn *conn, size_t ncopy, int fd)

Define Documentation

#define IOBUFSZ   2048


Function Documentation

int Ns_ConnClose ( Ns_Conn *  conn  ) 

-----------------------------------------------------------------

Ns_ConnClose - Close a connection.

Results: Always NS_OK.

Side effects: The underlying socket in the connection is closed or moved to the waiting keep-alive list.

-----------------------------------------------------------------

int Ns_ConnCopyToChannel ( Ns_Conn *  conn,
size_t  ncopy,
Tcl_Channel  chan 
)

int Ns_ConnCopyToDString ( Ns_Conn *  conn,
size_t  ncopy,
Ns_DString *  dsPtr 
)

----------------------------------------------------------------------

Ns_ConnCopyToDString, File, Fd, Channel --

Copy data from a connection to a DString, channel, FILE, or fd.

Results: NS_OK or NS_ERROR

Side effects: See ConnCopy().

----------------------------------------------------------------------

int Ns_ConnCopyToFd ( Ns_Conn *  conn,
size_t  ncopy,
int  fd 
)

int Ns_ConnCopyToFile ( Ns_Conn *  conn,
size_t  ncopy,
FILE *  fp 
)

int Ns_ConnFlush ( Ns_Conn *  conn,
char *  buf,
int  len,
int  stream 
)

----------------------------------------------------------------------

Ns_ConnFlush --

Flush the headers and/or response content, handling character encoding and/or gzip compression if necessary.

Results: NS_ERROR if a connection write routine failed, NS_OK otherwise.

Side effects: Content may be encoded and/or gzip'ed before calling Ns_ConnFlushDirect.

----------------------------------------------------------------------

Encode content to the expected charset.

GZIP the content when not streaming if enabled and the content length is above the minimum.

Flush content.

int Ns_ConnFlushContent ( Ns_Conn *  conn  ) 

----------------------------------------------------------------------

Ns_ConnFlushContent --

Finish reading waiting content.

Results: NS_OK.

Side effects: None.

----------------------------------------------------------------------

int Ns_ConnFlushDirect ( Ns_Conn *  conn,
char *  buf,
int  len,
int  stream 
)

----------------------------------------------------------------------

Ns_ConnFlushDirect --

Flush the headers and/or response content either as a single response or in stream/chunked mode.

Results: NS_ERROR if a connection write routine failed, NS_OK otherwise.

Side effects: Headers will be flushed on first write. Output will be chunked if streaming to an HTTP version 1.1 or greater client.

----------------------------------------------------------------------

Queue headers if not already sent.

NB: Surpress Content-length header.

Send content on any request other than HEAD.

Output content without chunking header/trailers.

Output length header followed by content and trailer.

Output end-of-content trailer.

Write the output buffer and if not streaming, close the connection.

char* Ns_ConnGets ( char *  buf,
size_t  bufsize,
Ns_Conn *  conn 
)

----------------------------------------------------------------------

Ns_ConnGets --

Read in a string from a connection, stopping when either we've run out of data, hit a newline, or had an error

Results: Pointer to given buffer or NULL on error.

Side effects:

----------------------------------------------------------------------

int Ns_ConnInit ( Ns_Conn *  conn  ) 

-----------------------------------------------------------------

Ns_ConnInit --

Initialize a connection, currently doing nothing.

Results: Always NS_OK.

Side effects: None.

-----------------------------------------------------------------

int Ns_ConnPuts ( Ns_Conn *  conn,
char *  string 
)

----------------------------------------------------------------------

Ns_ConnPuts --

Write a null-terminated string to the conn; no trailing newline will be appended despite the name.

Results: See Ns_WriteConn

Side effects: See Ns_WriteConn

----------------------------------------------------------------------

int Ns_ConnRead ( Ns_Conn *  conn,
void *  vbuf,
int  toread 
)

----------------------------------------------------------------------

Ns_ConnRead --

Copy data from read-ahead buffers.

Results: Number of bytes copied.

Side effects: None.

----------------------------------------------------------------------

int Ns_ConnReadHeaders ( Ns_Conn *  conn,
Ns_Set *  set,
int *  nreadPtr 
)

----------------------------------------------------------------------

Ns_ConnReadHeaders --

Read the headers and insert them into the passed-in set

Results: NS_OK/NS_ERROR

Side effects: Stuff will be read from the conn

----------------------------------------------------------------------

int Ns_ConnReadLine ( Ns_Conn *  conn,
Ns_DString *  dsPtr,
int *  nreadPtr 
)

----------------------------------------------------------------------

Ns_ConnReadLine --

Read a line (
or
terminated) from the conn.

Results: NS_OK or NS_ERROR

Side effects: Stuff may be read

----------------------------------------------------------------------

int Ns_ConnSend ( Ns_Conn *  conn,
struct iovec *  bufs,
int  nbufs 
)

----------------------------------------------------------------------

Ns_ConnSend --

Sends buffers to clients, including any queued write-behind data if necessary. Unlike in previous versions of AOLserver, this routine attempts to send all data if possible.

Results: Number of bytes written, -1 for error on first send.

Side effects: Will truncate queued data after send.

----------------------------------------------------------------------

Send up to 16 buffers, including the queued output buffer if necessary.

Return error on first send, if any, from NsSockSend above.

int Ns_ConnSendChannel ( Ns_Conn *  conn,
Tcl_Channel  chan,
int  nsend 
)

----------------------------------------------------------------------

Ns_ConnSendChannel, Fp, Fd --

Send an open channel, FILE, or fd.

Results: NS_OK/NS_ERROR

Side effects: See ConnSend().

----------------------------------------------------------------------

int Ns_ConnSendDString ( Ns_Conn *  conn,
Ns_DString *  dsPtr 
)

----------------------------------------------------------------------

Ns_ConnSendDString --

Write contents of a DString

Results: See Ns_WriteConn

Side effects: See Ns_WriteConn

----------------------------------------------------------------------

int Ns_ConnSendFd ( Ns_Conn *  conn,
int  fd,
int  nsend 
)

int Ns_ConnSendFdEx ( Ns_Conn *  conn,
int  fd,
off_t  off,
int  nsend 
)

int Ns_ConnSendFp ( Ns_Conn *  conn,
FILE *  fp,
int  nsend 
)

int Ns_ConnWrite ( Ns_Conn *  conn,
void *  vbuf,
int  towrite 
)

----------------------------------------------------------------------

Ns_ConnWrite --

Send a single buffer to the client.

Results: # of bytes written from buffer or -1 on error.

Side effects: Stuff may be written

----------------------------------------------------------------------

int Ns_WriteCharConn ( Ns_Conn *  conn,
char *  buf,
int  len 
)

----------------------------------------------------------------------

Ns_WriteCharConn --

This will write a string buffer to the conn. The distinction being that the given data is explicitly a UTF8 character string, and will be put out in an 'encoding-aware' manner. It promises to write all of it.

If we think we are writing the headers (which is the default), then we send the data exactly as it is given to us. If we are truly in the headers, then they are supposed to be US-ASCII, which is a subset of UTF-8, so no translation should be needed if the user has been good and not put any 8-bit characters into it.

If we have been told that we are sending the content, and we have been given an encoding to translate the content to, then we assume that the caller is handing us UTF-8 bytes and we translate them to the preset encoding.

Results: NS_OK/NS_ERROR

Side effects: Stuff may be written

----------------------------------------------------------------------

int Ns_WriteConn ( Ns_Conn *  conn,
char *  buf,
int  len 
)

----------------------------------------------------------------------

Ns_WriteConn --

This will write a buffer to the conn. It promises to write all of it.

Results: NS_OK/NS_ERROR

Side effects: Stuff may be written

----------------------------------------------------------------------


Generated on Tue Sep 4 19:58:56 2007 by  doxygen 1.5.1