]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/socket.h
Use default member initializers where possible
[libs/net.git] / source / net / socket.h
index f97588415b1e5df052b1138a1e706f596810fc0b..6e0a497a08d855db1fcb506dc9c91ebfb2eb9a50 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_NET_SOCKET_H_
 #define MSP_NET_SOCKET_H_
 
+#include <msp/core/except.h>
 #include <msp/io/eventobject.h>
 #include <msp/io/handle.h>
 #include "constants.h"
 namespace Msp {
 namespace Net {
 
-#ifdef WIN32
-typedef int socklen_t;
-#endif
-
-
-class bad_socket_state: public std::logic_error
+class bad_socket_state: public invalid_state
 {
 public:
-       bad_socket_state(const std::string &w): std::logic_error(w) { }
-       virtual ~bad_socket_state() throw() { }
+       bad_socket_state(const std::string &w): invalid_state(w) { }
 };
 
 
 class Socket: public IO::EventObject
 {
 protected:
+       enum SocketEvent
+       {
+               S_NONE = IO::P_NONE,
+               S_INPUT = IO::P_INPUT,
+               S_CONNECT = 4096,
+               S_ACCEPT = 8192
+       };
+
        struct Private;
 
-       Private *priv;
-       SockAddr *local_addr;
+       Private *priv = 0;
+       SockAddr *local_addr = 0;
 
        Socket(const Private &);
        Socket(Family, int, int);
+private:
+       void platform_init();
+       void platform_cleanup();
 public:
        ~Socket();
 
-       virtual void set_block(bool);
-       virtual const IO::Handle &get_event_handle();
+       void set_block(bool) override;
+       void set_inherit(bool) override;
+       const IO::Handle &get_handle(IO::Mode);
+       const IO::Handle &get_event_handle() override;
 
        /** Associates the socket with a local address.  There must be no existing
        users of the address. */
        void bind(const SockAddr &);
 
+       bool is_bound() const { return local_addr; }
        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;
+       void set_socket_events(unsigned);
+       void set_platform_events(unsigned);
 };
 
 } // namespace Net