blob: 30eda78789115b3ab256ab779593a55e57737c73 [file] [log] [blame]
Pierre Ossman5d055462018-05-03 14:04:38 +02001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 * Copyright (c) 2012 University of Oslo. All Rights Reserved.
3 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
19
20// -=- UnixSocket.h - base-class for UNIX stream sockets.
21// This header also defines the UnixListener class, used
22// to listen for incoming socket connections over UNIX
23//
24// NB: Any file descriptors created by the UnixSocket or
25// UnixListener classes are close-on-exec if the OS supports
26// it. UnixSockets initialised with a caller-supplied fd
27// are NOT set to close-on-exec.
28
29#ifndef __NETWORK_UNIX_SOCKET_H__
30#define __NETWORK_UNIX_SOCKET_H__
31
32#include <network/Socket.h>
33
34namespace network {
35
36 class UnixSocket : public Socket {
37 public:
38 UnixSocket(int sock, bool close=true);
39 UnixSocket(const char *name);
40 virtual ~UnixSocket();
41
42 virtual int getMyPort();
43
44 virtual char* getPeerAddress();
45 virtual int getPeerPort();
46 virtual char* getPeerEndpoint();
47 virtual bool sameMachine();
48
49 virtual void shutdown();
50 virtual bool cork(bool enable);
51
52 private:
53 bool closeFd;
54 };
55
56 class UnixListener : public SocketListener {
57 public:
58 UnixListener(const char *listenaddr, int mode);
59 UnixListener(int sock);
60 virtual ~UnixListener();
61
62 virtual void shutdown();
63 virtual Socket* accept();
64
65 int getMyPort();
66 };
67
68}
69
70#endif // __NETWORK_UNIX_SOCKET_H__