Skip to content

Commit

Permalink
Merge branch 'c++11' of github.com:CendioOssman/tigervnc
Browse files Browse the repository at this point in the history
  • Loading branch information
CendioOssman committed Jun 24, 2024
2 parents 0e9a00e + 02c6a1b commit 1b6d559
Show file tree
Hide file tree
Showing 288 changed files with 2,013 additions and 2,028 deletions.
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckVariableExists)
include(CheckTypeSize)
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
Expand Down Expand Up @@ -69,12 +70,16 @@ IF(CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-D_DEBUG)
ENDIF()

# Make sure we get a sane C version
# Make sure we get a sane C and C++ version
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")

# Tell the compiler to be stringent
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat=2 -Wvla")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat=2 -Wvla")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
# Make sure we catch these issues whilst developing
IF(CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
Expand Down Expand Up @@ -182,6 +187,13 @@ if(ENABLE_H264)
add_definitions("-DHAVE_H264")
set(H264_LIBS "WIN") # may be LIBAV in the future
set(H264_LIBRARIES ole32 mfplat mfuuid wmcodecdspuuid)

set(CMAKE_REQUIRED_LIBRARIES ${H264_LIBRARIES})
check_variable_exists(CLSID_VideoProcessorMFT HAVE_VIDEO_PROCESSOR_MFT)
set(CMAKE_REQUIRED_LIBRARIES)
if(HAVE_VIDEO_PROCESSOR_MFT)
add_definitions("-DHAVE_VIDEO_PROCESSOR_MFT")
endif()
else()
find_package(Ffmpeg)
if (AVCODEC_FOUND AND AVUTIL_FOUND AND SWSCALE_FOUND)
Expand Down
14 changes: 7 additions & 7 deletions common/network/Socket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ bool network::isSocketListening(int sock)
}

Socket::Socket(int fd)
: instream(0), outstream(0),
: instream(nullptr), outstream(nullptr),
isShutdown_(false), queryConnection(false)
{
initSockets();
setFd(fd);
}

Socket::Socket()
: instream(0), outstream(0),
: instream(nullptr), outstream(nullptr),
isShutdown_(false), queryConnection(false)
{
initSockets();
Expand Down Expand Up @@ -128,14 +128,14 @@ void Socket::setFd(int fd)
isShutdown_ = false;
}

SocketListener::SocketListener(int fd)
: fd(fd), filter(0)
SocketListener::SocketListener(int fd_)
: fd(fd_), filter(nullptr)
{
initSockets();
}

