#include <LogSock.h>
Data Structures | |
struct | ConnectTable |
struct | MsgHeader |
Public Types | |
enum | Constant { LS_CONST_PACKETSIZE = 1024, LS_CONST_CLUSTER_MAX_MACHINES = 256 } |
enum | Err { LS_ERROR_UNKNOWN = -1, LS_ERROR_CONNECT_TABLE_FULL = -3, LS_ERROR_SOCKET = -4, LS_ERROR_BIND = -5, LS_ERROR_CONNECT = -6, LS_ERROR_ACCEPT = -7, LS_ERROR_NO_SUCH_HOST = -8, LS_ERROR_NO_CONNECTION = -9, LS_ERROR_STATE = -10, LS_ERROR_WRITE = -11, LS_ERROR_READ = -12 } |
enum | State { LS_STATE_UNUSED = 0, LS_STATE_INCOMING, LS_STATE_OUTGOING, LS_N_STATES } |
Public Member Functions | |
LogSock (int max_connects=1) | |
LogSock. | |
~LogSock () | |
LogSock::~LogSock. | |
bool | pending_any (int *cid, int timeout_msec=0) |
LogSock::pending_any. | |
bool | pending_message_any (int *cid, int timeout_msec=0) |
bool | pending_message_on (int cid, int timeout_msec=0) |
LogSock::pending_message_on. | |
bool | pending_connect (int timeout_msec=0) |
LogSock::pending_connect. | |
int | listen (int accept_port, int family=AF_INET) |
LogSock::listen. | |
int | accept () |
LogSock::accept. | |
int | connect (sockaddr const *ip) |
LogSock::connect. | |
void | close (int cid) |
LogSock::close. | |
void | close () |
int | write (int cid, void *buf, int bytes) |
LogSock::write. | |
int | read (int cid, void *buf, unsigned maxsize) |
LogSock::read. | |
void * | read_alloc (int cid, int *size) |
LogSock::read_alloc. | |
char * | on_host () |
int | on_port () |
bool | is_connected (int cid, bool ping=false) const |
void | check_connections () |
bool | authorized_client (int cid, char *key) |
This routine will check to ensure that the client connecting is authorized to use the log collation port. | |
char * | connected_host (int cid) |
int | connected_port (int cid) |
Definition at line 38 of file LogSock.h.
enum LogSock::Constant |
enum LogSock::Err |
enum LogSock::State |
LogSock::LogSock | ( | int | max_connects = 1 |
) |
The constructor establishes the connection table (ct) and initializes the first entry of the table (index 0) to be the port on which new connections are accepted.
Definition at line 40 of file LogSock.cc.
References Debug, ink_assert, and LS_STATE_UNUSED.
LogSock::~LogSock | ( | ) |
Shut down all connections and delete memory for the tables.
Definition at line 65 of file LogSock.cc.
int LogSock::accept | ( | ) |
Accept a new connection. This is a blocking operation, so you may want to use one of the non-blocking pending_XXX calls to see if there is a connection first.
Definition at line 192 of file LogSock.cc.
References Debug, LS_STATE_INCOMING, IpEndpoint::port(), and IpEndpoint::sa.
Referenced by Log::collate_thread_main().
bool LogSock::authorized_client | ( | int | cid, | |
char * | key | |||
) |
This routine will check to ensure that the client connecting is authorized to use the log collation port.
To authorize, the client is expected to send the logging secret string.
Definition at line 615 of file LogSock.cc.
References ink_assert, pending_message_on(), and read().
Referenced by Log::collate_thread_main().
void LogSock::check_connections | ( | ) |
Definition at line 598 of file LogSock.cc.
References close(), Debug, is_connected(), and LS_STATE_INCOMING.
Referenced by Log::collate_thread_main().
void LogSock::close | ( | int | cid | ) |
Close one (cid specified) or all (no argument) sockets, except for the incomming connection socket.
Definition at line 435 of file LogSock.cc.
References close(), Debug, ink_assert, and LS_STATE_UNUSED.
Referenced by Log::collate_thread_main(), and LogHost::disconnect().
void LogSock::close | ( | ) |
Definition at line 449 of file LogSock.cc.
Referenced by check_connections(), close(), and ~LogSock().
int LogSock::connect | ( | sockaddr const * | ip | ) |
Establish a new connection to another machine [host:port], and place this information into the connection and poll tables.
Definition at line 230 of file LogSock.cc.
References ats_ip_nptop(), ats_ip_port_cast(), ats_ip_size(), ats_is_ip(), Debug, LS_PROTOCOL, LS_SOCKTYPE, LS_STATE_OUTGOING, Note, safe_setsockopt(), and SOCKOPT_ON.
Referenced by LogHost::connect().
char * LogSock::connected_host | ( | int | cid | ) |
Definition at line 643 of file LogSock.cc.
References ink_assert.
int LogSock::connected_port | ( | int | cid | ) |
Definition at line 652 of file LogSock.cc.
References ink_assert.
bool LogSock::is_connected | ( | int | cid, | |
bool | ping = false | |||
) | const |
Definition at line 567 of file LogSock.cc.
References ink_assert, and LS_STATE_UNUSED.
Referenced by check_connections(), and LogHost::connected().
int LogSock::listen | ( | int | accept_port, | |
int | family = AF_INET | |||
) |
This routine sets up the LogSock to begin accepting connections on the given
accept | port. A maximum number of connections is also specified, which is used to establish the size of the listen queue. |
zero if all goes well, -1 otherwise.
Definition at line 84 of file LogSock.cc.
References ats_ip_size(), Debug, IpEndpoint::isValid(), LS_PROTOCOL, LS_SOCKTYPE, LS_STATE_INCOMING, IpEndpoint::port(), IpEndpoint::sa, safe_bind(), safe_fcntl(), safe_getsockname(), safe_listen(), safe_setsockopt(), IpEndpoint::setToAnyAddr(), SOCKOPT_ON, and Warning.
Referenced by Log::collate_thread_main().
bool LogSock::pending_any | ( | int * | cid, | |
int | timeout_msec = 0 | |||
) |
Check for incomming data on any of the INCOMING sockets.
Definition at line 376 of file LogSock.cc.
References ink_assert.
bool LogSock::pending_connect | ( | int | timeout_msec = 0 |
) |
Check for an incoming connection request on the socket reserved for that (cid = 0).
Definition at line 417 of file LogSock.cc.
Referenced by Log::collate_thread_main().
bool LogSock::pending_message_any | ( | int * | cid, | |
int | timeout_msec = 0 | |||
) |
Definition at line 394 of file LogSock.cc.
References ink_assert.
Referenced by Log::collate_thread_main().
bool LogSock::pending_message_on | ( | int | cid, | |
int | timeout_msec = 0 | |||
) |
Check for incomming data on the specified socket.
Definition at line 406 of file LogSock.cc.
Referenced by authorized_client().
int LogSock::read | ( | int | cid, | |
void * | buf, | |||
unsigned | maxsize | |||
) |
Read data from the specified connection. This is a blocking call, so you may want to use one of the pending_XXX calls to see if there is anything to read first. Returns number of bytes read.
Definition at line 506 of file LogSock.cc.
References Debug, ink_assert, and LS_STATE_INCOMING.
Referenced by authorized_client().
void * LogSock::read_alloc | ( | int | cid, | |
int * | size | |||
) |
This routine reads data from the specified connection, and returns a pointer to newly allocated space (allocated with new) containing the data. The number of bytes read is set in the argument size, which is expected to be a pointer to an int.
Definition at line 537 of file LogSock.cc.
References Debug, ink_assert, and LS_STATE_INCOMING.
Referenced by Log::collate_thread_main().
int LogSock::write | ( | int | cid, | |
void * | buf, | |||
int | bytes | |||
) |
Write data onto the socket corresponding to the given cid. Return the number of bytes actually written.
Definition at line 463 of file LogSock.cc.
References Debug, ink_assert, and LS_STATE_OUTGOING.