Cp_socket


Files

file  client.h
file  http.c
file  http.h
file  httpclient.h
file  socket.c
file  socket.h

Data Structures

struct  _cp_client
struct  cp_http_status_code_entry
struct  _cp_http_request
struct  _cp_http_response
struct  _cp_httpsocket
struct  _cp_http_service
struct  _cp_httpclient
struct  _cp_url_descriptor
struct  _cp_httpclient_result
struct  _cp_httpclient_ctl
struct  _cp_http_transfer_descriptor
struct  _cp_socket
struct  _cp_connection_descriptor

Defines

#define DEFAULT_CLIENT_TIMEOUT   300
#define DEFAULT_RETRIES   3
#define HTTP_PARSE_BUFSIZE   0xFFFF
#define MATCHMAX   10
#define HTTP_RE_MATCHMAX   10
#define REQUEST_STAGE_START   0
#define REQUEST_STAGE_STATUS_LINE   1
#define REQUEST_STAGE_HEADERS   2
#define REQUEST_STAGE_BODY   3
#define REQUEST_STAGE_DONE   4
#define HEXDIGIT(c)
#define DEFAULT_SERVER_NAME   "cprops-__CPROPSVERSION"
#define DEFAULT_KEEPALIVE   300
#define HTTP_KEEPALIVE   DEFAULT_KEEPALIVE
#define MAX_URL_LENGTH   0x400
#define DEFAULT_MAX_REDIRECTS   10
#define CPSOCKET_DEFAULT_BACKLOG   50
#define CPSOCKET_DEFAULT_DELAY_SEC   1
#define CPSOCKET_DEFAULT_DELAY_USEC   0
#define CPSOCKET_THREADPOOL_DEFAULT_SIZE_MIN   5
#define CPSOCKET_THREADPOOL_DEFAULT_SIZE_MAX   50
#define cp_connection_descriptor_get_socket(cd)   ((cd)->sock)
#define cp_connection_descriptor_get_addr(cd)   ((cd)->addr)
#define cp_connection_descriptor_get_fd(cd)   ((cd)->fd)

Typedefs

typedef CPROPS_DLL struct
_cp_client 
cp_client
typedef CPROPS_DLL enum { ... }  cp_http_version
typedef CPROPS_DLL enum { ... }  cp_http_status_code
typedef CPROPS_DLL enum { ... }  connection_policy
typedef CPROPS_DLL enum { ... }  cp_http_content_type
typedef CPROPS_DLL struct
_cp_http_request 
cp_http_request
typedef CPROPS_DLL struct
_cp_http_response 
cp_http_response
typedef int(*) cp_http_service_callback (cp_http_request *request, cp_http_response *response)
typedef CPROPS_DLL struct
_cp_httpsocket 
cp_httpsocket
typedef CPROPS_DLL struct
_cp_http_service 
cp_http_service
typedef CPROPS_DLL struct
_cp_httpclient 
cp_httpclient
typedef CPROPS_DLL struct
_cp_url_descriptor 
cp_url_descriptor
typedef CPROPS_DLL struct
_cp_httpclient_result 
cp_httpclient_result
typedef CPROPS_DLL struct
_cp_httpclient_ctl 
cp_httpclient_ctl
typedef void(*) cp_httpclient_callback (cp_httpclient_result *response)
typedef CPROPS_DLL struct
_cp_http_transfer_descriptor 
cp_http_transfer_descriptor
typedef CPROPS_DLL enum { ... }  cp_socket_strategy
typedef void *(*) cp_socket_thread_function (void *)
typedef int(*) cp_socket_callback (struct _cp_socket *, int fd)
typedef CPROPS_DLL struct
_cp_socket 
cp_socket
typedef CPROPS_DLL struct
_cp_connection_descriptor 
cp_connection_descriptor

Enumerations

enum  {
  OPTIONS, GET, HEAD, POST,
  PUT, DELETE, TRACE, CONNECT
}
enum  { HTTP_1_0, HTTP_1_1 }
enum  {
  HTTP_NULL_STATUS = -1, HTTP_100_CONTINUE = 100, HTTP_101_SWITCHING_PROTOCOLS = 101, HTTP_200_OK = 200,
  HTTP_201_CREATED = 201, HTTP_202_ACCEPTED = 202, HTTP_203_NON_AUTHORITATIVE_INFORMATION = 203, HTTP_204_NO_CONTENT = 204,
  HTTP_205_RESET_CONTENT = 205, HTTP_206_PARTIAL_CONTENT = 206, HTTP_300_MULTIPLE_CHOICES = 300, HTTP_301_MOVED_PERMANENTLY = 301,
  HTTP_302_FOUND = 302, HTTP_303_SEE_OTHER = 303, HTTP_304_NOT_MODIFIED = 304, HTTP_305_USE_PROXY = 305,
  HTTP_307_TEMPORARY_REDIRECT = 307, HTTP_400_BAD_REQUEST = 400, HTTP_401_UNAUTHORIZED = 401, HTTP_402_PAYMENT_REQUIRED = 402,
  HTTP_403_FORBIDDEN = 403, HTTP_404_NOT_FOUND = 404, HTTP_405_METHOD_NOT_ALLOWED = 405, HTTP_406_NOT_ACCEPTABLE = 406,
  HTTP_407_PROXY_AUTHENTICATION_REQUIRED = 407, HTTP_408_REQUEST_TIME_OUT = 408, HTTP_409_CONFLICT = 409, HTTP_410_GONE = 410,
  HTTP_411_LENGTH_REQUIRED = 411, HTTP_412_PRECONDITION_FAILED = 412, HTTP_413_REQUEST_ENTITY_TOO_LARGE = 413, HTTP_414_REQUEST_URI_TOO_LARGE = 414,
  HTTP_415_UNSUPPORTED_MEDIA_TYPE = 415, HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE = 416, HTTP_417_EXPECTATION_FAILED = 417, HTTP_500_INTERNAL_SERVER_ERROR = 500,
  HTTP_501_NOT_IMPLEMENTED = 501, HTTP_502_BAD_GATEWAY = 502, HTTP_503_SERVICE_UNAVAILABLE = 503, HTTP_504_GATEWAY_TIME_OUT = 504,
  HTTP_505_HTTP_VERSION_NOT_SUPPORTED = 505
}
enum  { HTTP_CONNECTION_POLICY_DEFAULT, HTTP_CONNECTION_POLICY_CLOSE, HTTP_CONNECTION_POLICY_KEEP_ALIVE }
enum  { TEXT, HTML, JPEG }
enum  cp_http_result_status {
  CP_HTTP_RESULT_SUCCESS, CP_HTTP_RESULT_CONNECTION_FAILED, CP_HTTP_RESULT_CONNECTION_RESET, CP_HTTP_RESULT_TIMED_OUT,
  CP_HTTP_RESULT_WRITE_ERROR, CP_HTTP_RESULT_READ_ERROR
}
enum  { CPSOCKET_STRATEGY_CALLBACK, CPSOCKET_STRATEGY_THREADPOOL }

Functions

