diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..82f0b07 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,72 @@ +// Copyright (C) 2005 - 2026 Settlers Freaks +// +// SPDX-License-Identifier: GPL-2.0-or-later + +dockerRegistry = "registry.mytrap.de/" +dockerCredentials = "gitlab-Flow86" +dockerImage = "rttr/cross-compiler/linux/linux-amd64-docker:master" + +pipeline { + agent { + label "docker" + } + + options { + buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '14', daysToKeepStr: '14', numToKeepStr: '180')) + disableConcurrentBuilds() + } + + environment { + DEBIAN_FRONTEND = 'noninteractive' + } + + stages { + stage('checkout') { + steps { + dir('libendian') { + checkout scm: [ + $class: 'GitSCM', + branches: [[name: '*/master']], + doGenerateSubmoduleConfigurations: false, + extensions: [ + [$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: true, recursiveSubmodules: true, reference: '', trackingSubmodules: false], + [$class: 'GitLFSPull'], + [$class: 'AuthorInChangelog'], + [$class: 'CleanCheckout'] + ], + submoduleCfg: [], + userRemoteConfigs: [[name: 'libendian', url: 'https://github.com/Return-To-The-Roots/libendian.git']] + ] + } + } + } + stage('build') { + steps { + withDockerRegistry( registry: [credentialsId: dockerCredentials, url: 'https://'+dockerRegistry ] ) { + withDockerContainer( + image: dockerRegistry+dockerImage, + args: " \ + --pull=always \ + -v $HOME/.ccache:/.ccache \ + ") { + sh """set -ex + rm -rf build || true + export LIBENDIAN_DIR="\$(pwd)/libendian" + export GENERATOR="Unix Makefiles" + tools/ci/build.sh Debug "" tests + """ + } + } + } + } + } + post { + failure { + mail to: 'sf-team@siedler25.org', + subject: "Failed Pipeline: ${currentBuild.fullDisplayName}", + body: "Pipeline failed: ${env.BUILD_URL}" + } + cleanup { + sh 'rm -rf build' + } +}} diff --git a/libs/network/include/s25util/Socket.h b/libs/network/include/s25util/Socket.h index f1fb71b..7342dc4 100644 --- a/libs/network/include/s25util/Socket.h +++ b/libs/network/include/s25util/Socket.h @@ -67,18 +67,24 @@ class ResolvedAddr class PeerAddr { - address_t addr; + address_t addr{}; + socklen_t addrLen = 0; public: - /// Uninitilized value! - PeerAddr() = default; //-V730 + /// Empty address with room for any address type, e.g. to be filled by Socket::Recv + PeerAddr() = default; /// Initializes the address to a broadcast on the given port PeerAddr(unsigned short port); std::string GetIp() const; sockaddr* GetAddr(); const sockaddr* GetAddr() const; - int GetSize() const { return sizeof(addr); } + /// Size of the contained address (suitable for sendto) + socklen_t GetSize() const { return addrLen; } + /// Capacity of the underlying storage (suitable for recvfrom) + static constexpr socklen_t GetCapacity() { return sizeof(address_t); } + /// Set the size of the contained address, e.g. after it has been filled by recvfrom + void SetSize(socklen_t size) { addrLen = size; } }; /// Socket-Wrapper-Klasse für portable TCP/IP-Verbindungen diff --git a/libs/network/src/Socket.cpp b/libs/network/src/Socket.cpp index 8898c99..c9c4cf1 100644 --- a/libs/network/src/Socket.cpp +++ b/libs/network/src/Socket.cpp @@ -111,7 +111,7 @@ ResolvedAddr::~ResolvedAddr() } } -PeerAddr::PeerAddr(unsigned short port) +PeerAddr::PeerAddr(unsigned short port) : addrLen(sizeof(sockaddr_in)) { addr.sa_in.sin_family = AF_INET; addr.sa_in.sin_addr.s_addr = INADDR_BROADCAST; @@ -680,8 +680,10 @@ int Socket::Recv(void* const buffer, const int length, PeerAddr& addr) const if(!isValid()) return -1; - socklen_t addrLen = addr.GetSize(); - return recvfrom(socket_, reinterpret_cast(buffer), length, 0, addr.GetAddr(), &addrLen); + socklen_t addrLen = PeerAddr::GetCapacity(); + const int result = recvfrom(socket_, reinterpret_cast(buffer), length, 0, addr.GetAddr(), &addrLen); + addr.SetSize(result >= 0 ? addrLen : 0); + return result; } /**