11 #include <netinet/in.h>
14 #include <netinet/tcp.h>
15 #include <sys/ioctl.h>
18 #include <sys/types.h>
19 #include <sys/socket.h>
22 #include "rofl/common/croflexception.h"
23 #include "rofl/common/ciosrv.h"
24 #include "rofl/common/csockaddr.h"
25 #include "rofl/common/logging.h"
26 #include "rofl/common/cparams.h"
189 SOCKET_TYPE_UNKNOWN = 0,
190 SOCKET_TYPE_PLAIN = 1,
191 SOCKET_TYPE_OPENSSL = 2,
208 enum socket_type_t socket_type);
219 enum socket_type_t socket_type) :
221 socket_type(socket_type),
295 recv(
void *buf,
size_t count) = 0;
323 is_established()
const = 0;
329 write_would_block()
const = 0;
343 enum rofl::csocket::socket_type_t
344 get_socket_type()
const
351 get_socket_params()
const
387 { this->domain =
domain; };
401 { this->type =
type; };
429 supports_socket_type(
enum socket_type_t socket_type);
432 static std::string
const PARAM_KEY_DO_RECONNECT;
433 static std::string
const PARAM_KEY_REMOTE_HOSTNAME;
434 static std::string
const PARAM_KEY_REMOTE_PORT;
435 static std::string
const PARAM_KEY_LOCAL_HOSTNAME;
436 static std::string
const PARAM_KEY_LOCAL_PORT;
437 static std::string
const PARAM_KEY_DOMAIN;
438 static std::string
const PARAM_KEY_TYPE;
439 static std::string
const PARAM_KEY_PROTOCOL;
442 static std::string
const PARAM_DOMAIN_VALUE_INET_ANY;
443 static std::string
const PARAM_DOMAIN_VALUE_INET;
444 static std::string
const PARAM_DOMAIN_VALUE_INET6;
445 static std::string
const PARAM_TYPE_VALUE_STREAM;
446 static std::string
const PARAM_TYPE_VALUE_DGRAM;
447 static std::string
const PARAM_PROTOCOL_VALUE_TCP;
448 static std::string
const PARAM_PROTOCOL_VALUE_UDP;
451 static std::string
const PARAM_SSL_KEY_CA_PATH;
452 static std::string
const PARAM_SSL_KEY_CA_FILE;
453 static std::string
const PARAM_SSL_KEY_CERT;
454 static std::string
const PARAM_SSL_KEY_PRIVATE_KEY;
455 static std::string
const PARAM_SSL_KEY_PRIVATE_KEY_PASSWORD;
456 static std::string
const PARAM_SSL_KEY_VERIFY_MODE;
457 static std::string
const PARAM_SSL_KEY_VERIFY_DEPTH;
458 static std::string
const PARAM_SSL_KEY_CIPHERS;
463 operator<< (std::ostream& os,
csocket const& sock) {
465 <<
"sd:" << sock.sd <<
" "
466 <<
"domain:" << sock.domain <<
" "
467 <<
"type:" << sock.type <<
" "
468 <<
"protocol:" << sock.protocol <<
" ";
469 os <<
">" << std::endl;
int type
Definition: csocket.h:485
virtual void handle_accept_refused(rofl::csocket &socket)=0
Called once accepting a request from a remote entity failed.
virtual ssize_t recv(void *buf, size_t count)=0
Reads bytes from socket.
virtual void handle_accepted(rofl::csocket &socket)=0
Called once this csocket entity has succeeded its accept() method.
virtual ~csocket()
csocket destructor
Definition: csocket.h:233
A single socket.
Definition: csocket.h:182
virtual ~csocket_env()
Destructor.
Definition: csocket.h:66
virtual void accept(const rofl::cparams &socket_params, int sd)=0
Handle accepted socket descriptor obtained from external listening socket.
Definition: csockaddr.h:38
int backlog
Definition: csocket.h:487
virtual void reconnect()=0
Reconnect this socket.
virtual void handle_read(rofl::csocket &socket)=0
Called once new data is available for reading from the socket.
virtual void close()=0
Closes this socket.
int domain
Definition: csocket.h:484
cparams socket_params
Definition: csocket.h:488
virtual void handle_closed(rofl::csocket &socket)=0
Called once the socket has been shutdown and closed.
C++ abstraction for malloc'ed memory areas.
Definition: cmemory.h:44
virtual void handle_listen(rofl::csocket &socket, int newsd)=0
Called once a listening socket has accepted a connection request from a remote peer entity...
virtual void handle_connect_refused(rofl::csocket &socket)=0
Called once a connection request to a remote entity failed.
csocket_env * socket_env
Definition: csocket.h:475
An abstract interface defining the consumer side of a csocket.
Definition: csocket.h:58
int sd
Definition: csocket.h:481
virtual void connect(const rofl::cparams ¶ms)=0
Open socket and connect to peer entity (client side).
virtual void handle_connected(rofl::csocket &socket)=0
Called once a connection request has succeeded its connect() method.
Base class for IO services.
Definition: ciosrv.h:491
virtual void handle_connect_failed(rofl::csocket &socket)=0
Called once a connection request to a remote entity failed.
csockaddr raddr
Definition: csocket.h:483
virtual void send(cmemory *mem, rofl::csockaddr const &dest=rofl::csockaddr())=0
Store a packet for transmission.
csockaddr laddr
Definition: csocket.h:482
virtual void listen(const rofl::cparams ¶ms)=0
Open socket in listening mode (server side).
int protocol
Definition: csocket.h:486
enum socket_type_t socket_type
Definition: csocket.h:480
virtual void handle_write(rofl::csocket &socket)=0
Called once the socket accept additional data for sending.
csocket(csocket_env *env, enum socket_type_t socket_type)
csocket constructor
Definition: csocket.h:217
Definition: croflexception.h:27