CPROPS_DLL void cp_client_init ()
CPROPS_DLL void cp_client_stop_all ()
CPROPS_DLL void cp_client_shutdown ()
CPROPS_DLL void cp_tcp_add_shutdown_callback (void(*cb)(void *), void *prm)
CPROPS_DLL cp_clientcp_client_create (char *host, int port)
CPROPS_DLL cp_clientcp_client_create_addr (struct sockaddr_in *)
CPROPS_DLL void cp_client_set_timeout (cp_client *client, int sec, int usec)
CPROPS_DLL void cp_client_set_retry (cp_client *client, int retry_count)
CPROPS_DLL void cp_client_set_owner (cp_client *client, void *owner)
CPROPS_DLL int cp_client_connect (cp_client *client)
CPROPS_DLL int cp_client_reopen (cp_client *client, char *host, int port)
CPROPS_DLL int cp_client_close (cp_client *client)
CPROPS_DLL void cp_client_destroy (cp_client *client)
CPROPS_DLL int cp_client_read (cp_client *client, char *buf, int len)
CPROPS_DLL int cp_client_read_string (cp_client *client, cp_string *str, int len)
CPROPS_DLL int cp_client_write (cp_client *client, char *buf, int len)
CPROPS_DLL int cp_client_write_string (cp_client *client, cp_string *str)
void cp_http_signal_handler (int sig)
void * session_cleanup_thread (void *)
int cp_http_init ()
void cp_httpsocket_stop_all ()
void cp_httpsocket_stop (cp_httpsocket *sock)
void * cp_http_add_shutdown_callback (void(*cb)(void *), void *prm)
void cp_http_shutdown ()
void cp_http_request_delete (cp_http_request *request)
char * get_http_request_type_lit (cp_http_request_type type)
void urldecode (char *str, char **decoded)
char * cp_http_request_get_header (cp_http_request *req, char *header)
char ** cp_http_request_get_headers (cp_http_request *request)
char * cp_http_request_get_parameter (cp_http_request *request, char *name)
void cp_http_request_dump (cp_http_request *req)
cp_http_responsecp_http_response_create (cp_http_request *req)
void cp_http_response_delete (cp_http_response *response)
void cp_http_response_destroy (cp_http_response *res)
int cp_http_response_write (cp_connection_descriptor *cdesc, cp_http_response *res)
void cp_http_response_set_status (cp_http_response *response, cp_http_status_code status)
cp_http_status_code cp_http_response_get_status (cp_http_response *response)
void cp_http_response_set_content_type (cp_http_response *response, cp_http_content_type type)
void cp_http_response_set_content_type_string (cp_http_response *response, char *content_type)
char * cp_http_response_get_content_type (cp_http_response *response)
void cp_http_response_set_header (cp_http_response *response, char *name, char *value)
char * cp_http_response_get_header (cp_http_response *response, char *name)
cp_vector * cp_http_response_get_header_names (cp_http_response *response)
void cp_http_response_set_body (cp_http_response *response, char *body)
void cp_http_response_set_content (cp_http_response *response, cp_string *content)
cp_stringcp_http_response_get_content (cp_http_response *response)
void cp_http_response_set_connection_policy (cp_http_response *response, connection_policy policy)
void cp_http_response_skip (cp_http_response *response)
cp_httpsocketcp_httpsocket_create (int port, cp_http_service_callback service)
void cp_httpsocket_set_keepalive (cp_httpsocket *socket, int sec)
void cp_httpsocket_set_server_name (cp_httpsocket *socket, char *name)
void cp_httpsocket_set_backlog (cp_httpsocket *socket, int backlog)
void cp_httpsocket_set_delay (cp_httpsocket *socket, struct timeval delay)
void cp_httpsocket_set_delay_sec (cp_httpsocket *socket, long sec)
void cp_httpsocket_set_delay_usec (cp_httpsocket *socket, long usec)
void cp_httpsocket_set_poolsize_min (cp_httpsocket *socket, int min)
void cp_httpsocket_set_poolsize_max (cp_httpsocket *socket, int max)
void cp_httpsocket_delete (cp_httpsocket *sock)
void * cp_httpsocket_add_shutdown_callback (cp_httpsocket *socket, void(*cb)(void *), void *prm)
int cp_httpsocket_listen (cp_httpsocket *sock)
int cp_httpsocket_register_service (cp_httpsocket *server, cp_http_service *service)
void * cp_httpsocket_unregister_service (cp_httpsocket *server, cp_http_service *service)
cp_http_servicecp_http_service_create (char *name, char *path, cp_http_service_callback callback)
void cp_http_service_delete (cp_http_service *service)
void cp_http_response_report_error (cp_http_response *response, cp_http_status_code code, char *message)
void * cp_http_thread_fn (void *prm)
CPROPS_DLL cp_http_requestcp_http_request_parse (struct _cp_httpsocket *owner, char *request, int *err)
CPROPS_DLL cp_vector * cp_http_request_get_param_vector (cp_http_request *request, char *name)
CPROPS_DLL cp_vector * cp_http_request_get_params (cp_http_request *request)
__BEGIN_DECLS CPROPS_DLL int cp_httpclient_init ()
CPROPS_DLL int cp_httpclient_shutdown ()
CPROPS_DLL cp_httpclientcp_httpclient_create (char *host, int port)
CPROPS_DLL cp_httpclientcp_httpclient_create_proxy (char *host, int port, char *proxy_host, int proxy_port)
CPROPS_DLL void cp_httpclient_destroy (cp_httpclient *client)
CPROPS_DLL void cp_httpclient_set_http_version (cp_httpclient *client, cp_http_version version)
CPROPS_DLL void cp_httpclient_set_request_type (cp_httpclient *client, cp_http_request_type type)
CPROPS_DLL void cp_httpclient_set_header (cp_httpclient *client, char *header, char *value)
CPROPS_DLL void cp_httpclient_set_auto_drop_headers (cp_httpclient *client, short mode)
CPROPS_DLL void cp_httpclient_drop_headers (cp_httpclient *client)
CPROPS_DLL void * cp_httpclient_set_parameter (cp_httpclient *client, char *name, char *value)
CPROPS_DLL void cp_httpclient_set_auto_drop_parameters (cp_httpclient *client, short mode)
CPROPS_DLL void cp_httpclient_drop_parameters (cp_httpclient *client)
CPROPS_DLL void cp_httpclient_set_user_agent (cp_httpclient *client, char *agent)
CPROPS_DLL void cp_httpclient_set_timeout (cp_httpclient *client, int sec, int usec)
CPROPS_DLL void cp_httpclient_set_retry (cp_httpclient *client, int retry_count)
CPROPS_DLL void cp_httpclient_allow_redirects (cp_httpclient *client, int mode)
CPROPS_DLL void cp_httpclient_set_max_redirects (cp_httpclient *client, int max)
CPROPS_DLL int cp_httpclient_reopen (cp_httpclient *client, char *host, int port)
CPROPS_DLL cp_url_descriptorcp_url_descriptor_create (char *host, short ssl, int port, char *uri)
CPROPS_DLL void cp_url_descriptor_destroy (cp_url_descriptor *desc)
CPROPS_DLL short cp_url_descriptor_ssl (cp_url_descriptor *desc)
CPROPS_DLL char * cp_url_descriptor_host (cp_url_descriptor *desc)
CPROPS_DLL int cp_url_descriptor_port (cp_url_descriptor *desc)
CPROPS_DLL char * cp_url_descriptor_uri (cp_url_descriptor *desc)
CPROPS_DLL cp_url_descriptorcp_url_descriptor_parse (char *url)
CPROPS_DLL cp_httpclient_resultcp_httpclient_result_create (cp_httpclient *client)
CPROPS_DLL void cp_httpclient_result_destroy (cp_httpclient_result *res)
CPROPS_DLL void * cp_httpclient_result_id (cp_httpclient_result *res)
CPROPS_DLL cp_http_result_status cp_httpclient_result_status (cp_httpclient_result *res)
CPROPS_DLL cp_http_responsecp_httpclient_result_get_response (cp_httpclient_result *res)
CPROPS_DLL cp_httpclientcp_httpclient_result_get_client (cp_httpclient_result *res)
CPROPS_DLL cp_httpclient_resultcp_httpclient_fetch (cp_httpclient *client, char *uri)
CPROPS_DLL cp_httpclient_ctlcp_httpclient_ctl_create (int background)
CPROPS_DLL void cp_httpclient_ctl_destroy (cp_httpclient_ctl *ctl)
CPROPS_DLL fd_set * cp_httpclient_ctl_default_get_read_fd_set (int *num)
CPROPS_DLL fd_set * cp_httpclient_ctl_get_read_fd_set (cp_httpclient_ctl *ctl, int *num)
CPROPS_DLL fd_set * cp_httpclient_ctl_default_get_write_fd_set (int *num)
CPROPS_DLL fd_set * cp_httpclient_ctl_get_write_fd_set (cp_httpclient_ctl *ctl, int *num)
CPROPS_DLL cp_http_transfer_descriptorcp_http_transfer_descriptor_create (void *id, cp_httpclient *client, cp_httpclient_callback callback, char *uri)
CPROPS_DLL void cp_http_transfer_descriptor_destroy (cp_http_transfer_descriptor *desc)
CPROPS_DLL int cp_httpclient_fetch_nb (cp_httpclient *client, char *uri, void *id, cp_httpclient_callback callback, int background)
CPROPS_DLL int cp_httpclient_fetch_ctl (cp_httpclient_ctl *ctl, cp_httpclient *client, char *uri, void *id, cp_httpclient_callback callback)
CPROPS_DLL int cp_httpclient_fetch_nb_exec ()
CPROPS_DLL int cp_httpclient_fetch_ctl_exec (cp_httpclient_ctl *ctl)
void cp_socket_init ()
void cp_socket_stop (cp_socket *sock)
void cp_socket_stop_all ()
void cp_socket_shutdown ()
int setnonblocking (int sock)
cp_connection_descriptorcp_connection_descriptor_create (cp_socket *sock, struct sockaddr_in *addr, int fd)
void cp_connection_descriptor_destroy (cp_connection_descriptor *conn_desc)
cp_socketcp_socket_create (int port, cp_socket_strategy strategy, void *fn)
void cp_socket_set_backlog (cp_socket *socket, int backlog)
void cp_socket_set_delay (cp_socket *socket, struct timeval delay)
void cp_socket_set_delay_sec (cp_socket *socket, long sec)
void cp_socket_set_delay_usec (cp_socket *socket, long usec)
void cp_socket_set_poolsize_min (cp_socket *socket, int min)
void cp_socket_set_poolsize_max (cp_socket *socket, int max)
void cp_socket_set_owner (cp_socket *socket, void *owner)
void * cp_socket_add_shutdown_callback (cp_socket *sock, void(*cb)(void *), void *prm)
void cp_socket_delete (cp_socket *sock)
int cp_socket_listen (cp_socket *sock)
int cp_socket_select_callback_impl (cp_socket *sock)
int cp_socket_select_threadpool_impl (cp_socket *sock)
int cp_socket_select (cp_socket *sock)
int cp_socket_connection_close (cp_socket *sock, int fd)
int cp_connection_descrpitor_read (cp_connection_descriptor *desc, char *buf, int len)
int cp_connection_descriptor_write (cp_connection_descriptor *desc, char *buf, int len)

