]> git.tdb.fi Git - libs/net.git/commitdiff
Move some functions around a bit
authorMikko Rasa <tdb@tdb.fi>
Sat, 6 Aug 2011 20:30:00 +0000 (23:30 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 6 Aug 2011 20:30:00 +0000 (23:30 +0300)
source/socket.cpp
source/socket.h
source/streamsocket.cpp

index b5a6ec856ed615b9e3a8db920b4950f1a657917b..2bfdecc5b07794976ddaab3d5d528081c492d9a7 100644 (file)
@@ -117,6 +117,13 @@ void Socket::bind(const SockAddr &addr)
        local_addr = addr.copy();
 }
 
+const SockAddr &Socket::get_local_address() const
+{
+       if(local_addr==0)
+               throw bad_socket_state("not bound");
+       return *local_addr;
+}
+
 void Socket::set_timeout(const Time::TimeDelta &timeout)
 {
 #ifndef WIN32
@@ -130,13 +137,6 @@ void Socket::set_timeout(const Time::TimeDelta &timeout)
 #endif
 }
 
-const SockAddr &Socket::get_local_address() const
-{
-       if(local_addr==0)
-               throw bad_socket_state("not bound");
-       return *local_addr;
-}
-
 int Socket::set_option(int level, int optname, const void *optval, socklen_t optlen)
 {
 #ifdef WIN32
index 38d65da40da560ba3443d81d561cd38df71cea24..f97588415b1e5df052b1138a1e706f596810fc0b 100644 (file)
@@ -35,15 +35,16 @@ protected:
 public:
        ~Socket();
 
-       void set_block(bool);
-       const IO::Handle &get_event_handle();
+       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 &);
 
-       void set_timeout(const Time::TimeDelta &);
        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;
index 3fa6b9a13daafda29f3cd47f8ee1ef7d01cc3953..b06cf69ca9314cb6c750c1147513f9b4dc9c3a0a 100644 (file)
@@ -26,47 +26,6 @@ StreamSocket::StreamSocket(Family af, int proto):
        ClientSocket(af, SOCK_STREAM, proto)
 { }
 
-bool StreamSocket::poll_connect(const Time::TimeDelta &timeout)
-{
-       if(!connecting)
-               throw bad_socket_state("not connecting");
-
-       int res = poll(*this, IO::P_OUTPUT, timeout);
-       if(res==-1)
-#ifdef WIN32
-               throw system_error("poll", WSAGetLastError());
-#else
-               throw system_error("poll");
-#endif
-       else if(res>0)
-       {
-               connecting = false;
-
-               int err;
-               socklen_t len = sizeof(int);
-               get_option(SOL_SOCKET, SO_ERROR, &err, &len);
-
-               if(err!=0)
-               {
-                       set_events(IO::P_NONE);
-#ifdef WIN32
-                       throw system_error("connect", WSAGetLastError());
-#else
-                       throw system_error("connect");
-#endif
-               }
-
-#ifdef WIN32
-               WSAEventSelect(priv->handle, *priv->event, FD_READ|FD_CLOSE);
-#endif
-               set_events(IO::P_INPUT);
-
-               connected = true;
-       }
-
-       return connected;
-}
-
 bool StreamSocket::connect(const SockAddr &addr)
 {
        if(connected)
@@ -120,6 +79,47 @@ bool StreamSocket::connect(const SockAddr &addr)
        return connected;
 }
 
+bool StreamSocket::poll_connect(const Time::TimeDelta &timeout)
+{
+       if(!connecting)
+               throw bad_socket_state("not connecting");
+
+       int res = poll(*this, IO::P_OUTPUT, timeout);
+       if(res==-1)
+#ifdef WIN32
+               throw system_error("poll", WSAGetLastError());
+#else
+               throw system_error("poll");
+#endif
+       else if(res>0)
+       {
+               connecting = false;
+
+               int err;
+               socklen_t len = sizeof(int);
+               get_option(SOL_SOCKET, SO_ERROR, &err, &len);
+
+               if(err!=0)
+               {
+                       set_events(IO::P_NONE);
+#ifdef WIN32
+                       throw system_error("connect", WSAGetLastError());
+#else
+                       throw system_error("connect");
+#endif
+               }
+
+#ifdef WIN32
+               WSAEventSelect(priv->handle, *priv->event, FD_READ|FD_CLOSE);
+#endif
+               set_events(IO::P_INPUT);
+
+               connected = true;
+       }
+
+       return connected;
+}
+
 void StreamSocket::on_event(IO::PollEvent ev)
 {
        if((ev&(IO::P_OUTPUT|IO::P_ERROR)) && connecting)