SocketListener::SocketListener()
: fd(-1), filter(0)
: fd(-1), filter(nullptr)
{
initSockets();
}
Expand All @@ -160,14 +160,14 @@ Socket* SocketListener::accept() {
int new_sock = -1;

// Accept an incoming connection
if ((new_sock = ::accept(fd, 0, 0)) < 0)
if ((new_sock = ::accept(fd, nullptr, nullptr)) < 0)
throw SocketException("unable to accept new connection", errorNumber);

// Create the socket object & check connection is allowed
Socket* s = createSocket(new_sock);
if (filter && !filter->verifyConnection(s)) {
delete s;
return NULL;
return nullptr;
}

return s;
Expand Down
48 changes: 24 additions & 24 deletions common/network/TcpSocket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,17 @@ TcpSocket::TcpSocket(const char *host, int port)
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;
hints.ai_canonname = nullptr;
hints.ai_addr = nullptr;
hints.ai_next = nullptr;

if ((result = getaddrinfo(host, NULL, &hints, &ai)) != 0) {
if ((result = getaddrinfo(host, nullptr, &hints, &ai)) != 0) {
throw GAIException("unable to resolve host by name", result);
}

sock = -1;
err = 0;
for (current = ai; current != NULL; current = current->ai_next) {
for (current = ai; current != nullptr; current = current->ai_next) {
int family;
vnc_sockaddr_t sa;
socklen_t salen;
Expand Down Expand Up @@ -168,7 +168,7 @@ TcpSocket::TcpSocket(const char *host, int port)
else
sa.u.sin6.sin6_port = htons(port);

getnameinfo(&sa.u.sa, salen, ntop, sizeof(ntop), NULL, 0, NI_NUMERICHOST);
getnameinfo(&sa.u.sa, salen, ntop, sizeof(ntop), nullptr, 0, NI_NUMERICHOST);
vlog.debug("Connecting to %s [%s] port %d", host, ntop, port);

sock = socket (family, SOCK_STREAM, 0);
Expand Down Expand Up @@ -228,7 +228,7 @@ const char* TcpSocket::getPeerAddress() {
buffer[0] = '[';

ret = getnameinfo(&sa.u.sa, sizeof(sa.u.sin6),
buffer + 1, sizeof(buffer) - 2, NULL, 0,
buffer + 1, sizeof(buffer) - 2, nullptr, 0,
NI_NUMERICHOST);
if (ret != 0) {
vlog.error("unable to convert peer name to a string");
Expand All @@ -244,7 +244,7 @@ const char* TcpSocket::getPeerAddress() {
char *name;

name = inet_ntoa(sa.u.sin.sin_addr);
if (name == NULL) {
if (name == nullptr) {
vlog.error("unable to convert peer name to a string");
return "(N/A)";
}
Expand Down Expand Up @@ -338,8 +338,8 @@ TcpListener::TcpListener(const struct sockaddr *listenaddr,
listen(sock);
}

Socket* TcpListener::createSocket(int fd) {
return new TcpSocket(fd);
Socket* TcpListener::createSocket(int fd_) {
return new TcpSocket(fd_);
}

std::list<std::string> TcpListener::getMyAddresses() {
Expand All @@ -352,15 +352,15 @@ std::list<std::string> TcpListener::getMyAddresses() {
hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;
hints.ai_canonname = nullptr;
hints.ai_addr = nullptr;
hints.ai_next = nullptr;

// Windows doesn't like NULL for service, so specify something
if ((getaddrinfo(NULL, "1", &hints, &ai)) != 0)
if ((getaddrinfo(nullptr, "1", &hints, &ai)) != 0)
return result;

for (current= ai; current != NULL; current = current->ai_next) {
for (current= ai; current != nullptr; current = current->ai_next) {
char addr[INET6_ADDRSTRLEN];

switch (current->ai_family) {
Expand All @@ -377,7 +377,7 @@ std::list<std::string> TcpListener::getMyAddresses() {
}

getnameinfo(current->ai_addr, current->ai_addrlen, addr, INET6_ADDRSTRLEN,
NULL, 0, NI_NUMERICHOST);
nullptr, 0, NI_NUMERICHOST);

result.push_back(addr);
}
Expand Down Expand Up @@ -417,7 +417,7 @@ void network::createLocalTcpListeners(std::list<SocketListener*> *listeners,
ai[1].ai_family = sa[1].u.sin6.sin6_family;
ai[1].ai_addr = &sa[1].u.sa;
ai[1].ai_addrlen = sizeof(sa[1].u.sin6);
ai[1].ai_next = NULL;
ai[1].ai_next = nullptr;

createTcpListeners(listeners, ai);
}
Expand All @@ -436,9 +436,9 @@ void network::createTcpListeners(std::list<SocketListener*> *listeners,
hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;
hints.ai_canonname = nullptr;
hints.ai_addr = nullptr;
hints.ai_next = nullptr;

snprintf (service, sizeof (service) - 1, "%d", port);
service[sizeof (service) - 1] = '\0';
Expand All @@ -463,7 +463,7 @@ void network::createTcpListeners(std::list<SocketListener*> *listeners,

initSockets();

for (current = ai; current != NULL; current = current->ai_next) {
for (current = ai; current != nullptr; current = current->ai_next) {
switch (current->ai_family) {
case AF_INET:
if (!UseIPv4)
Expand Down Expand Up @@ -629,7 +629,7 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) {
parts[0].erase(parts.size()-1, 1);
}

if ((result = getaddrinfo (parts[0].c_str(), NULL, &hints, &ai)) != 0) {
if ((result = getaddrinfo (parts[0].c_str(), nullptr, &hints, &ai)) != 0) {
throw GAIException("unable to resolve host by name", result);
}

Expand Down Expand Up @@ -711,11 +711,11 @@ std::string TcpFilter::patternToStr(const TcpFilter::Pattern& p) {

if (p.address.u.sa.sa_family == AF_INET) {
getnameinfo(&p.address.u.sa, sizeof(p.address.u.sin),
addr, sizeof(addr), NULL, 0, NI_NUMERICHOST);
addr, sizeof(addr), nullptr, 0, NI_NUMERICHOST);
} else if (p.address.u.sa.sa_family == AF_INET6) {
addr[0] = '[';
getnameinfo(&p.address.u.sa, sizeof(p.address.u.sin6),
addr + 1, sizeof(addr) - 2, NULL, 0, NI_NUMERICHOST);
addr + 1, sizeof(addr) - 2, nullptr, 0, NI_NUMERICHOST);
strcat(addr, "]");
} else
addr[0] = '\0';
Expand Down
10 changes: 5 additions & 5 deletions common/network/TcpSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ namespace network {
TcpSocket(int sock);
TcpSocket(const char *name, int port);

virtual const char* getPeerAddress();
virtual const char* getPeerEndpoint();
const char* getPeerAddress() override;
const char* getPeerEndpoint() override;

protected:
bool enableNagles(bool enable);
Expand All @@ -68,12 +68,12 @@ namespace network {
TcpListener(const struct sockaddr *listenaddr, socklen_t listenaddrlen);
TcpListener(int sock);

virtual int getMyPort();
int getMyPort() override;

static std::list<std::string> getMyAddresses();

protected:
virtual Socket* createSocket(int fd);
Socket* createSocket(int fd) override;
};

void createLocalTcpListeners(std::list<SocketListener*> *listeners,
Expand All @@ -97,7 +97,7 @@ namespace network {
TcpFilter(const char* filter);
virtual ~TcpFilter();

virtual bool verifyConnection(Socket* s);
bool verifyConnection(Socket* s) override;

typedef enum {Accept, Reject, Query} Action;
struct Pattern {
Expand Down
4 changes: 2 additions & 2 deletions common/network/UnixSocket.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ UnixListener::~UnixListener()
unlink(addr.sun_path);
}

Socket* UnixListener::createSocket(int fd) {
return new UnixSocket(fd);
Socket* UnixListener::createSocket(int fd_) {
return new UnixSocket(fd_);
}

int UnixListener::getMyPort() {
Expand Down
8 changes: 4 additions & 4 deletions common/network/UnixSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ namespace network {
UnixSocket(int sock);
UnixSocket(const char *name);

virtual const char* getPeerAddress();
virtual const char* getPeerEndpoint();
const char* getPeerAddress() override;
const char* getPeerEndpoint() override;
};

class UnixListener : public SocketListener {
public:
UnixListener(const char *listenaddr, int mode);
virtual ~UnixListener();

int getMyPort();
int getMyPort() override;

protected:
virtual Socket* createSocket(int fd);
Socket* createSocket(int fd) override;
};

}
Expand Down
8 changes: 4 additions & 4 deletions common/os/Mutex.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Mutex::Mutex()
int ret;

systemMutex = new pthread_mutex_t;
ret = pthread_mutex_init((pthread_mutex_t*)systemMutex, NULL);
ret = pthread_mutex_init((pthread_mutex_t*)systemMutex, nullptr);
if (ret != 0)
throw rdr::SystemException("Failed to create mutex", ret);
#endif
Expand Down Expand Up @@ -84,9 +84,9 @@ void Mutex::unlock()
#endif
}

Condition::Condition(Mutex* mutex)
Condition::Condition(Mutex* mutex_)
{
this->mutex = mutex;
this->mutex = mutex_;

#ifdef WIN32
systemCondition = new CONDITION_VARIABLE;
Expand All @@ -95,7 +95,7 @@ Condition::Condition(Mutex* mutex)
int ret;

systemCondition = new pthread_cond_t;
ret = pthread_cond_init((pthread_cond_t*)systemCondition, NULL);
ret = pthread_cond_init((pthread_cond_t*)systemCondition, nullptr);
if (ret != 0)
throw rdr::SystemException("Failed to create condition variable", ret);
#endif
Expand Down
16 changes: 10 additions & 6 deletions common/os/Thread.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

using namespace os;

Thread::Thread() : running(false), threadId(NULL)
Thread::Thread() : running(false), threadId(nullptr)
{
mutex = new Mutex;

Expand Down Expand Up @@ -64,8 +64,8 @@ void Thread::start()
AutoMutex a(mutex);

#ifdef WIN32
*(HANDLE*)threadId = CreateThread(NULL, 0, startRoutine, this, 0, NULL);
if (*(HANDLE*)threadId == NULL)
*(HANDLE*)threadId = CreateThread(nullptr, 0, startRoutine, this, 0, nullptr);
if (*(HANDLE*)threadId == nullptr)
throw rdr::SystemException("Failed to create thread", GetLastError());
#else
int ret;
Expand All @@ -78,9 +78,9 @@ void Thread::start()
if (ret != 0)
throw rdr::SystemException("Failed to mask signals", ret);

ret = pthread_create((pthread_t*)threadId, NULL, startRoutine, this);
ret = pthread_create((pthread_t*)threadId, nullptr, startRoutine, this);

pthread_sigmask(SIG_SETMASK, &old, NULL);
pthread_sigmask(SIG_SETMASK, &old, nullptr);

if (ret != 0)
throw rdr::SystemException("Failed to create thread", ret);
Expand All @@ -103,7 +103,7 @@ void Thread::wait()
#else
int ret;

ret = pthread_join(*(pthread_t*)threadId, NULL);
ret = pthread_join(*(pthread_t*)threadId, nullptr);
if (ret != 0)
throw rdr::SystemException("Failed to join thread", ret);
#endif
Expand Down Expand Up @@ -165,5 +165,9 @@ void* Thread::startRoutine(void* data)
self->running = false;
self->mutex->unlock();

#ifdef WIN32
return 0;
#else
return nullptr;
#endif
}
Loading

0 comments on commit 1b6d559

Please sign in to comment.