Variables

cp_http_status_code_entry cp_http_status_code_list []
volatile int cp_http_stopping = 0
__BEGIN_DECLS typedef CPROPS_DLL
enum { ... }  
cp_http_request_type
CPROPS_DLL _cp_httpsocket
volatile int stopping_all = 0

Define Documentation

#define cp_connection_descriptor_get_addr ( cd   )     ((cd)->addr)

return client address for given connection descriptor

Definition at line 254 of file socket.h.

Referenced by cp_http_thread_fn().

#define cp_connection_descriptor_get_fd ( cd   )     ((cd)->fd)

return file descriptor for given connection descriptor

Definition at line 256 of file socket.h.

Referenced by cp_http_response_write(), and cp_http_thread_fn().

#define cp_connection_descriptor_get_socket ( cd   )     ((cd)->sock)

return cp_socket struct for given connection descriptor

Definition at line 252 of file socket.h.

Referenced by cp_http_response_write(), and cp_http_thread_fn().

#define DEFAULT_CLIENT_TIMEOUT   300

seconds to wait for responses

Definition at line 50 of file client.h.

#define DEFAULT_RETRIES   3

default connect retries

Definition at line 53 of file client.h.

Referenced by cp_client_create(), and cp_client_create_addr().

#define HEXDIGIT (  ) 

Value:

