Windows support (no TLS yet)

This commit is contained in:
Benjamin Sergeant
2018-10-08 21:42:45 -07:00
parent af12089e7a
commit 71b40c6d6c
5 changed files with 116 additions and 45 deletions

View File

@ -11,6 +11,8 @@
#include <mutex>
#include <atomic>
struct addrinfo;
namespace ix
{
class Socket {
@ -20,9 +22,9 @@ namespace ix
Socket();
virtual ~Socket();
static int hostname_connect(const std::string& hostname,
int port,
std::string& errMsg);
int hostname_connect(const std::string& hostname,
int port,
std::string& errMsg);
void configure();
virtual void poll(const OnPollCallback& onPollCallback);
@ -38,13 +40,24 @@ namespace ix
virtual int send(const std::string& buffer);
virtual int recv(void* buffer, size_t length);
int getErrno() const;
static bool init(); // Required on Windows to initialize WinSocket
static void cleanup(); // Required on Windows to cleanup WinSocket
protected:
void wakeUpFromPollApple();
void wakeUpFromPollLinux();
void closeSocket(int fd);
std::atomic<int> _sockfd;
int _eventfd;
std::mutex _socketMutex;
private:
bool connectToAddress(const struct addrinfo *address,
int& sockfd,
std::string& errMsg);
};
}