Main Page | Data Structures | Directories | File List | Data Fields | Globals

ks_socket.h File Reference

Interface to the libkarmaclient socket type. More...

#include "ks_bquery.h"
#include "ks_response.h"
#include <sys/types.h>
#include <sys/socket.h>

Go to the source code of this file.

Defines

#define KS_TIMEOUT_DEFAULT   1000

Typedefs

typedef _ks_socket_t ks_socket_t
 libkarmaclient socket type.

Functions

ks_socket_tks_socket_new (const char *, const char *, int)
int ks_socket_connect (ks_socket_t *)
void ks_socket_close (ks_socket_t *)
ssize_t ks_socket_send (ks_socket_t *, ks_bquery_t *)
ks_response_tks_socket_recv (ks_socket_t *, ks_string_t *, int)
ks_response_tks_socket_ask (ks_socket_t *, ks_bquery_t *, int)
void ks_socket_free (ks_socket_t *)
void ks_socket_set_auth (ks_socket_t *, const char *, const char *)


Detailed Description

Interface to the libkarmaclient socket type.

Type and function declarations for the functions defined in ks_socket_posix.c. Do not include this file directly in your client. Instead, include the application header file, ks.h, which will include all the libkarmaclient header files for you.

Definition in file ks_socket.h.


Define Documentation

#define KS_TIMEOUT_DEFAULT   1000
 

The default query timeout, in milliseconds.

Definition at line 65 of file ks_socket.h.

Referenced by ks_socket_ask(), and ks_socket_recv().


Typedef Documentation

typedef struct _ks_socket_t ks_socket_t
 

libkarmaclient socket type.

Definition at line 53 of file ks_socket.h.


Function Documentation

ks_response_t* ks_socket_ask ks_socket_t k,
ks_bquery_t q,
int  timeout
 

A threadsafe implementation to retrieve a response to a specific query from the socket. It is important that the value returned by this function is tested for failure, as other functions that take the ks_response_t pointer as an argument will not test that it is not NULL before trying to dereference it.

This method makes at most 3 retries, doubling the timeout each time.

Parameters:
k A pointer to the ks_socket_t to retrieve the response from.
q A pointer to the ks_bquery_t to send to the socket.
timeout The timeout for each retry, in milliseconds.
Returns:
A pointer to a ks_response_t, or NULL on an error.

Definition at line 734 of file ks_socket_posix.c.

References ks_bquery_id_get(), ks_socket_recv(), ks_socket_send(), and KS_TIMEOUT_DEFAULT.

Referenced by main().

void ks_socket_close ks_socket_t k  ) 
 

Close a connected socket, if it is connected.

Parameters:
k A pointer to the ks_socket_t to close.
Returns:
Nothing.

Definition at line 390 of file ks_socket_posix.c.

References _ks_socket_t::socket.

Referenced by ks_socket_connect(), ks_socket_free(), and ks_socket_send().

int ks_socket_connect ks_socket_t k  ) 
 

Connect a ks_socket_t. This looks up the hostname and port to connect to, and connects a new socket to the address.

Parameters:
k A pointer to the ks_socket_t to connect.
Returns:
0 on success, non zero otherwise.

Definition at line 351 of file ks_socket_posix.c.

References _ks_socket_t::addr, ks_error(), ks_socket_close(), _ks_socket_t::proto, and _ks_socket_t::socket.

Referenced by ks_socket_send(), and main().

void ks_socket_free ks_socket_t k  ) 
 

Destroy a given ks_socket_t, close it if it's open and free any associated allocated memory.

Parameters:
k A pointer to the ks_socket_t to be destroyed.
Returns:
Nothing.

Definition at line 322 of file ks_socket_posix.c.

References _ks_socket_t::c_cache, _ks_socket_t::cache, _ks_socket_t::creds, _ks_socket_t::hostname, ks_array_fini(), ks_free(), ks_socket_close(), _ks_socket_t::m_cache, _ks_socket_t::m_recv, _ks_socket_t::m_send, _ks_socket_t::port, and _ks_socket_t::princ.

Referenced by main().

ks_socket_t* ks_socket_new const char *  hostname,
const char *  port,
int  proto
 

Create a new ks_socket_t to connect to hostname:port using proto.

Parameters:
hostname A NUL terminated string, which is the host to connect to.
port A NUL terminated string, which is the port to connect to.
proto The protocol number to use.
Returns:
A pointer to a new ks_socket_t on success, NULL otherwise.

Definition at line 275 of file ks_socket_posix.c.

References _ks_socket_t::c_cache, _ks_socket_t::cache, _ks_socket_t::creds, _ks_socket_t::hostname, ks_array_init(), ks_error(), ks_malloc(), KS_SLAVE_HOST_DEFAULT, KS_SLAVE_PORT_DEFAULT, _ks_socket_t::m_cache, _ks_socket_t::m_recv, _ks_socket_t::m_send, _ks_socket_t::port, _ks_socket_t::princ, _ks_socket_t::proto, and _ks_socket_t::socket.

Referenced by main().

ks_response_t* ks_socket_recv ks_socket_t k,
ks_string_t id,
int  timeout
 

A threadsafe implementation to retrieve a response with a specific id from the socket.

Parameters:
k A pointer to the ks_socket_t to retrieve the response from.
id The id of the response to retrieve.
timeout The timeout for the call, in milliseconds.
Returns:
A pointer to a ks_response_t, or NULL on an error.

Definition at line 648 of file ks_socket_posix.c.

References _ks_socket_t::c_cache, ks_error(), ks_response_id(), ks_string_equals(), KS_TIMEOUT_DEFAULT, _ks_socket_t::m_cache, _ks_socket_t::m_recv, MSECS, NSECS, and USECS.

Referenced by ks_socket_ask().

ssize_t ks_socket_send ks_socket_t k,
ks_bquery_t q
 

Send ks_bquery_t (q) over ks_socket_t (k).

Parameters:
k A pointer to the ks_socket_t to send the query to.
q A pointer to the ks_bquery_t to send to the socket.
Returns:
On success returns the number of characters sent, on error -1 is returned.

Definition at line 424 of file ks_socket_posix.c.

References _ks_socket_t::creds, ks_bquery_has_auth(), ks_bquery_packet(), ks_bquery_set_auth(), ks_error(), ks_free(), ks_malloc(), ks_socket_close(), ks_socket_connect(), ks_string_free(), ks_string_get(), ks_string_length(), _ks_socket_t::m_send, _ks_socket_t::princ, _ks_socket_t::proto, and _ks_socket_t::socket.

Referenced by ks_socket_ask().

void ks_socket_set_auth ks_socket_t ,
const char *  ,
const char * 
 

Definition at line 141 of file ks_socket_posix.c.

References _ks_socket_t::creds, ks_free(), ks_malloc(), and _ks_socket_t::princ.

Referenced by main().


Generated on Tue Aug 7 21:11:31 2007 for libkarmaclient by  doxygen 1.4.4