-
Notifications
You must be signed in to change notification settings - Fork 0
/
Socket.hh
43 lines (36 loc) · 1.03 KB
/
Socket.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
/**
Represent a client/server socket pair
and call a handler.
@author: Dov Kruger
*/
#ifdef _WIN32
#include <winsock2.h>
#endif
#include <cstdint>
using namespace std;
class Request; // forward reference, all code is included in .cc
class Socket {
protected:
const char* address;
uint16_t port;
#ifdef __linux__
char sockaddress[16]; // placeholder big enough to hold sockaddr_in structure
#elif _WIN32
static WSADATA wsaData;
struct addrinfo* result;
#endif
Request* req; // to be called when a request is INCOMING (req->handle() )
public:
Socket(const char* addr, uint16_t port);
// TODO: simplify
// below two constructors could be merged depends on the location of variable
// "req" Constructor for CSP server
Socket(uint16_t port, Request* req);
Socket(uint16_t port); // Constructor for server (addres not specified)
~Socket();
static void classCleanup();
static void classInit();
void attach(Request* r) { req = r; }
virtual void wait() = 0;
};