MPD  0.20.18
ServerSocket.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2003-2017 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef MPD_SERVER_SOCKET_HXX
21 #define MPD_SERVER_SOCKET_HXX
22 
23 #include <list>
24 
25 class SocketAddress;
27 class EventLoop;
28 class AllocatedPath;
29 class OneServerSocket;
30 
34 class ServerSocket {
35  friend class OneServerSocket;
36 
37  EventLoop &loop;
38 
39  std::list<OneServerSocket> sockets;
40 
41  unsigned next_serial;
42 
43 public:
44  ServerSocket(EventLoop &_loop);
45  ~ServerSocket();
46 
48  return loop;
49  }
50 
51 private:
52  OneServerSocket &AddAddress(SocketAddress address);
53  OneServerSocket &AddAddress(AllocatedSocketAddress &&address);
54 
60  void AddPortIPv4(unsigned port);
61 
67  void AddPortIPv6(unsigned port);
68 
69 public:
78  void AddPort(unsigned port);
79 
90  void AddHost(const char *hostname, unsigned port);
91 
100  void AddPath(AllocatedPath &&path);
101 
109  void AddFD(int fd);
110 
114  void Open();
115 
116  void Close();
117 
118 protected:
119  virtual void OnAccept(int fd, SocketAddress address, int uid) = 0;
120 };
121 
122 #endif
void Open()
Throws #std::runtime_error on error.
An OO wrapper for struct sockaddr.
void AddFD(int fd)
Add a socket descriptor that is accepting connections.
An event loop that polls for events on file/socket descriptors.
Definition: Loop.hxx:52
A path name in the native file system character set.
ServerSocket(EventLoop &_loop)
A socket that accepts incoming stream connections (e.g.
void AddHost(const char *hostname, unsigned port)
Resolves a host name, and adds listeners on all addresses in the result set.
EventLoop & GetEventLoop()
virtual void OnAccept(int fd, SocketAddress address, int uid)=0
void AddPort(unsigned port)
Add a listener on a port on all interfaces.
void AddPath(AllocatedPath &&path)
Add a listener on a Unix domain socket.
friend class OneServerSocket