blob: 9d7e5a2427416bd3d282b78bbb0e3347c5bf212d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/*
* psocksxx - A C++ wrapper for POSIX sockets
* Copyright (C) 2013 Uditha Atukorala
*
* This software 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 3 of the License, or
* (at your option) any later version.
*
* This software 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 software library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef PSOCKSXX_NSOCKSTREAM_H
#define PSOCKSXX_NSOCKSTREAM_H
#include <psocksxx/iosockstream.h>
#include <psocksxx/nsockaddr.h>
namespace psocksxx {
/**
* @brief Network (IPv4) controller class
*
* This is the base class for network (IP version 4)
* communications streams.
*
*/
class nsockstream : public iosockstream {
public:
/**
* @brief constructor
* @param type socket communications type
* @param proto socket communications protocol
* @throw psocksxx::sockexception socket exception
*
* Open a network (IPv4) communications stream with the
* passed in type and protocol.
*/
nsockstream( sockstreambuf::socket_type_t type, sockstreambuf::socket_protocol_t proto ) throw( sockexception );
/**
* @brief constructor
* @param ssb initialised socket stream buffer instance
*
* Initialise a network socket stream by using the passed in
* socket stream buffer, @c ssb, as the associated sequence
* which is assumed to be initialised with the correct type
* and protocol. The class destructor will delete the psocksxx::sockstreambuf
* instance pointed by @c ssb.
*
*/
nsockstream( sockstreambuf * ssb ) throw();
/**
* @brief destructor
*/
virtual ~nsockstream() throw();
/**
* @brief connect to a network address
* @param saddr destination address information
* @throw psocksxx::sockexception socket exception
* @throw psocksxx::socktimeoutexception connection timeout
* exception
*
* Connect to a IPv4 communication end point making this stream
* ready for I/O.
*
*/
void connect( const nsockaddr * saddr ) throw( sockexception, socktimeoutexception );
/**
* @brief connect to a network address
* @param node node (host name or IP)
* @param port port number
* @throw psocksxx::sockexception socket exception
* @throw psocksxx::socktimeoutexception connection timeout
* exception
*
* Connect to a IPv4 communication end point making this stream
* ready for I/O.
*
*/
void connect( const char * node, unsigned int port ) throw( sockexception, socktimeoutexception );
/**
* @brief bind the stream to a network address
* @param saddr address information to bind to
* @param reuse_addr allow address to be re-used
* @throw psocksxx::sockexception socket exception
*
* This binds the network socket stream to the specified network
* address. If you want to try to bind to any socket that is not
* actively listening (e.g. TIME_WAIT) then set the @c reuse_addr
* parameter to be @c true.
*
*/
void bind( const nsockaddr * saddr, bool reuse_addr = false ) throw( sockexception );
/**
* @brief make this stream passive and ready to accept connections
* @param backlog maximum length of the queue for pending connections
* and if this value is 0 (default) then it assumes
* system default
*
* @throw psocksxx::sockexception socket exception
*
* Make this network stream passive and ready to accept connections.
* Before calling this method the stream must be bound to a
* network address using the bind() method.
*
*/
void listen( int backlog = 0 ) throw( sockexception );
/**
* @brief accept a connection on a listening (passive) stream
* @throw psocksxx::sockexception socket exception
* @return a new stream instance for the accepted connection
*
* This method will accept an incoming connection on a listening
* stream and return a newly created stream instance that can
* be used to communicate with the accepted client connection.
* Note that the returned stream instance must be deleted by the
* caller.
*
*/
nsockstream * accept() throw( sockexception );
};
} /* end of namespace psocksxx */
#endif /* !PSOCKSXX_NSOCKSTEAM_H */
|