sockets.cpp File Reference


Detailed Description

Implementation of HydraNode Sockets API.

Definition in file sockets.cpp.

#include <hn/hnprec.h>
#include <hn/sockets.h>
#include <hn/log.h>
#include <stdexcept>
#include <sys/socket.h>
#include <sys/un.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>

Include dependency graph for sockets.cpp:

Go to the source code of this file.


Namespaces

namespace  Socket

Defines

#define MSG_NOSIGNAL   0
#define closesocket(socket)   ::close(socket)

Enumerations

enum  Socket_Errors {
  SOCK_EUNKNOWN = 0, SOCK_EINETDOWN = -1, SOCK_ECONNREFUSED = ECONNREFUSED, SOCK_EWOULDBLOCK = EWOULDBLOCK,
  SOCK_EWINSOCK = -2, SOCK_EINVALIDSOCKET = ENOTSOCK, SOCK_ECONNRESET = ECONNRESET, SOCK_ECONNFAILED = ECONNREFUSED,
  SOCK_EACCESS = EACCES, SOCK_EPERM = EPERM, SOCK_EADDRINUSE = EADDRINUSE, SOCK_EADDRNOTAVAIL = EADDRNOTAVAIL,
  SOCK_EINVALIDPARAM = EINVAL, SOCK_EINPROGRESS = EINPROGRESS, SOCK_EALREADYBOUND = SOCK_EADDRINUSE, SOCK_ETOOMANYCONN = EMFILE,
  SOCK_ENOTSOCK = ENOTSOCK, SOCK_EAGAIN = EAGAIN
}
 Socket error codes Define our internal socket error codes from platform-specific codes for simplicity. More...

Functions

static void initSockets ()
static void setNonBlocking (SOCKET s)
static void setReUsable (SOCKET s)
static std::string getErrorStr (int err)
static int getLastError ()
static std::string socketError (const std::string &msg)
 IMPLEMENT_EVENT_TABLE (SocketClient, SocketClient *, SocketEvent)
 IMPLEMENT_EVENT_TABLE (SocketServer, SocketServer *, SocketEvent)
 IMPLEMENT_EVENT_TABLE (UDPSocket, UDPSocket *, SocketEvent)

Variables

static const int INVALID_SOCKET = -1
static const int SOCKET_ERROR = -1
_Endl Endl
 Line ending object, similar to std::endl.

Define Documentation

#define closesocket socket   )     ::close(socket)
 

Definition at line 198 of file sockets.cpp.

Referenced by SocketServer::close(), SocketClient::close(), and UDPSocket::destroy().

#define MSG_NOSIGNAL   0
 

Definition at line 40 of file sockets.cpp.

Referenced by SocketWatcher::handleReadableSocket(), SocketClient::read(), UDPSocket::recv(), UDPSocket::send(), and SocketClient::write().


Enumeration Type Documentation

enum Socket_Errors
 

Socket error codes Define our internal socket error codes from platform-specific codes for simplicity.

If platform misses some of the errors - no prob, just assign some negative value to it.

Enumeration values:
SOCK_EUNKNOWN 
SOCK_EINETDOWN 
SOCK_ECONNREFUSED 
SOCK_EWOULDBLOCK 
SOCK_EWINSOCK 
SOCK_EINVALIDSOCKET 
SOCK_ECONNRESET 
SOCK_ECONNFAILED 
SOCK_EACCESS 
SOCK_EPERM 
SOCK_EADDRINUSE 
SOCK_EADDRNOTAVAIL 
SOCK_EINVALIDPARAM 
SOCK_EINPROGRESS 
SOCK_EALREADYBOUND 
SOCK_ETOOMANYCONN 
SOCK_ENOTSOCK 
SOCK_EAGAIN 

Definition at line 71 of file sockets.cpp.


Function Documentation

static std::string getErrorStr int  err  )  [static]
 

Definition at line 132 of file sockets.cpp.

References SOCK_EACCESS, SOCK_EADDRINUSE, SOCK_EADDRNOTAVAIL, SOCK_EALREADYBOUND, SOCK_ECONNREFUSED, SOCK_EINETDOWN, SOCK_EINPROGRESS, SOCK_EINVALIDPARAM, SOCK_ENOTSOCK, SOCK_ETOOMANYCONN, SOCK_EUNKNOWN, SOCK_EWINSOCK, and SOCK_EWOULDBLOCK.

Referenced by SocketWatcher::handleReadableSocket(), and socketError().

static int getLastError  )  [static]
 

Definition at line 184 of file sockets.cpp.

Referenced by SocketClient::connect(), SocketWatcher::handleReadableSocket(), SocketClient::read(), UDPSocket::recv(), UDPSocket::send(), socketError(), and SocketClient::write().

IMPLEMENT_EVENT_TABLE UDPSocket  ,
UDPSocket ,
SocketEvent 
 

IMPLEMENT_EVENT_TABLE SocketServer  ,
SocketServer ,
SocketEvent 
 

IMPLEMENT_EVENT_TABLE SocketClient  ,
SocketClient ,
SocketEvent 
 

static void initSockets  )  [static]
 

Definition at line 100 of file sockets.cpp.

Referenced by SocketClient::SocketClient(), SocketServer::SocketServer(), and UDPSocket::UDPSocket().

static void setNonBlocking SOCKET  s  )  [static]
 

Definition at line 112 of file sockets.cpp.

Referenced by SocketServer::accept(), SocketClient::connect(), SocketServer::SocketServer(), and UDPSocket::UDPSocket().

static void setReUsable SOCKET  s  )  [static]
 

Definition at line 121 of file sockets.cpp.

Referenced by SocketServer::SocketServer(), and UDPSocket::UDPSocket().

static std::string socketError const std::string &  msg  )  [static]
 

Definition at line 192 of file sockets.cpp.

References getErrorStr(), getLastError(), and logDebug().

Referenced by SocketServer::accept(), SocketServer::close(), SocketClient::close(), SocketClient::connect(), UDPSocket::destroy(), UDPSocket::listen(), SocketServer::listen(), UDPSocket::recv(), and UDPSocket::send().

Here is the call graph for this function:


Variable Documentation

DLLEXPORT class Socket::_Endl Socket::Endl
 

Line ending object, similar to std::endl.

When dealing with plain-text protocols over sockets,
is used to indicate newline. Usage:

 SocketClient *c;
 *c << "Message" << Socket::Endl;
 

const int INVALID_SOCKET = -1 [static]
 

Definition at line 213 of file sockets.cpp.

Referenced by SocketServer::accept(), SocketClient::connect(), SocketServer::SocketServer(), and UDPSocket::UDPSocket().

const int SOCKET_ERROR = -1 [static]
 

Definition at line 214 of file sockets.cpp.

Referenced by SocketClient::connect(), SocketClient::getAddr(), SocketWatcher::handleReadableSocket(), SocketWatcher::handleWritableSocket(), UDPSocket::listen(), SocketServer::listen(), SocketClient::read(), UDPSocket::recv(), UDPSocket::send(), and SocketClient::write().