]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/socket.h
Prepare for assimilating msphttp
[libs/net.git] / source / net / socket.h
diff --git a/source/net/socket.h b/source/net/socket.h
new file mode 100644 (file)
index 0000000..f975884
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef MSP_NET_SOCKET_H_
+#define MSP_NET_SOCKET_H_
+
+#include <msp/io/eventobject.h>
+#include <msp/io/handle.h>
+#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