deskflow/src/lib/arch/unix/ArchNetworkBSD.h
Nick Bolton 9eeb1cb7ee
Introduce 'Advanced' tab to Preferences window (#7419)
* Add QML and QtQuick deps

* Keep only Qt declarative

* Fixed delcarative package name

* Use `qt6-qtdeclarative` on OpenSUSE

* Fixed warnings

* Introduce tabs for settings and make some settings easier to understand

* Further reorganization of settings UI

* Revert config.yml

* Show Qt version in config

* Remove custom font

* Improve wording of elevate privs

* Fixed window sizes and default tabs

* Save main window size and position

* Fixed slot warning

* Fixed hacky use of validators

* Make activation cancel more intuitive

* Save window state in dtor and add try-catch to prevent exceptions propagating

* Fixed consistency of fatal messages

* Improve color conssitency and add tooltip

* Clean up styles and weird layout

* Move config files to new gui lib

* Core interface integ tests

* Rename `Config` to `ConfigScopes`

* Add 'Schoeneman' to cspell

* Fixed incorrect `Config` (should be `ConfigScopes`)

* Fixed typo

* Missed a spot

* Delete accidentally re-added file

* Fixed formatting

* Add short opt

* Coverage for `AppConfig`

* Update ChangeLog

* Remove redundant includes

* Fixed date

* Remove rogue include
2024-08-01 01:13:01 +01:00

134 lines
4.3 KiB
C++

/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "arch/IArchMultithread.h"
#include "arch/IArchNetwork.h"
#include <memory>
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#else
struct sockaddr_storage {
unsigned char ss_len; /* address length */
unsigned char ss_family; /* [XSI] address family */
char __ss_pad1[_SS_PAD1SIZE];
long long __ss_align; /* force structure storage alignment */
char __ss_pad2[_SS_PAD2SIZE];
};
#endif
#if !HAVE_SOCKLEN_T
typedef int socklen_t;
#endif
#include <poll.h>
#define ARCH_NETWORK ArchNetworkBSD
#define TYPED_ADDR(type_, addr_) (reinterpret_cast<type_ *>(&addr_->m_addr))
// old systems may use char* for [gs]etsockopt()'s optval argument.
// this should be void on modern systems but char is forwards
// compatible so we always use it.
typedef char optval_t;
class ArchSocketImpl {
public:
int m_fd;
int m_refCount;
};
class ArchNetAddressImpl {
public:
ArchNetAddressImpl() : m_len(sizeof(m_addr)) {}
public:
struct sockaddr_storage m_addr;
socklen_t m_len;
};
//! Berkeley (BSD) sockets implementation of IArchNetwork
class ArchNetworkBSD : public IArchNetwork {
public:
struct Deps {
virtual ~Deps() = default;
virtual void sleep(double);
virtual int poll(struct pollfd *, nfds_t, int);
virtual std::shared_ptr<struct pollfd[]> makePollFD(nfds_t);
virtual ssize_t read(int, void *, size_t);
virtual void testCancelThread();
};
explicit ArchNetworkBSD() : m_deps(s_deps) {}
explicit ArchNetworkBSD(Deps &deps) : m_deps(deps) {}
ArchNetworkBSD(ArchNetworkBSD const &) = delete;
ArchNetworkBSD(ArchNetworkBSD &&) = delete;
~ArchNetworkBSD() override;
ArchNetworkBSD &operator=(ArchNetworkBSD const &) = delete;
ArchNetworkBSD &operator=(ArchNetworkBSD &&) = delete;
void init() override;
// IArchNetwork overrides
ArchSocket newSocket(EAddressFamily, ESocketType) override;
ArchSocket copySocket(ArchSocket s) override;
void closeSocket(ArchSocket s) override;
void closeSocketForRead(ArchSocket s) override;
void closeSocketForWrite(ArchSocket s) override;
void bindSocket(ArchSocket s, ArchNetAddress addr) override;
void listenOnSocket(ArchSocket s) override;
ArchSocket acceptSocket(ArchSocket s, ArchNetAddress *addr) override;
bool connectSocket(ArchSocket s, ArchNetAddress name) override;
int pollSocket(PollEntry[], int num, double timeout) override;
void unblockPollSocket(ArchThread thread) override;
size_t readSocket(ArchSocket s, void *buf, size_t len) override;
size_t writeSocket(ArchSocket s, const void *buf, size_t len) override;
void throwErrorOnSocket(ArchSocket) override;
bool setNoDelayOnSocket(ArchSocket, bool noDelay) override;
bool setReuseAddrOnSocket(ArchSocket, bool reuse) override;
std::string getHostName() override;
ArchNetAddress newAnyAddr(EAddressFamily) override;
ArchNetAddress copyAddr(ArchNetAddress) override;
std::vector<ArchNetAddress> nameToAddr(const std::string &) override;
void closeAddr(ArchNetAddress) override;
std::string addrToName(ArchNetAddress) override;
std::string addrToString(ArchNetAddress) override;
EAddressFamily getAddrFamily(ArchNetAddress) override;
void setAddrPort(ArchNetAddress, int port) override;
int getAddrPort(ArchNetAddress) override;
bool isAnyAddr(ArchNetAddress) override;
bool isEqualAddr(ArchNetAddress, ArchNetAddress) override;
private:
const int *getUnblockPipe();
const int *getUnblockPipeForThread(ArchThread);
void setBlockingOnSocket(int fd, bool blocking);
void throwError(int);
void throwNameError(int);
private:
static Deps s_deps;
Deps &m_deps;
ArchMutex m_mutex{};
};