1#ifndef TENDUKE_OSA_ABSTRACTBASESOCKET_H 
    2#define TENDUKE_OSA_ABSTRACTBASESOCKET_H 
   10#if defined(__APPLE__) || defined(__linux__) || defined(__unix__) || defined(_POSIX_VERSION) || defined(__ANDROID__) 
   13#include <sys/socket.h> 
   15#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined (_WIN64) 
   43    int get()
 const {
return descriptor;}
 
 
   63    std::unique_ptr<tenduke::osa::Socket> 
accept(uint32_t timeoutMs) 
override;
 
   74    int read(
void * buffer, std::size_t bufferSize) 
override;
 
   79    int write(
const void * buffer, std::size_t len) 
override;
 
  108    virtual std::string 
mkErrorMessage(
const std::string &body) 
const;
 
  123    virtual std::string 
mkErrorMessage(
const std::string &body, 
int errorCode) 
const = 0;
 
  136    struct ::sockaddr_in address;
 
 
 
void listen() override
Configures the socket to listen for incoming connections.
Definition AbstractBaseSocket.cpp:89
 
virtual bool wouldBlock(int errorCode) const =0
Checks if error code means that call would have blocked.
 
virtual int getLastError() const =0
Returns last error code.
 
virtual std::unique_ptr< tenduke::osa::Socket > createSocket(int descriptor, const struct ::sockaddr_in *address)=0
Creates a socket.
 
virtual std::unique_ptr< Socket > accept()=0
Accepts next connection from listening socket.
 
AbstractBaseSocket(int descriptor, const struct ::sockaddr_in *address)
Constructs new instance.
 
int read(void *buffer, std::size_t bufferSize) override
Reads bytes from the socket.number of bytes read. Returns -1, if socket is non-blocking and nothing t...
Definition AbstractBaseSocket.cpp:97
 
SocketDescriptor descriptor
The socket descriptor.
Definition AbstractBaseSocket.h:133
 
int write(const void *buffer, std::size_t len) override
Write bytes to the socket.number of bytes written
Definition AbstractBaseSocket.cpp:115
 
virtual std::string mkErrorMessage(const std::string &body, int errorCode) const =0
Builds error message.
 
virtual std::string mkErrorMessage(const std::string &body) const
Builds error message.
Definition AbstractBaseSocket.cpp:138
 
AbstractBaseSocket(uint32_t address, uint16_t port)
Constructs new socket.
Definition AbstractBaseSocket.cpp:43
 
Wraps the socket descriptor for RAII.
Definition AbstractBaseSocket.h:30
 
int get() const
Returns the descriptor.
Definition AbstractBaseSocket.h:43
 
SocketDescriptor(int descriptor)
Creates new instance.
Definition AbstractBaseSocket.cpp:20
 
OS-independent abstraction of a socket.
Definition Socket.h:14
 
virtual std::unique_ptr< Socket > accept(uint32_t timeoutMs)=0
Accepts next connection from listening socket, with a timeout.
 
Operating system abstraction.
Definition AbstractBaseSocket.h:22
 
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4