Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vsnet_serversocket.h
Go to the documentation of this file.
1 #ifndef VSNET_SERVERSOCKET_H
2 #define VSNET_SERVERSOCKET_H
3 
4 #include <config.h>
5 
6 /*
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 
22 #include "vsnet_address.h"
23 #include "vsnet_socketset.h"
24 #include "vsnet_socketbase.h"
25 #include "vsnet_thread.h"
26 
27 #include <queue>
28 
30 {
31 protected:
32  AddressIP _srv_ip; //own IP address structure of this server
33 
34 public: ServerSocket( int fd, const AddressIP &adr, const char *socktype, SocketSet &set ) :
35  VsnetSocketBase( fd, socktype, set )
36  {
37  _srv_ip = adr;
38  }
39 
40  inline const AddressIP& get_adr() const
41  {
42  return _srv_ip;
43  }
44 
45  virtual SOCKETALT acceptNewConn() = 0;
46 
47  friend std::ostream&operator<<( std::ostream &ostr, const ServerSocket &s );
48  friend bool operator==( const ServerSocket &l, const ServerSocket &r );
49 
50 protected:
51  virtual void child_disconnect( const char *s );
52 
53 private: ServerSocket();
54  ServerSocket( const ServerSocket &orig );
55  ServerSocket& operator=( const ServerSocket &orig );
56 };
57 
59 {
60 public: ServerSocketTCP( int fd, const AddressIP &adr, SocketSet &set );
61 
62  virtual bool isActive();
63 
64 //Accept a new connection
65  virtual SOCKETALT acceptNewConn();
66 
67  virtual bool lower_selected( int datalen = -1 );
68 
69 private:
70  std::queue< SOCKETALT >_accepted_connections;
71  VSMutex _ac_mx;
72 
73 private: ServerSocketTCP();
74  ServerSocketTCP( const ServerSocketTCP &orig );
75  ServerSocketTCP& operator=( const ServerSocketTCP &orig );
76 };
77 
79 {
80 public: ServerSocketUDP( int fd, const AddressIP &adr, SocketSet &set );
81 
82  virtual bool isActive();
83 
84 //Accept a new connection
85  virtual SOCKETALT acceptNewConn();
86 
87 //Can't happen
88  virtual bool lower_selected( int datalen = -1 )
89  {
90  return false;
91  }
92 
93 private: ServerSocketUDP();
94  ServerSocketUDP( const ServerSocketUDP &orig );
95  ServerSocketUDP& operator=( const ServerSocketUDP &orig );
96 };
97 
98 #endif /* VSNET_SERVERSOCKET_H */
99