ddc
|
#include "utilit.h"
#include "ddcLog.h"
#include <pthread.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <stdio.h>
#include <fcntl.h>
Go to the source code of this file.
Classes | |
struct | CSocketAddr |
Macros | |
#define | SOCKET int |
#define | SOCKET int |
Enumerations | |
enum | NetworkErrorsEnum { neSuccess = 0, neNetworkError = 1, neTimeout = 2, neProtocolError = 3, neSubcorpusNotFound = 4, neInternalReadAccessError = 5, neCouldNotOpenSocket = 6, neCouldNotSendData = 7, neCouldNotReceiveData = 8, neInternalError = 9, neRequestTooLarge = 10 } |
enum | SocketTypeEnum { stUnknown = 0, stINET = 1, stUNIX = 2 } |
enum for socket schemes More... | |
Functions | |
uint32_t | size_to_lsb (uint32_t sz) |
uint32_t | lsb_to_size (uint32_t sz_lsb) |
int | create_socket (const CSocketAddr &Addr, bool bBind, mode_t bindPerms, string &strError) |
int | create_inet_socket (const char *HostAddr, int Port, bool bBind, string &strError) |
int | create_unix_socket (const string &socket_path, bool bBind, mode_t bindPerms, string &strError) |
int | create_socket (const char *HostAddr, int Port, bool bBind, string &strError) |
void | flush_socket (int sock) |
bool | SocketInitialize (bool bReadFromLocalFile) |
bool | SocketDeinitialize () |
bool | CloseSocket (int l_socket, bool linger=false, int timeout=5) |
bool | CloseSocketRef (int &rConnectedSocket, bool linger=false, int timeout=5) |
string | GetNetworkErrorString (const NetworkErrorsEnum &t) |
void | SocketPeer (int sock, string &PeerAddr, int &PeerPort) |
string | SocketPeer (int sock) |
bool | SendString (int client_fd, const char *Str, uint32_t StrLen, string &ErrorStr) |
bool | SendString (int client_fd, const std::string &str, string &ErrorStr) |
NetworkErrorsEnum | receive_buffer (int client_fd, char *Buffer, int Length, int &have_read, int TimeOut) |
NetworkErrorsEnum | ReceiveString (int client_fd, string &Result, int TimeOut, uint32_t maxPacketLength=0) |
Variables | |
const int | ddcSocketChunkSize |
#define SOCKET int |
Referenced by CHost::ClientError(), create_inet_socket(), create_unix_socket(), CDDCBranchServer::GetSubcorpusJsonStrings(), CHost::IsListening(), CSocketAddr::operator bool(), CHost::RunThread(), CDDCBranchServer::SendGetHitStringsRequest(), CDDCServer::UseClientThreads(), CDDCLeafServer::WorkerClone(), and CDDCBranchServer::WorkerClone().
#define SOCKET int |
enum NetworkErrorsEnum |
enum SocketTypeEnum |
uint32_t size_to_lsb | ( | uint32_t | sz | ) |
Referenced by CSocketAddr::operator bool(), and SendString().
uint32_t lsb_to_size | ( | uint32_t | sz_lsb | ) |
Referenced by CSocketAddr::operator bool(), and ReceiveString().
int create_socket | ( | const CSocketAddr & | Addr, |
bool | bBind, | ||
mode_t | bindPerms, | ||
string & | strError | ||
) |
References create_inet_socket(), create_unix_socket(), CSocketAddr::m_Addr, CSocketAddr::m_Port, CSocketAddr::m_Type, stINET, and stUNIX.
Referenced by CSocketAddr::operator bool().
int create_inet_socket | ( | const char * | HostAddr, |
int | Port, | ||
bool | bBind, | ||
string & | strError | ||
) |
References CloseSocket(), CloseSocketRef(), errRuntime, FDDEBUG, Format(), SOCKET, and StrError().
Referenced by create_socket(), CHost::CreateSocket(), and CSocketAddr::operator bool().
int create_unix_socket | ( | const string & | socket_path, |
bool | bBind, | ||
mode_t | bindPerms, | ||
string & | strError | ||
) |
References CloseSocketRef(), ddcLogWarn, errRuntime, Format(), SOCKET, and StrError().
Referenced by create_socket(), CHost::CreateSocket(), and CSocketAddr::operator bool().
int create_socket | ( | const char * | HostAddr, |
int | Port, | ||
bool | bBind, | ||
string & | strError | ||
) |
void flush_socket | ( | int | sock | ) |
bool SocketInitialize | ( | bool | bReadFromLocalFile | ) |
Referenced by do_start(), ListenerThread(), and CSocketAddr::operator bool().
bool SocketDeinitialize | ( | ) |
Referenced by do_start(), ListenerThread(), main(), CSocketAddr::operator bool(), puke(), and UnloadData().
bool CloseSocket | ( | int | l_socket, |
bool | linger = false , |
||
int | timeout = 5 |
||
) |
close a socket; if linger is true, SO_LINGER option will be set for timeout second(s)
References FDDEBUG.
Referenced by CloseSocketRef(), CFirstHitsQueryResult::CloseSockets(), create_inet_socket(), and CSocketAddr::operator bool().
bool CloseSocketRef | ( | int & | rConnectedSocket, |
bool | linger = false , |
||
int | timeout = 5 |
||
) |
wrapper for CloseSocket() on a reference
References CloseSocket(), ddcLogTrace, and Format().
Referenced by CHost::Close(), create_inet_socket(), create_unix_socket(), and CSocketAddr::operator bool().
string GetNetworkErrorString | ( | const NetworkErrorsEnum & | t | ) |
References neCouldNotOpenSocket, neCouldNotReceiveData, neCouldNotSendData, neInternalError, neInternalReadAccessError, neNetworkError, neProtocolError, neRequestTooLarge, neSubcorpusNotFound, neSuccess, and neTimeout.
Referenced by CDDCBranchServer::CheckFirstHitsResult(), CDDCBranchServer::GetFirstHitsFromCorpora(), CHost::GetRequest(), CDDCBranchServer::handle__get_hit_strings(), and CSocketAddr::operator bool().
void SocketPeer | ( | int | sock, |
string & | PeerAddr, | ||
int & | PeerPort | ||
) |
References Format().
Referenced by CHost::GetRequest(), CHost::HandleClientConnection(), CDDCServer::HandleClientConnection(), CHost::HandleSocketError(), CSocketAddr::operator bool(), CHost::SendResponse(), and SocketPeer().
string SocketPeer | ( | int | sock | ) |
bool SendString | ( | int | client_fd, |
const char * | Str, | ||
uint32_t | StrLen, | ||
string & | ErrorStr | ||
) |
References send_buffer(), and size_to_lsb().
Referenced by CHost::ClientError(), CDDCBranchServer::CloseDtr(), CFirstHitsQueryResult::CloseSockets(), CDDCBranchServer::GetFirstHitsFromCorpora(), CDDCBranchServer::GetSubcorpusJsonStrings(), CDDCBranchServer::handle__expand_terms(), CSocketAddr::operator bool(), CDDCBranchServer::SendGetHitStringsRequest(), CHost::SendResponse(), and SendString().
bool SendString | ( | int | client_fd, |
const std::string & | str, | ||
string & | ErrorStr | ||
) |
NetworkErrorsEnum receive_buffer | ( | int | client_fd, |
char * | Buffer, | ||
int | Length, | ||
int & | have_read, | ||
int | TimeOut | ||
) |
References errOther, neSuccess, neTimeout, and StrError().
Referenced by CSocketAddr::operator bool(), and ReceiveString().
NetworkErrorsEnum ReceiveString | ( | int | client_fd, |
string & | Result, | ||
int | TimeOut, | ||
uint32_t | maxPacketLength = 0 |
||
) |
References ddcSocketChunkSize, lsb_to_size(), neRequestTooLarge, neSuccess, and receive_buffer().
Referenced by CDDCBranchServer::GetFirstHitsFromCorpora(), CDDCBranchServer::GetHitStringsFromOneCorpus(), CHost::GetRequest(), CDDCBranchServer::GetSubcorpusJsonStrings(), CDDCBranchServer::handle__expand_terms(), and CSocketAddr::operator bool().
const int ddcSocketChunkSize |
Referenced by ReceiveString().