~ubuntu-branches/ubuntu/oneiric/libclaw/oneiric

« back to all changes in this revision

Viewing changes to claw/code/basic_socket.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge
  • Date: 2008-05-17 15:36:57 UTC
  • Revision ID: james.westby@ubuntu.com-20080517153657-0b1204j754ykoz48
Tags: upstream-1.5.2b
ImportĀ upstreamĀ versionĀ 1.5.2b

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  CLAW - a C++ Library Absolutely Wonderful
 
3
 
 
4
  CLAW is a free library without any particular aim but being useful to 
 
5
  anyone.
 
6
 
 
7
  Copyright (C) 2005-2008 Julien Jorge
 
8
 
 
9
  This library is free software; you can redistribute it and/or
 
10
  modify it under the terms of the GNU Lesser General Public
 
11
  License as published by the Free Software Foundation; either
 
12
  version 2.1 of the License, or (at your option) any later version.
 
13
 
 
14
  This library is distributed in the hope that it will be useful,
 
15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
  Lesser General Public License for more details.
 
18
 
 
19
  You should have received a copy of the GNU Lesser General Public
 
20
  License along with this library; if not, write to the Free Software
 
21
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
22
 
 
23
  contact: julien_jorge@yahoo.fr
 
24
*/
 
25
/**
 
26
 * \file basic_socket.cpp
 
27
 * \brief Implementation of the claw::net::basic_socket class.
 
28
 * \author Julien Jorge
 
29
 */
 
30
#include <claw/basic_socket.hpp>
 
31
 
 
32
/*----------------------------------------------------------------------------*/
 
33
/**
 
34
 * \brief Constructor.
 
35
 * \post is_open() == false
 
36
 */
 
37
claw::net::basic_socket::basic_socket()
 
38
  : m_descriptor(socket_traits::invalid_socket)
 
39
{
 
40
 
 
41
} // basic_socket::basic_socket()
 
42
 
 
43
/*----------------------------------------------------------------------------*/
 
44
/**
 
45
 * \brief Open the socket.
 
46
 * \return this is everything works fine, NULL otherwise.
 
47
 */
 
48
claw::net::basic_socket::basic_socket* claw::net::basic_socket::open()
 
49
{
 
50
  basic_socket* result = NULL;
 
51
  
 
52
  m_descriptor = socket_traits::open();
 
53
 
 
54
  if ( socket_traits::valid_descriptor( m_descriptor ) )
 
55
    result = this;
 
56
 
 
57
  return result;
 
58
} // basic_socket::open()
 
59
 
 
60
/*----------------------------------------------------------------------------*/
 
61
/**
 
62
 * \brief Close the socket.
 
63
 * \return this if everything works fine, NULL otherwise.
 
64
 */
 
65
claw::net::basic_socket::basic_socket* claw::net::basic_socket::close()
 
66
{
 
67
  basic_socket* result = this;
 
68
 
 
69
  if ( is_open() )
 
70
    {
 
71
      if ( socket_traits::close(m_descriptor) )
 
72
        m_descriptor = socket_traits::invalid_socket;
 
73
      else
 
74
        result = NULL;
 
75
    }
 
76
 
 
77
  return result;
 
78
} // basic_socket::close()
 
79
 
 
80
/*----------------------------------------------------------------------------*/
 
81
/**
 
82
 * \brief Tell if the socket is open.
 
83
 */
 
84
bool claw::net::basic_socket::is_open() const
 
85
{
 
86
  return socket_traits::valid_descriptor(m_descriptor);
 
87
} // basic_socket::is_open()
 
88