|
|
dd2ea4 |
#ifndef SOCKET_H
|
|
|
873e9f |
#define SOCKET_H
|
|
|
dd2ea4 |
|
|
|
dd2ea4 |
|
|
|
873e9f |
#include <vector></vector>
|
|
|
873e9f |
|
|
|
dd2ea4 |
#include "common.h"
|
|
|
dd2ea4 |
|
|
|
dd2ea4 |
|
|
|
873e9f |
class Connection;
|
|
|
873e9f |
|
|
|
873e9f |
|
|
|
dd2ea4 |
class Poll {
|
|
|
873e9f |
public:
|
|
|
873e9f |
struct Entry {
|
|
|
873e9f |
Connection *connection;
|
|
|
873e9f |
int sockId;
|
|
|
873e9f |
bool wantRead;
|
|
|
873e9f |
bool wantWrite;
|
|
|
873e9f |
bool canRead;
|
|
|
873e9f |
bool canWrite;
|
|
|
873e9f |
bool closed;
|
|
|
873e9f |
|
|
|
873e9f |
inline Entry():
|
|
|
873e9f |
connection(), sockId(-1), wantRead(), wantWrite(), canRead(), canWrite(), closed() { }
|
|
|
873e9f |
};
|
|
|
dd2ea4 |
|
|
|
873e9f |
typedef std::vector<entry> List;</entry>
|
|
|
873e9f |
|
|
|
873e9f |
private:
|
|
|
873e9f |
std::vector<unsigned char=""> data;</unsigned>
|
|
|
873e9f |
|
|
|
dd2ea4 |
public:
|
|
|
873e9f |
List list;
|
|
|
873e9f |
|
|
|
dd2ea4 |
Poll();
|
|
|
dd2ea4 |
~Poll();
|
|
|
f6f04f |
bool wait(Time duration);
|
|
|
dd2ea4 |
};
|
|
|
dd2ea4 |
|
|
|
dd2ea4 |
|
|
|
dd2ea4 |
class Socket {
|
|
|
dd2ea4 |
private:
|
|
|
dd2ea4 |
Socket();
|
|
|
dd2ea4 |
|
|
|
dd2ea4 |
public:
|
|
|
dd2ea4 |
static int tcpConnect(const Address &address);
|
|
|
dd2ea4 |
static int tcpListen(const Address &address);
|
|
|
937c1c |
static int tcpAccept(int sockId);
|
|
|
937c1c |
static int tcpSendAsync(int sockId, const void *data, int size);
|
|
|
937c1c |
static int tcpRecvAsync(int sockId, void *data, int size);
|
|
|
dd2ea4 |
|
|
|
c47604 |
static int udpBind(const Address &address);
|
|
|
937c1c |
static int udpSend(int sockId, const Address &address, const void *data, int size);
|
|
|
937c1c |
static int udpRecvAsync(int sockId, Address &address, void *data, int size);
|
|
|
dd2ea4 |
|
|
|
dd2ea4 |
static void close(int soskId);
|
|
|
dd2ea4 |
};
|
|
|
dd2ea4 |
|
|
|
dd2ea4 |
|
|
|
dd2ea4 |
#endif
|