X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnet%2Fsocket.h;fp=source%2Fnet%2Fsocket.h;h=f97588415b1e5df052b1138a1e706f596810fc0b;hb=50e9f9ea7f7385a2c5931fca2b8fb1103078e67c;hp=0000000000000000000000000000000000000000;hpb=21c596567e3b6fd794ed6af73d304ce2bc70e58f;p=libs%2Fnet.git diff --git a/source/net/socket.h b/source/net/socket.h new file mode 100644 index 0000000..f975884 --- /dev/null +++ b/source/net/socket.h @@ -0,0 +1,56 @@ +#ifndef MSP_NET_SOCKET_H_ +#define MSP_NET_SOCKET_H_ + +#include +#include +#include "constants.h" +#include "sockaddr.h" + +namespace Msp { +namespace Net { + +#ifdef WIN32 +typedef int socklen_t; +#endif + + +class bad_socket_state: public std::logic_error +{ +public: + bad_socket_state(const std::string &w): std::logic_error(w) { } + virtual ~bad_socket_state() throw() { } +}; + + +class Socket: public IO::EventObject +{ +protected: + struct Private; + + Private *priv; + SockAddr *local_addr; + + Socket(const Private &); + Socket(Family, int, int); +public: + ~Socket(); + + virtual void set_block(bool); + virtual const IO::Handle &get_event_handle(); + + /** Associates the socket with a local address. There must be no existing + users of the address. */ + void bind(const SockAddr &); + + const SockAddr &get_local_address() const; + + void set_timeout(const Time::TimeDelta &); +protected: + int set_option(int, int, const void *, socklen_t); + int get_option(int, int, void *, socklen_t *) const; +}; + +} // namespace Net +} // namespace Msp + +#endif