Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
vsnet_socketbase.h
Go to the documentation of this file.
1
#ifndef VSNET_SOCKETBASE_H
2
#define VSNET_SOCKETBASE_H
3
4
#include <config.h>
5
6
//#include "boost/shared_ptr.hpp"
7
8
/*
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License
11
* as published by the Free Software Foundation; either version 2
12
* of the License, or (at your option) any later version.
13
*
14
* This program 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
17
* GNU General Public License for more details.
18
*
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
*/
23
24
#include <iostream>
25
26
#include "
vsnet_debug.h
"
27
#include "
vsnet_address.h
"
28
#include "
vsnet_socketset.h
"
29
30
class
SocketSet
;
31
class
Packet
;
32
class
SOCKETALT
;
33
class
PacketMem
;
34
35
//Number of times we resend a "reliable" packet in UDP mode
36
//#define NUM_RESEND 3
37
38
class
VsnetSocketBase
39
{
40
DECLARE_VALID
41
public
:
VsnetSocketBase
(
int
fd,
const
char
*socktype,
SocketSet
&set );
42
43
virtual
~VsnetSocketBase
();
44
45
bool
valid
()
const
;
46
47
int
get_fd
()
const
;
48
int
close_fd
();
49
50
const
char
*
get_socktype
()
const
;
51
52
bool
set_block
();
53
bool
set_nonblock
();
54
bool
get_nonblock
()
const
;
55
56
virtual
bool
isActive
() = 0;
57
58
void
disconnect
(
const
char
*s );
59
60
virtual
bool
lower_selected
(
int
datalen = -1 ) = 0;
61
62
virtual
bool
need_test_writable
()
63
{
64
return
false
;
65
}
66
virtual
bool
write_on_negative
()
67
{
68
return
false
;
69
}
70
virtual
int
get_write_fd
()
const
71
{
72
return
_fd
;
73
}
74
virtual
int
lower_sendbuf
()
75
{
76
return
0;
77
}
81
virtual
void
lower_clean_sendbuf
() {}
82
virtual
bool
isReadyToSend
( fd_set* );
//i.e. can call send_lower based on fd_set
83
84
void
setSet
(
SocketSet
*set );
85
protected
:
86
virtual
void
child_disconnect
(
const
char
*s ) {}
87
88
protected
:
89
//_fd may need to change for HTTP if server closes connection.
90
int
_fd
;
91
92
private
:
94
char
*_socktype;
95
protected
:
96
SocketSet
*
_set
;
//May be NULL if this isn't part of a socketset.
97
98
private
:
99
//Indicates whether a socket is in blocking or non-blocking mode.
100
//Necessary since WIN32 does not allow testing.
101
int
_noblock;
102
private
:
VsnetSocketBase
();
103
VsnetSocketBase
(
const
VsnetSocketBase
&orig );
104
VsnetSocketBase
& operator=(
const
VsnetSocketBase
&orig );
105
};
106
107
class
VsnetSocket
:
public
VsnetSocketBase
108
{
109
public
:
VsnetSocket
(
int
sock,
const
AddressIP
&remote_ip,
const
char
*socktype,
SocketSet
&set );
110
virtual
~VsnetSocket
();
111
112
virtual
bool
isTcp
()
const
= 0;
113
114
virtual
int
optPayloadSize
()
const
= 0;
115
virtual
int
queueLen
(
int
pri ) = 0;
116
117
bool
eq
(
const
VsnetSocket
&r )
const
;
118
bool
lt
(
const
VsnetSocket
&r )
const
;
119
bool
sameAddress
(
const
VsnetSocket
&r )
const
;
120
121
//virtual int sendbuf( PacketMem& packet, const AddressIP* to, int pcktflags ) = 0;
122
virtual
int
sendbuf
(
Packet
*packet,
const
AddressIP
*to,
int
pcktflags ) = 0;
123
128
virtual
int
recvbuf
(
Packet
*p,
AddressIP
*from ) = 0;
129
130
friend
std::ostream&
operator<<
( std::ostream &ostr,
const
VsnetSocket
&s );
131
132
virtual
void
dump
( std::ostream &ostr )
const
= 0;
133
134
const
AddressIP
&
getRemoteAddress
()
const
135
{
136
return
_remote_ip
;
137
}
138
virtual
bool
setRemoteAddress
(
const
AddressIP
& )
139
{
140
return
false
;
141
}
142
143
//Storage... binding is done in netui for now.
144
const
AddressIP
&
getLocalAddress
()
const
145
{
146
return
_local_ip
;
147
}
148
bool
setLocalAddress
(
const
AddressIP
&lip )
149
{
150
_local_ip
= lip;
151
return
true
;
152
}
153
//virtual void ack( ) = 0;
154
155
protected
:
156
AddressIP
_remote_ip
;
//IP address structure of remote server
157
AddressIP
_local_ip
;
//IP address this socket is bind()ed to
158
159
private
:
VsnetSocket
();
160
VsnetSocket
(
const
VsnetSocket
&orig );
161
VsnetSocket
& operator=(
const
VsnetSocket
&orig );
162
};
163
164
#endif
/* VSNET_SOCKETBASE_H */
165
src
networking
lowlevel
vsnet_socketbase.h
Generated on Fri May 29 2015 23:07:35 for Vegastrike 0.5.1 rc1 by
1.8.4