Switch from epoll to libevent, to add OS X support.

This commit is contained in:
Ian Gulliver
2015-02-07 16:44:42 +01:00
parent 2c9b9f97de
commit 88c3c69e52
4 changed files with 64 additions and 98 deletions

View File

@@ -1,26 +1,27 @@
#include <sys/epoll.h>
#include <event2/bufferevent.h>
#include <event2/event.h>
#include <event2/listener.h>
#include <string>
class CryptoBase {
public:
CryptoBase(const int fd);
virtual ~CryptoBase();
virtual ~CryptoBase() {};
static void GenKey(std::string* key);
static void GenKeyPair(std::string* secret_key, std::string* public_key);
virtual void OnReadable() = 0;
protected:
const int fd_;
};
class CryptoPubServerConnection : public CryptoBase {
public:
CryptoPubServerConnection(const int fd, const std::string secret_key);
void OnReadable();
CryptoPubServerConnection(struct bufferevent* bev, const std::string secret_key);
~CryptoPubServerConnection();
static void OnReadable(struct bufferevent* bev, void* this__);
static void OnError(struct bufferevent* bev, const short what, void* this__);
private:
struct bufferevent* bev_;
const std::string secret_key_;
const std::string ephemeral_secret_key_;
const std::string client_public_key_;
@@ -32,12 +33,14 @@ class CryptoPubServerConnection : public CryptoBase {
class CryptoPubServer : public CryptoBase {
public:
CryptoPubServer(const int fd, const std::string secret_key);
CryptoPubServer(const std::string secret_key);
~CryptoPubServer();
void OnReadable();
static void OnNewConn(struct evconnlistener* listener, int fd, struct sockaddr* client_addr, int client_addrlen, void* this__);
void Loop();
private:
struct event_base *event_base_;
struct evconnlistener *listener_;
const std::string secret_key_;
const int epoll_fd_;
};