((c) >= '0' && (c) <= '9' ? (c) - '0' : \
                     ((c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 0xA : \
                     ((c) >= 'a' && (c) <= 'f' ? (c) - 'a' + 0xA : -1)))

Definition at line 903 of file http.c.

Referenced by urldecode().


Typedef Documentation

typedef { ... } connection_policy

connection handling policy. HTTP_CONNECTION_POLICY_DEFAULT defaults to HTTP_CONNECTION_POLICY_CLOSE for HTTP/1.0 and to HTTP_CONNECTION_POLICY_KEEP_ALIVE for HTTP/1.1.

typedef CPROPS_DLL struct _cp_client cp_client

cp_client is a 'client socket'. create a cp_client with address information, call cp_client_connect() and communicate on the resulting file descriptor.

typedef CPROPS_DLL struct _cp_connection_descriptor cp_connection_descriptor

connection descriptor structure

typedef CPROPS_DLL struct _cp_http_request cp_http_request

http request descriptor

typedef CPROPS_DLL struct _cp_http_response cp_http_response

http response holder

typedef CPROPS_DLL struct _cp_http_service cp_http_service

http service descriptor

typedef int(*) cp_http_service_callback(cp_http_request *request, cp_http_response *response)

service function prototype

Definition at line 482 of file http.h.

typedef { ... } cp_http_status_code

HTTP status codes

typedef CPROPS_DLL struct _cp_http_transfer_descriptor cp_http_transfer_descriptor

transfer descriptor for async interface

typedef { ... } cp_http_version

HTTP versions

typedef CPROPS_DLL struct _cp_httpclient cp_httpclient

http client socket wrapper

typedef CPROPS_DLL struct _cp_httpclient_ctl cp_httpclient_ctl

asynchronous interface control block. By default asynchronous transfers use a static block shared between all client transfers. To separate transfers into different groups, create a cp_httpclient_ctl control block and use _fetch_ctl_nb and _fetch_ctl_nb_exec().

typedef CPROPS_DLL struct _cp_httpclient_result cp_httpclient_result

wrapper for asynchronous interface callback

typedef CPROPS_DLL struct _cp_httpsocket cp_httpsocket

http server socket

typedef CPROPS_DLL struct _cp_socket cp_socket

cp_socket is a 'server socket'. create a cp_socket to listen on a port, specify a callback to implemet your communication protocol (libcprops provides a basic http implementation you could plug in) and the strategy you want for handling handling multiple connections - use a thread pool to serve each connection on its own thread or a more select()-like approach.

If you create a socket with the CPSOCKET_STRATEGY_THREADPOOL, supply a thread function to handle communication once a connection has been accept()-ed. Your cp_thread function should close the connection when done and check the 'closing' flag, which is set to 1 on shutdown.

If you create a socket with the CPSOCKET_STRATEGY_CALLBACK, supply a callback to process incremental feeds as they come along.

typedef int(*) cp_socket_callback(struct _cp_socket *, int fd)

function prototype for callback implementation

Definition at line 98 of file socket.h.

typedef { ... } cp_socket_strategy

cp_socket connection handling strategy

typedef void*(*) cp_socket_thread_function(void *)

thread function for threadpool implementation

Definition at line 96 of file socket.h.

typedef CPROPS_DLL struct _cp_url_descriptor cp_url_descriptor

wrapper for url information


Enumeration Type Documentation

anonymous enum

HTTP request types

Definition at line 144 of file http.h.

anonymous enum

HTTP versions

Definition at line 162 of file http.h.

anonymous enum

HTTP status codes

Definition at line 165 of file http.h.

anonymous enum

connection handling policy. HTTP_CONNECTION_POLICY_DEFAULT defaults to HTTP_CONNECTION_POLICY_CLOSE for HTTP/1.0 and to HTTP_CONNECTION_POLICY_KEEP_ALIVE for HTTP/1.1.

Definition at line 215 of file http.h.

anonymous enum

cp_socket connection handling strategy

Definition at line 86 of file socket.h.

enum cp_http_result_status

result codes for HTTP requests

Definition at line 262 of file httpclient.h.


Function Documentation

CPROPS_DLL int cp_client_close ( cp_client client  ) 

close a client connection

Definition at line 668 of file client.c.

References CP_IO_ERROR, and cp_perror().

Referenced by cp_client_reopen(), and cp_httpclient_destroy().

CPROPS_DLL int cp_client_connect ( cp_client client  ) 

open connection

Definition at line 572 of file client.c.

References cp_error(), CP_INITIALIZATION_FAILURE, and CP_MEMORY_ALLOCATION_FAILURE.

Referenced by cp_client_reopen().

CPROPS_DLL cp_client* cp_client_create ( char *  host,
int  port 
)

create a client socket

Definition at line 396 of file client.c.

References cp_client_destroy(), CP_IO_ERROR, cp_perror(), and DEFAULT_RETRIES.

Referenced by cp_httpclient_create(), and cp_httpclient_create_proxy().

CPROPS_DLL cp_client* cp_client_create_addr ( struct sockaddr_in *  addr  ) 

create a client socket with a struct sockaddr *

Definition at line 496 of file client.c.

References DEFAULT_RETRIES.

CPROPS_DLL void cp_client_destroy ( cp_client client  ) 

deallocate a cp_client

Definition at line 707 of file client.c.

Referenced by cp_client_create(), and cp_httpclient_destroy().

CPROPS_DLL void cp_client_init (  ) 

recommended to call before using tcp client socket functions

Definition at line 255 of file client.c.

References cp_fatal(), CP_INITIALIZATION_FAILURE, CP_MEMORY_ALLOCATION_FAILURE, and cp_socket_init().

Referenced by cp_httpclient_init().

CPROPS_DLL int cp_client_reopen ( cp_client client,
char *  host,
int  port 
)

use the same wrapper for a different address. this will close an existing connection, change the host and port settings on the wrapper and attempt to connect. maybe rename this function.

Definition at line 450 of file client.c.

References cp_client_close(), cp_client_connect(), cp_error(), CP_IO_ERROR, and cp_perror().

Referenced by cp_httpclient_fetch(), and cp_httpclient_reopen().

CPROPS_DLL void cp_client_set_owner ( cp_client client,
void *  owner 
)

useful free pointer for client code

Definition at line 527 of file client.c.

CPROPS_DLL void cp_client_set_retry ( cp_client client,
int  retry_count 
)

number of connection retries

Definition at line 521 of file client.c.

Referenced by cp_httpclient_set_retry().

CPROPS_DLL void cp_client_set_timeout ( cp_client client,
int  sec,
int  usec 
)

set the timeout - (0, 0) for no timeout

Definition at line 514 of file client.c.

Referenced by cp_httpclient_set_timeout().

CPROPS_DLL void cp_client_shutdown (  ) 

performs cleanup

Definition at line 271 of file client.c.

References cp_socket_shutdown().

Referenced by cp_httpclient_shutdown().

CPROPS_DLL void cp_client_stop_all (  ) 

call from signal handler to stop sockets in waiting select() and close all connections

CPROPS_DLL cp_connection_descriptor * cp_connection_descriptor_create ( cp_socket sock,
struct sockaddr_in *  addr,
int  fd 
)

internal: create a new connection descriptor

Definition at line 391 of file socket.c.

References cp_error(), and CP_MEMORY_ALLOCATION_FAILURE.

Referenced by cp_socket_select_threadpool_impl().

CPROPS_DLL void cp_connection_descriptor_destroy ( cp_connection_descriptor conn_desc  ) 

deallocate a connection descriptor

Definition at line 428 of file socket.c.

References cp_socket_connection_close().

Referenced by cp_http_thread_fn().

CPROPS_DLL int cp_connection_descriptor_write ( cp_connection_descriptor desc,
char *  buf,
int  len 
)

write on a connection descriptor

Definition at line 1118 of file socket.c.

References cp_error(), and CP_IO_ERROR.

CPROPS_DLL int cp_connection_descrpitor_read ( cp_connection_descriptor desc,
char *  buf,
int  len 
)

read from a connection descriptor

Definition at line 1093 of file socket.c.

References cp_error(), and CP_IO_ERROR.

CPROPS_DLL void * cp_http_add_shutdown_callback ( void(*)(void *)  cb,
void *  prm 
)

called when shutting down http layer

Definition at line 278 of file http.c.

CPROPS_DLL int cp_http_init (  ) 

recommended to call before using cp_httpsocket api

Definition at line 198 of file http.c.

References COLLECTION_MODE_DEEP, cp_hash_compare_int(), cp_hash_int(), cp_hashlist_create_by_mode(), cp_hashtable_create(), cp_hashtable_put(), cp_http_signal_handler(), cp_socket_init(), and cp_http_status_code_entry::lit.

Referenced by cp_httpsocket_create().

CPROPS_DLL void cp_http_request_delete ( cp_http_request request  ) 

deallocate an http request descriptor

Definition at line 679 of file http.c.

References cp_hashtable_destroy().

Referenced by cp_http_thread_fn().

CPROPS_DLL void cp_http_request_dump ( cp_http_request req  ) 

dump a cp_http_request descriptor (uses cp_info)

Definition at line 1017 of file http.c.

References cp_hashtable_count(), cp_hashtable_get(), cp_hashtable_get_keys(), and cp_info().

Referenced by cp_http_thread_fn().

CPROPS_DLL char * cp_http_request_get_header ( cp_http_request request,
char *  name 
)

return value of specified header or NULL if none

Definition at line 977 of file http.c.

References cp_hashtable_get().

CPROPS_DLL char ** cp_http_request_get_headers ( cp_http_request request  ) 

return a newly allocated array of header names

Definition at line 987 of file http.c.

References cp_hashtable_get_keys().

CPROPS_DLL cp_vector* cp_http_request_get_param_vector ( cp_http_request request,
char *  name 
)

return vector of GET or POST parameters with specified name

CPROPS_DLL char * cp_http_request_get_parameter ( cp_http_request request,
char *  name 
)

return a single parameter with the specified name

Definition at line 996 of file http.c.

References cp_hashtable_get().

Referenced by cp_http_thread_fn().

CPROPS_DLL cp_vector* cp_http_request_get_params ( cp_http_request request  ) 

return all GET or POST parameters for given request

CPROPS_DLL cp_http_request* cp_http_request_parse ( struct _cp_httpsocket owner,
char *  request,
int *  err 
)

parse an http request

CPROPS_DLL cp_http_response * cp_http_response_create ( cp_http_request request  ) 

(internal) create a new response descriptor

Definition at line 1082 of file http.c.

References COLLECTION_MODE_COPY, COLLECTION_MODE_DEEP, COLLECTION_MODE_NOSYNC, cp_hash_compare_string(), cp_hash_string(), cp_hashtable_create_by_option(), DEFAULT_SERVER_NAME, and _cp_http_response::request.

Referenced by cp_http_thread_fn().

CPROPS_DLL void cp_http_response_delete ( cp_http_response res  ) 

(internal) deallocate a response descriptor

Definition at line 1111 of file http.c.

References cp_hashtable_destroy(), and cp_string_delete().

Referenced by cp_http_response_destroy(), cp_http_thread_fn(), cp_httpclient_fetch(), cp_httpclient_result_destroy(), and cp_httpsocket_delete().

CPROPS_DLL void cp_http_response_destroy ( cp_http_response res  ) 

deallocate a response descriptor

Definition at line 1134 of file http.c.

References cp_http_response_delete().

CPROPS_DLL cp_string * cp_http_response_get_content ( cp_http_response response  ) 

get the content of an http response

Definition at line 1360 of file http.c.

CPROPS_DLL char * cp_http_response_get_content_type ( cp_http_response response  ) 

get the Content-Type header value for an http response

Definition at line 1319 of file http.c.

References cp_hashtable_get().

CPROPS_DLL char * cp_http_response_get_header ( cp_http_response response,
char *  name 
)

retrieve header content for one header

Definition at line 1330 of file http.c.

References cp_hashtable_get().

CPROPS_DLL cp_vector * cp_http_response_get_header_names ( cp_http_response response  ) 

returns a vector containing header names

Definition at line 1335 of file http.c.

References cp_hashtable_count(), and cp_hashtable_get_keys().

CPROPS_DLL cp_http_status_code cp_http_response_get_status ( cp_http_response response  ) 

get the status code of an http response

Definition at line 1302 of file http.c.

CPROPS_DLL void cp_http_response_report_error ( cp_http_response response,
cp_http_status_code  code,
char *  message 
)

set up a response reporting an error

Definition at line 1733 of file http.c.

References cp_hashtable_get(), cp_http_response_set_body(), cp_http_response_set_content_type(), cp_http_response_set_status(), and DEFAULT_SERVER_NAME.

CPROPS_DLL void cp_http_response_set_body ( cp_http_response response,
char *  body 
)

deprecated - use cp_http_response_set_content instead

Definition at line 1348 of file http.c.

Referenced by cp_http_response_report_error().

CPROPS_DLL void cp_http_response_set_connection_policy ( cp_http_response response,
connection_policy  policy 
)

set the Connection header on a cp_http_response descriptor

Definition at line 1365 of file http.c.

CPROPS_DLL void cp_http_response_set_content ( cp_http_response response,
cp_string content 
)

set the (possibly binary) content on an http response

Definition at line 1354 of file http.c.

CPROPS_DLL void cp_http_response_set_content_type ( cp_http_response response,
cp_http_content_type  type 
)

deprecated - use cp_http_response_set_content_type_string

Definition at line 1307 of file http.c.

Referenced by cp_http_response_report_error().

CPROPS_DLL void cp_http_response_set_content_type_string ( cp_http_response response,
char *  content_type_lit 
)

set the Content-Type header on an http response

Definition at line 1313 of file http.c.

CPROPS_DLL void cp_http_response_set_header ( cp_http_response response,
char *  name,
char *  value 
)

set an arbitrary header on an http response

Definition at line 1324 of file http.c.

References cp_hashtable_put().

CPROPS_DLL void cp_http_response_set_status ( cp_http_response response,
cp_http_status_code  code 
)

set the status code on an http response

Definition at line 1296 of file http.c.

Referenced by cp_http_response_report_error().

CPROPS_DLL void cp_http_response_skip ( cp_http_response response  ) 

sets the 'skip' flag on an http response, which prevents the response being deserialized and written to the client by the http framework. this is needed if the service function writes directly to the underlying socket.

Definition at line 1437 of file http.c.

CPROPS_DLL int cp_http_response_write ( cp_connection_descriptor cdesc,
cp_http_response res 
)

(internal) output an http response on given connection

Definition at line 1139 of file http.c.

References cp_connection_descriptor_get_fd, cp_connection_descriptor_get_socket, cp_hashtable_count(), cp_hashtable_get(), cp_hashtable_get_keys(), cp_info(), cp_log(), cp_ndump(), cp_nlog(), DEBUGMSG, DEFAULT_SERVER_NAME, HTTP_PARSE_BUFSIZE, and LOG_LEVEL_INFO.

Referenced by cp_http_thread_fn().

CPROPS_DLL cp_http_service * cp_http_service_create ( char *  name,
char *  path,
cp_http_service_callback  service 
)

create a new cp_http_service descriptor. client requests for uris beginning with 'path' will be delegated to this service once registered on a listening socket.

Definition at line 1669 of file http.c.

References cp_error(), and CP_MEMORY_ALLOCATION_FAILURE.

CPROPS_DLL void cp_http_service_delete ( cp_http_service svc  ) 

deallocate a cp_http_service descriptor

Definition at line 1689 of file http.c.

References cp_warn().

Referenced by cp_httpsocket_register_service().

CPROPS_DLL void cp_http_shutdown (  ) 

call to perform cleanup after using cp_httpsocket api

Definition at line 292 of file http.c.

References cp_hashlist_destroy_custom(), cp_hashtable_destroy(), cp_httpsocket_stop(), cp_socket_shutdown(), and DEBUGMSG.

Referenced by cp_http_signal_handler().

CPROPS_DLL void cp_httpclient_allow_redirects ( cp_httpclient client,
int  mode 
)

set client behavior on HTTP 302, 302 etc. responses

Definition at line 542 of file httpclient.c.

CPROPS_DLL cp_httpclient* cp_httpclient_create ( char *  host,
int  port 
)

create an http client wrapper to communicate with the given host on the given port

Definition at line 394 of file httpclient.c.

References cp_client_create(), and cp_httpclient_destroy().

CPROPS_DLL cp_httpclient* cp_httpclient_create_proxy ( char *  host,
int  port,
char *  proxy_host,
int  proxy_port 
)

create an http client wrapper to communicate with the given host on the given port using the given proxy settings

Definition at line 410 of file httpclient.c.

References cp_client_create(), and cp_httpclient_destroy().

CPROPS_DLL cp_httpclient_ctl* cp_httpclient_ctl_create ( int  background  ) 

create an asynchronous client transfer block for separate transfers. if background is 0, transfers must be driven by calling cp_httpclient_fetch_ctl_exec(). If background is 1, transfers will be run on a separate thread. If background is greater than 1, a thread pool is created to perform background transfers and the given value is used as the maximal size of the thread pool.

Definition at line 2137 of file httpclient.c.

References cp_hash_addr(), cp_hash_compare_addr(), cp_hashlist_create, cp_httpclient_ctl_destroy(), and cp_thread_pool_create().

Referenced by cp_httpclient_init().

CPROPS_DLL fd_set* cp_httpclient_ctl_default_get_read_fd_set ( int *  num  ) 

retrieve a read file descriptor set for select() for the default transfer control block. If num is non-null it is set to the number of entries in the file descriptor array.

Definition at line 2222 of file httpclient.c.

References cp_httpclient_ctl_get_read_fd_set().

CPROPS_DLL fd_set* cp_httpclient_ctl_default_get_write_fd_set ( int *  num  ) 

retrieve a write file descriptor set for select() for the default transfer control block. If num is non-null it is set to the number of entries in the file descriptor array.

Definition at line 2234 of file httpclient.c.

References cp_httpclient_ctl_get_write_fd_set().

CPROPS_DLL void cp_httpclient_ctl_destroy ( cp_httpclient_ctl ctl  ) 

transfer blocks created with cp_httpclient_ctl_create() are not released by the framework and must be finalized by calling cp_httpclient_ctl_destroy().

Definition at line 2177 of file httpclient.c.

References cp_hashlist_destroy_custom(), cp_http_transfer_descriptor_destroy(), cp_thread_pool_destroy(), and cp_thread_pool_stop().

Referenced by cp_httpclient_ctl_create(), and cp_httpclient_shutdown().

CPROPS_DLL fd_set* cp_httpclient_ctl_get_read_fd_set ( cp_httpclient_ctl ctl,
int *  num 
)

retrieve a read file descriptor set prepared for select(). If num is non- null it is set to the number of entries in the file descriptor array.

Definition at line 2227 of file httpclient.c.

Referenced by cp_httpclient_ctl_default_get_read_fd_set().

CPROPS_DLL fd_set* cp_httpclient_ctl_get_write_fd_set ( cp_httpclient_ctl ctl,
int *  num 
)

retrieve a write file descriptor set prepared for select(). If num is non- null it is set to the number of entries in the file descriptor array.

Definition at line 2239 of file httpclient.c.

Referenced by cp_httpclient_ctl_default_get_write_fd_set().

CPROPS_DLL void cp_httpclient_destroy ( cp_httpclient client  ) 

deallocate a cp_httpclient wrapper.

Definition at line 478 of file httpclient.c.

References cp_client_close(), cp_client_destroy(), and cp_hashtable_destroy().

Referenced by cp_httpclient_create(), and cp_httpclient_create_proxy().

CPROPS_DLL void cp_httpclient_drop_headers ( cp_httpclient client  ) 

deallocate cgi parameters

Definition at line 516 of file httpclient.c.

References cp_hashtable_remove_all().

Referenced by cp_http_transfer_descriptor_destroy(), and cp_httpclient_fetch().

CPROPS_DLL void cp_httpclient_drop_parameters ( cp_httpclient client  ) 

deallocate cgi parameters

Definition at line 614 of file httpclient.c.

References cp_hashtable_remove_all().

Referenced by cp_http_transfer_descriptor_destroy(), and cp_httpclient_fetch().

CPROPS_DLL cp_httpclient_result* cp_httpclient_fetch ( cp_httpclient client,
char *  uri 
)

read uri content - synchronous interface

Definition at line 1390 of file httpclient.c.

References cp_client_reopen(), cp_client_write_string(), cp_hashtable_get(), cp_http_response_delete(), cp_httpclient_drop_headers(), cp_httpclient_drop_parameters(), cp_httpclient_result_create(), cp_string, cp_string_destroy(), cp_url_descriptor_destroy(), and cp_url_descriptor_parse().

CPROPS_DLL int cp_httpclient_fetch_ctl ( cp_httpclient_ctl ctl,
cp_httpclient client,
char *  uri,
void *  id,
cp_httpclient_callback  callback 
)

same as cp_httpclient_fetch_nb but allows specifying a different asynchronous transfer control block.

Definition at line 2312 of file httpclient.c.

References cp_hashlist_append(), and cp_http_transfer_descriptor_create().

Referenced by cp_httpclient_fetch_nb().

CPROPS_DLL int cp_httpclient_fetch_ctl_exec ( cp_httpclient_ctl ctl  ) 

same as cp_httpclient_fetch_nb_exec() but allows specifying a different aysnchronous transfer control block.

Definition at line 2099 of file httpclient.c.

References cp_error(), cp_hashlist_item_count(), and CP_MEMORY_ALLOCATION_FAILURE.

Referenced by cp_httpclient_fetch_nb_exec().

CPROPS_DLL int cp_httpclient_fetch_nb ( cp_httpclient client,
char *  uri,
void *  id,
cp_httpclient_callback  callback,
int  background 
)

perform an asynchronous fetch. If background is non-zero, the fetch happens in a separate thread and the callback is invoked asynchronously. Otherwise the caller must make repeated calls to cp_httpclient_fetch_nb_exec() until all transfers complete. cp_httpclient_fetch_nb_next() returns the number of active transfers. cp_httpclient_fetch_nb returns zero if the request could be registered, non-zero otherwise.

Definition at line 2302 of file httpclient.c.

References cp_httpclient_fetch_ctl().

CPROPS_DLL int cp_httpclient_fetch_nb_exec (  ) 

non-blocking fetches executing in the foreground must be driven by calls to cp_httpclient_fetch_nb_exec(). The callback for each request is made once it completes or if an error occurs. cp_httplcient_fetch_nb_exec() returns the number of active requests. Zero indicates all transfers have completed.

Definition at line 2094 of file httpclient.c.

References cp_httpclient_fetch_ctl_exec().

__BEGIN_DECLS CPROPS_DLL int cp_httpclient_init (  ) 

api initialization function

Definition at line 91 of file httpclient.c.

References COLLECTION_MODE_DEEP, cp_client_init(), cp_error(), cp_httpclient_ctl_create(), CP_MEMORY_ALLOCATION_FAILURE, cp_trie_create_trie(), and cp_trie_destroy().

CPROPS_DLL int cp_httpclient_reopen ( cp_httpclient client,
char *  host,
int  port 
)

use the same wrapper for a different address. this will close an existing connection, change the host and port settings on the wrapper and attempt to connect. maybe rename this function.

Definition at line 1505 of file httpclient.c.

References cp_client_reopen().

CPROPS_DLL cp_httpclient_result* cp_httpclient_result_create ( cp_httpclient client  ) 

(internal) create a cp_httpclient_result object

Definition at line 1546 of file httpclient.c.

Referenced by cp_httpclient_fetch().

CPROPS_DLL void cp_httpclient_result_destroy ( cp_httpclient_result res  ) 

destructor for cp_httpclient_result objects

Definition at line 1573 of file httpclient.c.

References cp_http_response_delete().

CPROPS_DLL cp_httpclient* cp_httpclient_result_get_client ( cp_httpclient_result res  ) 

get the client object the response was made on

Definition at line 1597 of file httpclient.c.

CPROPS_DLL cp_http_response* cp_httpclient_result_get_response ( cp_httpclient_result res  ) 

get the response object from a result descriptor

Definition at line 1592 of file httpclient.c.

CPROPS_DLL void* cp_httpclient_result_id ( cp_httpclient_result res  ) 

get the client assigned id from a result descriptor

Definition at line 1582 of file httpclient.c.

CPROPS_DLL cp_http_result_status cp_httpclient_result_status ( cp_httpclient_result res  ) 

get the result status code from a result descriptor

Definition at line 1587 of file httpclient.c.

CPROPS_DLL void cp_httpclient_set_auto_drop_headers ( cp_httpclient client,
short  mode 
)

determine whether headers are automatically deleted or not - disabled by default

Definition at line 521 of file httpclient.c.

CPROPS_DLL void cp_httpclient_set_auto_drop_parameters ( cp_httpclient client,
short  mode 
)

determine whether cgi parameters are automatically deleted or not - enabled by default

Definition at line 619 of file httpclient.c.

CPROPS_DLL void cp_httpclient_set_header ( cp_httpclient client,
char *  header,
char *  value 
)

set an arbitrary header. Any existing value is overriden.

Definition at line 508 of file httpclient.c.

References cp_hashtable_put(), and cp_hashtable_remove().

CPROPS_DLL void cp_httpclient_set_http_version ( cp_httpclient client,
cp_http_version  version 
)

set the HTTP version for subsequent requests

Definition at line 496 of file httpclient.c.

CPROPS_DLL void cp_httpclient_set_max_redirects ( cp_httpclient client,
int  max 
)

maximal number of server redirect directives to follow - default is 10

Definition at line 547 of file httpclient.c.

CPROPS_DLL void* cp_httpclient_set_parameter ( cp_httpclient client,
char *  name,
char *  value 
)

set a cgi parameter

Definition at line 587 of file httpclient.c.

References COLLECTION_MODE_COPY, COLLECTION_MODE_DEEP, COLLECTION_MODE_NOSYNC, cp_hash_compare_string(), cp_hash_string(), cp_hashtable_create_by_option(), cp_hashtable_put(), and cp_hashtable_remove().

CPROPS_DLL void cp_httpclient_set_request_type ( cp_httpclient client,
cp_http_request_type  type 
)

set the request type for subsequent requests. GET by default.

Definition at line 502 of file httpclient.c.

CPROPS_DLL void cp_httpclient_set_retry ( cp_httpclient client,
int  retry_count 
)

set the number of times to retry a connection on failure

Definition at line 537 of file httpclient.c.

References cp_client_set_retry().

CPROPS_DLL void cp_httpclient_set_timeout ( cp_httpclient client,
int  sec,
int  usec 
)

set the timeout value for the underlying tcp socket

Definition at line 531 of file httpclient.c.

References cp_client_set_timeout().

CPROPS_DLL void cp_httpclient_set_user_agent ( cp_httpclient client,
char *  agent 
)

set a value for the 'User-Agent' header. Default is libcprops-(version)

Definition at line 526 of file httpclient.c.

References cp_hashtable_put().

CPROPS_DLL int cp_httpclient_shutdown (  ) 

api cleanup function

Definition at line 152 of file httpclient.c.

References cp_client_shutdown(), cp_httpclient_ctl_destroy(), cp_socket_shutdown(), and cp_trie_destroy().

CPROPS_DLL void * cp_httpsocket_add_shutdown_callback ( cp_httpsocket socket,
void(*)(void *)  cb,
void *  prm 
)

called when closing a socket

Definition at line 1613 of file http.c.

References cp_socket_add_shutdown_callback().

CPROPS_DLL cp_httpsocket * cp_httpsocket_create ( int  port,
cp_http_service_callback  default_service 
)

create a cp_http_socket with the specified default cp_http_service

Definition at line 1486 of file http.c.

References cp_error(), cp_hashlist_append(), cp_http_init(), cp_http_thread_fn(), cp_httpsocket_set_keepalive(), CP_MEMORY_ALLOCATION_FAILURE, cp_socket_create(), cp_socket_delete(), cp_socket_set_owner(), and HTTP_KEEPALIVE.

CPROPS_DLL void cp_httpsocket_delete ( cp_httpsocket svc  ) 

deallocate a cp_httpsocket structure

Definition at line 1590 of file http.c.

References cp_hashlist_destroy_custom(), cp_hashlist_destroy_deep(), cp_hashlist_remove(), cp_http_response_delete(), cp_socket_delete(), and cp_trie_destroy().

CPROPS_DLL int cp_httpsocket_listen ( cp_httpsocket sock  ) 

puts socket in listening mode

Definition at line 1620 of file http.c.

References cp_socket_listen(), and cp_socket_select().

CPROPS_DLL int cp_httpsocket_register_service ( cp_httpsocket server,
cp_http_service service 
)

register a service on a socket

Definition at line 1630 of file http.c.

References COLLECTION_MODE_DEEP, cp_http_service_delete(), cp_trie_add(), and cp_trie_create_trie().

CPROPS_DLL void cp_httpsocket_set_backlog ( cp_httpsocket socket,
int  backlog 
)

set maximal number of queued requests before accept() starts refusing connections

Definition at line 1560 of file http.c.

References cp_socket_set_backlog().

CPROPS_DLL void cp_httpsocket_set_delay ( cp_httpsocket socket,
struct timeval  delay 
)

set time to block in accept

Definition at line 1565 of file http.c.

References cp_socket_set_delay().

CPROPS_DLL void cp_httpsocket_set_delay_usec ( cp_httpsocket socket,
long  usec 
)

set micro sec. to block in accept()

Definition at line 1575 of file http.c.

References cp_socket_set_delay_usec().

CPROPS_DLL void cp_httpsocket_set_keepalive ( cp_httpsocket socket,
int  sec 
)

set value for Keep-Alive header

Definition at line 1550 of file http.c.

Referenced by cp_httpsocket_create().

CPROPS_DLL void cp_httpsocket_set_poolsize_max ( cp_httpsocket socket,
int  max 
)

set upper limit on thread pool size

Definition at line 1585 of file http.c.

References cp_socket_set_poolsize_max().

CPROPS_DLL void cp_httpsocket_set_poolsize_min ( cp_httpsocket socket,
int  min 
)

set lower limit on thread pool size

Definition at line 1580 of file http.c.

References cp_socket_set_poolsize_min().

CPROPS_DLL void cp_httpsocket_set_server_name ( cp_httpsocket socket,
char *  name 
)

set value for Server header

Definition at line 1555 of file http.c.

CPROPS_DLL void * cp_httpsocket_unregister_service ( cp_httpsocket server,
cp_http_service service 
)

unregister a service on a socket

Definition at line 1649 of file http.c.

References cp_trie_remove().

CPROPS_DLL void * cp_socket_add_shutdown_callback ( cp_socket sock,
void(*)(void *)  cb,
void *  prm 
)

add a callback to be made on socket shutdown

Definition at line 552 of file socket.c.

Referenced by cp_httpsocket_add_shutdown_callback().

CPROPS_DLL int cp_socket_connection_close ( cp_socket sock,
int  fd 
)

close a (non ssl) connection

Definition at line 1065 of file socket.c.

References cp_hashlist_get(), cp_hashlist_remove_deep(), CP_IO_ERROR, cp_perror(), and DEBUGMSG.

Referenced by cp_connection_descriptor_destroy(), and cp_socket_delete().

CPROPS_DLL cp_socket * cp_socket_create ( int  port,
cp_socket_strategy  strategy,
void *  fn 
)

create a new cp_socket struct

Definition at line 443 of file socket.c.

References COLLECTION_MODE_DEEP, cp_error(), cp_hash_compare_int(), cp_hash_int(), cp_hashlist_append(), cp_hashlist_create_by_option(), CP_MEMORY_ALLOCATION_FAILURE, cp_socket_init(), CPSOCKET_DEFAULT_BACKLOG, CPSOCKET_DEFAULT_DELAY_SEC, CPSOCKET_DEFAULT_DELAY_USEC, CPSOCKET_THREADPOOL_DEFAULT_SIZE_MAX, and CPSOCKET_THREADPOOL_DEFAULT_SIZE_MIN.

Referenced by cp_httpsocket_create().

CPROPS_DLL void cp_socket_delete ( cp_socket sock  ) 

deallocate a socket descriptor

Definition at line 564 of file socket.c.

References COLLECTION_LOCK_NONE, cp_hashlist_create_iterator(), cp_hashlist_destroy_custom(), cp_hashlist_entry_get_key(), cp_hashlist_iterator_destroy(), cp_hashlist_iterator_next(), cp_hashlist_remove(), cp_socket_connection_close(), cp_thread_pool_destroy(), and cp_thread_pool_stop().

Referenced by cp_httpsocket_create(), and cp_httpsocket_delete().

CPROPS_DLL void cp_socket_init (  ) 

recommended to call before using socket functions

Definition at line 198 of file socket.c.

References COLLECTION_MODE_DEEP, cp_hash_compare_int(), cp_hash_int(), and cp_hashlist_create_by_mode().

Referenced by cp_client_init(), cp_http_init(), and cp_socket_create().

CPROPS_DLL int cp_socket_listen ( cp_socket sock  ) 

cp_socket_listen attempts to create a SOCK_STREAM socket with socket(), bind to a local port with bind(), and set the socket to listen for connections with listen().

Definition at line 616 of file socket.c.

References CP_IO_ERROR, cp_perror(), cp_thread_pool_create(), and DEBUGMSG.

Referenced by cp_httpsocket_listen().

CPROPS_DLL int cp_socket_select ( cp_socket sock  ) 

block and wait for connections

Definition at line 997 of file socket.c.

References cp_socket_select_callback_impl(), and cp_socket_select_threadpool_impl().

Referenced by cp_httpsocket_listen().

CPROPS_DLL void cp_socket_set_backlog ( cp_socket socket,
int  backlog 
)

set number of outstanding requests before accept() fails new connections

Definition at line 517 of file socket.c.

Referenced by cp_httpsocket_set_backlog().

CPROPS_DLL void cp_socket_set_delay ( cp_socket socket,
struct timeval  delay 
)

delay time before re-accept()ing

Definition at line 522 of file socket.c.

Referenced by cp_httpsocket_set_delay().

CPROPS_DLL void cp_socket_set_delay_sec ( cp_socket socket,
long  sec 
)

seconds before re-accept()ing

Definition at line 527 of file socket.c.

Referenced by cp_httpsocket_set_delay_sec().

CPROPS_DLL void cp_socket_set_delay_usec ( cp_socket socket,
long  usec 
)

microseconds before re-accept()ing

Definition at line 532 of file socket.c.

Referenced by cp_httpsocket_set_delay_usec().

CPROPS_DLL void cp_socket_set_owner ( cp_socket socket,
void *  owner 
)

useful free pointer for client code

Definition at line 547 of file socket.c.

Referenced by cp_httpsocket_create().

CPROPS_DLL void cp_socket_set_poolsize_max ( cp_socket socket,
int  max 
)

upper size limit for threadpool implementation

Definition at line 542 of file socket.c.

Referenced by cp_httpsocket_set_poolsize_max().

CPROPS_DLL void cp_socket_set_poolsize_min ( cp_socket socket,
int  min 
)

lower size limit for threadpool implementation

Definition at line 537 of file socket.c.

Referenced by cp_httpsocket_set_poolsize_min().

CPROPS_DLL void cp_socket_shutdown (  ) 

performs cleanup

Definition at line 287 of file socket.c.

References cp_hashlist_destroy(), cp_socket_stop_all(), and DEBUGMSG.

Referenced by cp_client_shutdown(), cp_http_shutdown(), and cp_httpclient_shutdown().

CPROPS_DLL void cp_socket_stop_all (  ) 

call from signal handler to stop sockets in waiting select() and close all connections

Definition at line 271 of file socket.c.

References COLLECTION_LOCK_READ, cp_hashlist_iterator_init(), cp_hashlist_iterator_next_value(), cp_hashlist_iterator_release(), and cp_socket_stop().

Referenced by cp_httpsocket_stop_all(), and cp_socket_shutdown().

CPROPS_DLL void cp_tcp_add_shutdown_callback ( void(*)(void *)  cb,
void *  prm 
)

add callback to be made on tcp layer shutdown

Definition at line 257 of file socket.c.


Variable Documentation

__BEGIN_DECLS { ... } cp_http_request_type

HTTP request types


Generated on Mon Dec 5 23:00:22 2011 for cprops by  doxygen 1.4.7