nanohttp-stream.h File Reference
Go to the source code of this file.
|
Classes |
| struct | http_input_stream_t |
| struct | http_output_stream_t |
Defines |
| #define | STREAM_ERROR 1200 |
| #define | STREAM_ERROR_INVALID_TYPE (STREAM_ERROR + 1) |
| #define | STREAM_ERROR_SOCKET_ERROR (STREAM_ERROR + 2) |
| #define | STREAM_ERROR_NO_CHUNK_SIZE (STREAM_ERROR + 3) |
| #define | STREAM_ERROR_WRONG_CHUNK_SIZE (STREAM_ERROR + 4) |
Typedefs |
| typedef enum http_transfer_type | http_transfer_type_t |
Enumerations |
| enum | http_transfer_type { HTTP_TRANSFER_CONTENT_LENGTH,
HTTP_TRANSFER_CHUNKED,
HTTP_TRANSFER_CONNECTION_CLOSE,
HTTP_TRANSFER_FILE
} |
Functions |
| http_input_stream_t * | http_input_stream_new (struct hsocket_t *sock, hpair_t *header) |
| http_input_stream_t * | http_input_stream_new_from_file (const char *filename) |
| void | http_input_stream_free (struct http_input_stream_t *stream) |
| int | http_input_stream_is_ready (struct http_input_stream_t *stream) |
| int | http_input_stream_read (struct http_input_stream_t *stream, unsigned char *dest, int size) |
| http_output_stream_t * | http_output_stream_new (struct hsocket_t *sock, hpair_t *header) |
| void | http_output_stream_free (struct http_output_stream_t *stream) |
| herror_t | http_output_stream_write (struct http_output_stream_t *stream, const unsigned char *bytes, int size) |
| herror_t | http_output_stream_write_string (struct http_output_stream_t *stream, const char *str) |
| herror_t | http_output_stream_flush (struct http_output_stream_t *stream) |
Detailed Description
nanoHTTP supports 2 different streams:
- http_input_stream_t
- http_output_stream_t
These are not regular streams. They will care about transfer styles while sending/receiving data.
Supported transfer styles are
- Content-length
- Chunked encoding
- Connection: "close"
A stream will set its transfer style from the header information, which must be given while creating a stream.
A stream will start sending/receiving data "after" sending/receiving header information. (After <CF><CF>)"
Typedef Documentation
|
|
Transfer types supported while sending/receiving data. |
Enumeration Type Documentation
|
|
Transfer types supported while sending/receiving data. - Enumerator:
-
| HTTP_TRANSFER_CONTENT_LENGTH |
The stream cares about Content-length |
| HTTP_TRANSFER_CHUNKED |
The stream sends/receives chunked data |
| HTTP_TRANSFER_CONNECTION_CLOSE |
The stream sends/receives data until connection is closed |
| HTTP_TRANSFER_FILE |
This transfer style will be used by MIME support and for debug purposes. |
|
Function Documentation
|
|
Free input stream. Note that the socket will not be closed by this functions.
- Parameters:
-
| stream | the input stream to free. |
|
|
|
Returns the actual status of the stream.
- Parameters:
-
| stream | the stream to check its status |
- Returns:
- - 1, if there is still data to read.
- 0, if no more data exists.
|
|
|
Creates a new input stream. The transfer style will be choosen from the given header.
- Parameters:
-
| sock | the socket to receive data from |
| header | the http header. This must be received before creating a http_input_stream_t. |
- Returns:
- a newly created http_input_stream_t object. If no transfer style was found in the header, HTTP_TRANSFER_CONNECTION_CLOSE will be used as default.
- See also:
- http_input_stream_free
|
|
|
Creates a new input stream from file. This function was added for MIME messages and for debugging. The transfer style is always HTTP_TRANSFER_FILE.
- Parameters:
-
| filename | the name of the file to open and read. |
- Returns:
- The return value is a http_input_stream_t object if the file exists and could be opened. NULL otherwise.
- See also:
- http_input_stream_free
|
| int http_input_stream_read |
( |
struct http_input_stream_t * |
stream, |
|
|
unsigned char * |
dest, |
|
|
int |
size |
|
) |
|
|
|
|
Tries to read 'size' bytes from the stream. Check always with http_input_stream_is_ready() if there are some data to read. If it returns 0, no more data is available on stream.
On error this function will return -1. In this case the "err" field of stream will be set to the actual error. This can be one of the followings:
- STREAM_ERROR_NO_CHUNK_SIZE
- STREAM_ERROR_WRONG_CHUNK_SIZE
- STREAM_ERROR_INVALID_TYPE
- HSOCKET_ERROR_RECEIVE
- Parameters:
-
| stream | the stream to read data from |
| dest | destination memory to store read bytes |
| size | maximum size of 'dest' (size to read) |
- Returns:
- the actual read bytes or -1 on error.
|
|
|
Sends finish flags if nesseccary (like in chunked transport). Call always this function before closing the connections.
- Parameters:
-
| stream | the stream to send post data. |
- Returns:
- H_OK on success. One of the followings otherwise
- HSOCKET_ERROR_NOT_INITIALIZED
- HSOCKET_ERROR_SEND
|
|
|
Free output stream. Note that this functions will not close any socket connections.
- Parameters:
-
| stream | the stream to free. |
|
|
|
Creates a new output stream. Transfer style will be found from the given header.
- Parameters:
-
| sock | the socket to to send data to |
| header | the header which must be sent before |
- Returns:
- a http_output_stream_t object. If no proper transfer style was found in the header, HTTP_TRANSFER_CONNECTION_CLOSE will be used as default.
- See also:
- http_output_stream_free
|
|
|
Writes 'size' bytes of 'bytes' into stream.
- Parameters:
-
| stream | the stream to use to send data |
| bytes | bytes to send |
| size | size of bytes to send |
- Returns:
- H_OK on success. One of the followings otherwise
- HSOCKET_ERROR_NOT_INITIALIZED
- HSOCKET_ERROR_SEND
|
|
|
Writes a null terminated string to the stream.
- Parameters:
-
| stream | the stream to use to send data |
| str | a null terminated string to send |
- Returns:
- H_OK on success. One of the followings otherwise
- HSOCKET_ERROR_NOT_INITIALIZED
- HSOCKET_ERROR_SEND
|
Generated on Thu Jan 25 23:36:00 2007 for csoap by
1.4.6