socket_server.cpp
Go to the documentation of this file.
/*
CLAW - a C++ Library Absolutely Wonderful
CLAW is a free library without any particular aim but being useful to
anyone.
Copyright (C) 2005-2011 Julien Jorge
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
contact: julien.jorge@gamned.org
*/
#include <claw/socket_server.hpp>
#include <sys/types.h>
/*----------------------------------------------------------------------------*/
claw::net::socket_server::socket_server()
{
// nothing to do
} // socket_server::socket_server()
/*----------------------------------------------------------------------------*/
claw::net::socket_server::socket_server( int port, unsigned int queue_size )
{
open(port, queue_size);
} // socket_server::socket_server()
/*----------------------------------------------------------------------------*/
claw::net::socket_server*
claw::net::socket_server::open( int port, unsigned int queue_size )
{
socket_server* result = NULL;
if ( basic_socket::open() )
{
if ( !socket_traits::listen(m_descriptor, port, queue_size) )
basic_socket::close();
else
result = this;
}
return result;
} // socket_server::open()
/*----------------------------------------------------------------------------*/
claw::net::socket_server* claw::net::socket_server::close()
{
if ( basic_socket::close() )
return this;
else
return NULL;
} // socket_server::close()
/*----------------------------------------------------------------------------*/
bool claw::net::socket_server::is_open() const
{
return basic_socket::is_open();
} // socket_server::is_open()
/*----------------------------------------------------------------------------*/
claw::net::socket_server::operator bool() const
{
return is_open();
} // socket_server::operator bool()
/*----------------------------------------------------------------------------*/
bool claw::net::socket_server::init()
{
return socket_traits::init();
} // socket_server::init()
/*----------------------------------------------------------------------------*/
bool claw::net::socket_server::release()
{
return socket_traits::release();
} // socket_server::release()
claw::net::socket_server
Class used to receive incoming connections.
Definition: socket_server.hpp:47
claw::net::basic_socket::open
basic_socket * open()
Open the socket.
Definition: basic_socket.cpp:48
claw::net::socket_server::init
static bool init()
Initialize the use of the socket library.
Definition: socket_server.cpp:112
claw::net::socket_server::release
static bool release()
Close the socket library.
Definition: socket_server.cpp:122
claw::net::basic_socket::m_descriptor
socket_traits::descriptor m_descriptor
File descriptor.
Definition: basic_socket.hpp:58
claw::net::basic_socket::close
basic_socket * close()
Close the socket.
Definition: basic_socket.cpp:65
claw::socket_traits_unix::init
static bool init()
Initialize the use of the socket library.
Definition: socket_traits_unix.hpp:66
claw::net::socket_server::is_open
bool is_open() const
Tell if the server is open.
Definition: socket_server.cpp:93
claw::net::socket_server::close
socket_server * close()
Close the socket.
Definition: socket_server.cpp:81
claw::net::socket_server::socket_server
socket_server()
Constructor.
Definition: socket_server.cpp:38
socket_server.hpp
Class used to receive incoming connections.
claw::socket_traits_unix::listen
static bool listen(descriptor d, int port, unsigned int queue_size)
Open a socket for incoming connexions.
Definition: socket_traits_unix.hpp:145
claw::net::basic_socket::is_open
bool is_open() const
Tell if the socket is open.
Definition: basic_socket.cpp:84
claw::socket_traits_unix::release
static bool release()
Close the socket library.
Definition: socket_traits_unix.hpp:76