/* */ #ifndef _D_SOCKET_H_ #define _D_SOCKET_H_ #include #include "SocketCore.h" #include "common.h" using namespace std; class Socket { private: SocketCore* core; /** * This method doesn't increment the use count of core. */ Socket(SocketCore* core); public: Socket(); Socket(const Socket& s); ~Socket(); Socket& operator=(const Socket& s); /** * Returns socket descriptor of this socket. * @returns socket descriptor of this socket. */ int getSockfd() const { return core->sockfd; } /** * @see SocketCore::beginListen() */ void beginListen(int port = 0) const; /** * @see SocketCore::getAddrInfo() */ void getAddrInfo(pair& addrinfo) const; /** * @see SocketCore::getPeerInfo(); */ void getPeerInfo(pair& peerinfo) const; /** * @see SocketCore::acceptConnection() */ Socket* acceptConnection() const; /** * @see SocketCore::establishConnection() */ void establishConnection(string host, int port) const; /** * @see SocketCore::setBlockingMode() */ void setBlockingMode() const; /** * @see SocketCore::closeConnection() */ void closeConnection() const; /** * @see SocketCore::isWritable() */ bool isWritable(int timeout) const; /** * @see SocketCore::isReadable() */ bool isReadable(int timeout) const; /** * @see SocketCore::writeData() */ void writeData(const char* data, int len, int timeout = 5) const; /** * A covenient function that can take string class parameter and * internally calls SocketCore::writeData(). */ void writeData(string str, int timeout = 5) const; /** * @see SocketCore::readData() */ void readData(char* data, int& len, int timeout = 5) const; /** * @see SocketCore::peekData() */ void peekData(char* data, int& len, int timeout = 5) const; /** * @see SocketCore::initiateSecureConnection() */ void initiateSecureConnection() const; }; #endif // _D_SOCKET_H_