LIBRCSC Docs
Documentation for HELIOS's BASE LIBRCSC library for RoboCup 2D Simulation League.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
abstract_socket.h
Go to the documentation of this file.
1// -*-c++-*-
2
8/*
9 *Copyright:
10
11 Copyright (C) Hidehisa AKIYAMA, Hiroki SHIMORA
12
13 This code is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 3 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27 *EndCopyright:
28 */
29
31
32#ifndef RCSC_NET_ABSTRACT_SOCKET_H
33#define RCSC_NET_ABSTRACT_SOCKET_H
34
36
37#include <boost/scoped_ptr.hpp>
38
39#include <string>
40#include <cstddef>
41
42namespace rcsc {
43
49public:
55 DATAGRAM_TYPE,
56 STREAM_TYPE,
57 UNKNOWN_TYPE,
58 };
59
60private:
62 int M_fd;
64 int M_socket_type;
65
66protected:
71
72protected:
77
78public:
82 virtual
84
89 int fd() const
90 {
91 return M_fd;
92 }
93
94protected:
99 bool open( const SocketType type );
100
106 bool bind( const HostAddress::PortNumber port );
107
114 bool setPeerAddress( const char * hostname,
115 const HostAddress::PortNumber port );
116
122
128
129public:
130
135 bool isOpen() const
136 {
137 return fd() != -1;
138 }
139
144 int close();
145
150 const HostAddress & localAddress() const
151 {
152 return M_local_address;
153 }
154
160 {
161 return M_local_address.portNumber();
162 }
163
168 const HostAddress & peerAddress() const
169 {
170 return M_peer_address;
171 }
172
177 std::string peerName() const
178 {
179 return M_peer_address.toHostName();
180 }
181
187 {
188 return M_peer_address.portNumber();
189 }
190
191};
192
193} // end namespace
194
195#endif
socket class
Definition: abstract_socket.h:48
const HostAddress & localAddress() const
get the local address object
Definition: abstract_socket.h:150
AbstractSocket()
protected constructor to prevent instantiation
HostAddress::PortNumber peerPort() const
get the port number of destination address
Definition: abstract_socket.h:186
bool isOpen() const
check if socket is opened or not.
Definition: abstract_socket.h:135
bool open(const SocketType type)
open socket
bool setPeerAddress(const char *hostname, const HostAddress::PortNumber port)
set the address info of the specified remote host.
const HostAddress & peerAddress() const
get the peer address object
Definition: abstract_socket.h:168
SocketType
socket type definition
Definition: abstract_socket.h:54
HostAddress M_peer_address
destination address
Definition: abstract_socket.h:70
HostAddress M_local_address
local address
Definition: abstract_socket.h:68
virtual ~AbstractSocket()
destructor. close socket automatically
bool bind(const HostAddress::PortNumber port)
bind the socket to local address
int setNonBlocking()
set non blocking mode.
int close()
close socket
int fd() const
returns socket file descriptor
Definition: abstract_socket.h:89
HostAddress::PortNumber localPort() const
get the port number of destination address
Definition: abstract_socket.h:159
std::string peerName() const
get the host name of destination address
Definition: abstract_socket.h:177
int connectToPresetAddr()
connect to address set by setAddr()
Definition: host_address.h:43
std::uint16_t PortNumber
port number type
Definition: host_address.h:45
std::string toHostName() const
get the address as a string (e.g. "127.0.0.1") that is generated by inet_ntoa.
address class Header File.