/** * xerxes - mysql proxying * ``Why do you persist in your loneliness?'' --Xerxes * (c) 2008 * Jan Losinski * Maximilian Marx */ #ifndef XERXES_SOCKET_HXX #define XERXES_SOCKET_HXX #include #include #include #include #include #include #include #include #include #include #include #include namespace xerxes { struct Socket : boost::noncopyable { Socket(int fd); Socket(int domain, int type, int protocol); virtual ~Socket(); int fd; private: Socket() {}; }; typedef boost::shared_array buffer_t; typedef std::pair MysqlData; MysqlData makeData(int len); enum sock_opt_types { TCP, UNIX }; class SocketOption { public: SocketOption(std::string new_file); SocketOption(std::string new_hostname, std::string new_port); Socket* gen_socket(); int type; std::string file; std::string hostname; std::string port; }; void validate(boost::any& v, const std::vector& values, SocketOption* target_type, int); boost::shared_ptr accept(Socket& socket, sockaddr* address, socklen_t* address_len); int listen(Socket& socket, int backlog); int connect(Socket& socket, sockaddr const* const serv_address, socklen_t address_len); int connect_inet(Socket& socket, SocketOption& opt); int connect_unix(Socket& socket, SocketOption& opt); int recv(Socket& socket, MysqlData& data, int flags); int send(Socket& socket, MysqlData& data, int len, int flags); int bind(Socket& socket, sockaddr const* const bind_address, socklen_t addrlen); int bind_inet(Socket& socket, SocketOption& opt); int bind_unix(Socket& socket, SocketOption& opt); class SocketErr{}; class ConResetErr: public SocketErr{}; class ConDataErr: public SocketErr{}; } #endif