From 6541728f7999ac4bbb83564aa39ea71e6df1dd93 Mon Sep 17 00:00:00 2001 From: Myun2 Date: Wed, 1 Dec 2010 00:53:35 +0900 Subject: [PATCH] =?utf8?q?net/socket=5Fserver.hpp:=202=5F=E3=82=AF?= =?utf8?q?=E3=83=A9=E3=82=B9=E3=81=AE=E4=B8=AD=E8=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- roast/include/roast/net/socket_server.hpp | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/roast/include/roast/net/socket_server.hpp b/roast/include/roast/net/socket_server.hpp index 597b94f0..9072d364 100644 --- a/roast/include/roast/net/socket_server.hpp +++ b/roast/include/roast/net/socket_server.hpp @@ -6,9 +6,47 @@ #define __SFJP_ROAST__net__socket_server_HPP__ #include "roast/net/server_socket.hpp" +#include "roast/thread/thread.hpp" namespace roast { + template + class socket_server + { + protected: + typedef _SocketImpl ServerSocketImpl; + ServerSocketImpl m_listen_socket; + + public: + typedef struct + { + char hostname[256]; + int port_no; + } + accepted_info; + + public: + socket_server(){} + socket_server(int listen_port_no, int socktype=SOCK_STREAM, int family=AF_INET) + { + listen(listen_port_no, socktype, family); + } + + _SocketImpl listen(int listen_port_no, int socktype=SOCK_STREAM, int family=AF_INET) + { + return m_listen_socket.server_listen_accept(listen_port_no, socktype, family); + } + + _SocketImpl listen_ex(int listen_port_no, accepted_info &ai, bool is_ip_hostname=false, int socktype=SOCK_STREAM, int family=AF_INET) + { + if ( m_listen_socket.server_listen(listen_port_no, socktype, family) == false ) + return _SocketImpl(); + + return m_listen_socket.accept(ai.hostname, sizeof(ai.hostname), false, &ai.port_no); + } + + + }; } -- 2.11.0