Blob Blame Raw
#ifndef SOCKET_H
#define SOCKET_H


#include <vector>

#include "common.h"


class Connection;


class Poll {
public:
	struct Entry {
		Connection *connection;
		int sockId;
		bool wantRead;
		bool wantWrite;
		bool canRead;
		bool canWrite;
		bool closed;
		
		inline Entry():
			connection(), sockId(-1), wantRead(), wantWrite(), canRead(), canWrite(), closed() { }
	};
	
	typedef std::vector<Entry> List;
	
private:
	std::vector<unsigned char> data;

public:
	List list;

	Poll();
	~Poll();
	bool wait(Time duration);
};


class Socket {
private:
	Socket();
	
public:
	static int tcpConnect(const Address &address);
	static int tcpListen(const Address &address);
	static int tcpAccept(int sockId, Address &address);
	static int tcpSendAsync(int sockId, const void *data, int size);
	static int tcpRecvAsync(int sockId, void *data, int size);
	
	static int udpBind(const Address &address);
	static int udpSend(int sockId, const Address &address, const void *data, int size);
	static int udpRecvAsync(int sockId, Address &address, void *data, int size);
	
	static void close(int soskId);
};


#endif