#include "ks_config.h"
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/select.h>
#include "ks_socket.h"
#include "ks_malloc.h"
Go to the source code of this file.
Data Structures | |
| struct | _ks_socket_t |
Defines | |
| #define | RECV_SIZE 65536 |
| #define | MSECS 1000 |
| #define | USECS 1000000 |
| #define | NSECS 1000000000 |
| #define | QUEUE_SIZE_MAX 64 |
Functions | |
| void | ks_socket_set_auth (ks_socket_t *s, const char *principal, const char *credentials) |
| ks_socket_t * | ks_socket_new (const char *hostname, const char *port, int proto) |
| void | ks_socket_free (ks_socket_t *k) |
| int | ks_socket_connect (ks_socket_t *k) |
| void | ks_socket_close (ks_socket_t *k) |
| ssize_t | ks_socket_send (ks_socket_t *k, ks_bquery_t *q) |
| ks_response_t * | ks_socket_recv (ks_socket_t *k, ks_string_t *id, int timeout) |
| ks_response_t * | ks_socket_ask (ks_socket_t *k, ks_bquery_t *q, int timeout) |
A threadsafe socket implementation including caching responses and returning responses from the cache if they've already been received.
Definition in file ks_socket_posix.c.
|
|
Definition at line 103 of file ks_socket_posix.c. Referenced by ks_socket_recv(). |
|
|
Definition at line 105 of file ks_socket_posix.c. Referenced by ks_socket_recv(). |
|
|
Definition at line 169 of file ks_socket_posix.c. |
|
|
Definition at line 38 of file ks_socket_posix.c. |
|
|
Definition at line 104 of file ks_socket_posix.c. Referenced by ks_socket_recv(). |
|
||||||||||||||||
|
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.
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(). |
|
|
Close a connected socket, if it is connected.
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(). |
|
|
Connect a ks_socket_t. This looks up the hostname and port to connect to, and connects a new socket to the address.
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(). |
|
|
Destroy a given ks_socket_t, close it if it's open and free any associated allocated memory.
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(). |
|
||||||||||||||||
|
Create a new ks_socket_t to connect to hostname:port using proto.
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(). |
|
||||||||||||||||
|
A threadsafe implementation to retrieve a response with a specific id from the socket.
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(). |
|
||||||||||||
|
Send ks_bquery_t (q) over ks_socket_t (k).
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(). |
|
||||||||||||||||
|
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(). |
1.4.4