OSDN Git Service

net/socket: 取り合えずselect()を追加
authorMyun2 <myun2@nwhite.info>
Wed, 15 Dec 2010 06:06:14 +0000 (15:06 +0900)
committerMyun2 <myun2@nwhite.info>
Wed, 15 Dec 2010 06:06:14 +0000 (15:06 +0900)
roast/include/roast/net/socket.hpp
roast/include/roast/net/socket_windows_impl.hpp

index dca5b00..be34302 100644 (file)
@@ -20,6 +20,7 @@ namespace roast
                typedef typename _Impl::sockaddr_t sockaddr_t;
                typedef typename _Impl::sockaddr_in_t sockaddr_in_t;
                typedef typename _Impl::addrinfo_t addrinfo_t;
+               typedef typename _Impl::fd_set_t fd_set_t, fdset_t;
                
        protected:
                _Impl m_impl;
@@ -130,9 +131,28 @@ namespace roast
                        }
                        return true;
                }
+               
+               //////////////////////////////////////////////////////////////////////////////
+               
+               int select(int fdset_max_plus_one,
+                       fdset_t* readable_check_fdset,
+                       fdset_t* writable_check_fdset,
+                       fdset_t* exception_check_fdset, long timeout_sec, long timeout_usec=0 )
+               {
+                       return m_impl.select(fdset_max_plus_one,
+                               readable_check_fdset, writable_check_fdset, exception_check_fdset,
+                               timeout_sec, timeout_usec);
+               }
+               bool is_connected()
+               {
+
+               }
                bool is_available_socket()
                {
-                       return (m_socket != _Impl::invalid_socket);
+                       //return (m_socket != _Impl::invalid_socket);
+                       /*if ( m_socket == _Impl::invalid_socket )
+                               return false;*/
+                       return is_connected();
                }
                bool is_available(){ return is_available_socket(); }
                
index 844b5b9..40db0a8 100644 (file)
@@ -52,6 +52,7 @@ namespace roast
                typedef struct ::sockaddr_in sockaddr_in_t;
                typedef struct ::addrinfo addrinfo_t;
                typedef ::SOCKET socket_t;
+               typedef ::fd_set fd_set_t, fdset_t;
        
        private:
                //WSADATA* m_wsaInfo;
@@ -202,6 +203,20 @@ namespace roast
                        return _apiret_WSAle( ::closesocket(s) );
                }
 
+               //      select()
+               int select(socket_t s,
+                       fdset_t *readfds, fdset_t *writefds, fdset_t *exceptfds,
+                       long timeout_sec, long timeout_usec)
+               {
+                       struct ::timeval tv;
+                       tv.tv_sec = timeout_sec;
+                       tv.tv_usec = timeout_usec;
+                       
+                       int ret = ::select(s, readfds, writefds, exceptfds, tv);
+                       _WSAle_update();
+                       return ret;
+               }
+
                ////////////////////////////////////////////////////////////////
 
                //      recv