Files
CPP/sstp/socketserver.hpp

42 lines
1.1 KiB
C++

#ifndef _LISTENER_SOCKETSERVER_HPP_
#define _LISTENER_SOCKETSERVER_HPP_
#include <stdio.h>
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <thread>
#include <vector>
#include <common/string.hpp>
#include <common/profiler.hpp>
#include <common/block.hpp>
#include <common/fileio.hpp>
#include <common/pointer.hpp>
class SocketConnectionReceiver;
class SocketServer
{
public:
SocketServer();
SocketServer(int port);
virtual ~SocketServer();
void listen(void);
void close(void);
bool isOkay(void);
private:
static constexpr int MAX_CONNECTIONS=10; // The maximum connections to be queued at a time
void shutdownConnectionReceivers();
void join(void);
bool mIsOkay;
int mListenPort;
int mSocketFileDescriptor;
struct sockaddr_in mInternalSocketAddress;
socklen_t mAddressLength = sizeof(mInternalSocketAddress);
std::vector<std::thread> mExecutionThreads;
Block<SmartPointer<SocketConnectionReceiver>> mSocketConnectionReceivers;
};
#endif