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 44 45 46 47 48 49 50 51 52 53
|
#ifndef RPCSOCKET_H
#define RPCSOCKET_H
namespace rpc {
class SocketException
{
public:
SocketException(char* aReason) : reason(aReason) {}
char* getReason() const {return reason;}
private:
char* reason;
};
class SocketListener;
/**
@author Rikard Bjorklind <olof@linux.nu>
*/
class Socket{
public:
Socket(SocketListener*);
// Interface for mortals
void listen(int port) throw(SocketException);
Socket* accept(SocketListener*) throw(SocketException);
int read(void* buf,int len) throw(SocketException);
int write(const void *buf,int len) throw(SocketException);
void connect(const char* addr,int port);
void disconnect();
int getFd() {return fd;}
void setFd(int f) {fd=f;}
int getId() {return fd;}
bool getIsServer() const { return isServer; }
// SocketManager interface - never call these
//! Called by the socketmanager when select() indicates readable
void onRead();
~Socket();
private:
SocketListener* listener;
bool isServer;
bool isConnected;
int fd;
};
}
#endif
|