Pierre Ossman | 5d05546 | 2018-05-03 14:04:38 +0200 | [diff] [blame] | 1 | /* 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 | |
| 34 | namespace network { |
| 35 | |
| 36 | class UnixSocket : public Socket { |
| 37 | public: |
Pierre Ossman | d7bbbbf | 2018-05-21 12:06:47 +0200 | [diff] [blame] | 38 | UnixSocket(int sock); |
Pierre Ossman | 5d05546 | 2018-05-03 14:04:38 +0200 | [diff] [blame] | 39 | UnixSocket(const char *name); |
Pierre Ossman | 5d05546 | 2018-05-03 14:04:38 +0200 | [diff] [blame] | 40 | |
Pierre Ossman | 5d05546 | 2018-05-03 14:04:38 +0200 | [diff] [blame] | 41 | virtual char* getPeerAddress(); |
Pierre Ossman | 5d05546 | 2018-05-03 14:04:38 +0200 | [diff] [blame] | 42 | virtual char* getPeerEndpoint(); |
Pierre Ossman | 5d05546 | 2018-05-03 14:04:38 +0200 | [diff] [blame] | 43 | |
Pierre Ossman | 5d05546 | 2018-05-03 14:04:38 +0200 | [diff] [blame] | 44 | virtual bool cork(bool enable); |
Pierre Ossman | 5d05546 | 2018-05-03 14:04:38 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | class UnixListener : public SocketListener { |
| 48 | public: |
| 49 | UnixListener(const char *listenaddr, int mode); |
Pierre Ossman | 5d05546 | 2018-05-03 14:04:38 +0200 | [diff] [blame] | 50 | virtual ~UnixListener(); |
| 51 | |
Pierre Ossman | 5d05546 | 2018-05-03 14:04:38 +0200 | [diff] [blame] | 52 | int getMyPort(); |
Pierre Ossman | 559e8b8 | 2018-05-04 12:44:31 +0200 | [diff] [blame^] | 53 | |
| 54 | protected: |
| 55 | virtual Socket* createSocket(int fd); |
Pierre Ossman | 5d05546 | 2018-05-03 14:04:38 +0200 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | } |
| 59 | |
| 60 | #endif // __NETWORK_UNIX_SOCKET_H__ |