From 6f1e42e6e06e44858b062437ba368e4036973141 Mon Sep 17 00:00:00 2001 From: Nick Little Date: Mon, 20 Apr 2020 21:08:45 -0500 Subject: [PATCH] Add github workflow --- .github/workflows/build.yml | 39 +++++++++++++++++++++++++++++++++++++ .gitignore | 5 +++-- Makefile | 13 +++++++++---- src/smbb/IPAddress.cxx | 4 ++-- src/smbb/IPSocket.h | 21 ++++++++++++++------ test/UnitTests.cxx | 10 ++++++---- 6 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..17ae51b --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,39 @@ +name: Build + +on: [push] + +jobs: + linux: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - name: Run tests + run: make clean check + + windows: + + runs-on: windows-latest + + steps: + - uses: actions/checkout@v1 + + - name: Add cl.exe to PATH + # uses: microsoft/setup-msbuild@v1 + uses: seanmiddleditch/gha-setup-vsdevenv@v1 + + - name: Run tests + # run: msbuild -p:WindowsTargetPlatformVersion=10 test/UnitTests.vcxproj + run: make CXX="cl.exe" CXXFLAGS="-W4" LDLIBS="ws2_32.lib iphlpapi.lib qwave.lib" clean check + + macos: + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v1 + + - name: Run tests + run: make CXX="clang++ -std=c++11" LDLIBS=-ldl clean check diff --git a/.gitignore b/.gitignore index 632033e..24c226c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,9 @@ Debug *.VC.*db .vs -# Makefile files +# Makefile created files obj -UnitTests +*.a +*.exe *.log diff --git a/Makefile b/Makefile index e1a8226..2a4464d 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,14 @@ +# Required variables PROJECT_NAME :=smbb -COMPILE_ARGS :=-D_FILE_OFFSET_BITS=64 -D_LARGE_FILES=1 -LINK_ARGS :=-lrt -ldl +DEFINE_ARGS :=-D_FILE_OFFSET_BITS=64 -D_LARGE_FILES=1 -D_WIN32_WINNT=0x0600 +LDLIBS :=-lrt -ldl DIR :=. +# Optional variables +CPPFLAGS +=$(DEFINE_ARGS) +CXXFLAGS :=-Wall -pedantic -O2 + SRC :=$(wildcard $(DIR)/src/smbb/*.cxx $(DIR)/src/smbb/*/*.cxx) OBJ :=$(patsubst $(DIR)/src/smbb/%.cxx,obj/%.o,$(SRC)) TESTS :=$(patsubst $(DIR)/test/%.cxx,%.exe,$(wildcard $(DIR)/test/*.cxx)) @@ -27,11 +32,11 @@ lib$(PROJECT_NAME).a: $(OBJ) obj/%.o: $(DIR)/src/smbb/%.cxx mkdir -p $(@D) - $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COMPILE_ARGS) -Wall -pedantic -c $< -o $@ + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ # Tests %.exe: $(DIR)/test/%.cxx - $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COMPILE_ARGS) -I$(DIR)/test/catch2 -I$(DIR)/src -Wall -pedantic -o $@ $^ $(LINK_ARGS) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -I$(DIR)/test/catch2 -I$(DIR)/src -o $@ $^ $(LDLIBS) %.exe.run: %.exe ./$< diff --git a/src/smbb/IPAddress.cxx b/src/smbb/IPAddress.cxx index 69f803d..1607391 100644 --- a/src/smbb/IPAddress.cxx +++ b/src/smbb/IPAddress.cxx @@ -48,8 +48,8 @@ int smbb::IPAddress::Parse(IPAddress results[], int resultsSize, const char *add addrinfo *result = NULL; int i = 0; - if (!address && !service) - service = ""; + if (!address && (!service || !service[0])) + service = "0"; info.ai_flags = (bindable ? AI_PASSIVE : 0) | AI_V4MAPPED; info.ai_family = family; diff --git a/src/smbb/IPSocket.h b/src/smbb/IPSocket.h index f0cb17b..fee23df 100644 --- a/src/smbb/IPSocket.h +++ b/src/smbb/IPSocket.h @@ -63,6 +63,12 @@ SOFTWARE. #define GET_OPTION_TYPE(NORMAL_TYPE, WINDOWS_TYPE) NORMAL_TYPE, NORMAL_TYPE #endif +// BSD IPv6 +#if !defined(IPV6_ADD_MEMBERSHIP) && defined(IPV6_JOIN_GROUP) +#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP +#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP +#endif + #include "utilities/Inline.h" #include "utilities/StaticCast.h" @@ -404,8 +410,8 @@ class IPSocket { } else #endif - if ((checkResult & SELECT_CAN_WRITE) != 0 && FD_ISSET(socket._handle, &_writeSet) == 0) - checkResult = static_cast(checkResult & ~SELECT_CAN_WRITE); + if ((checkResult & SELECT_CAN_WRITE) != 0 && FD_ISSET(socket._handle, &_writeSet) == 0) + checkResult = static_cast(checkResult & ~SELECT_CAN_WRITE); if ((checkResult & SELECT_CAN_READ) != 0 && FD_ISSET(socket._handle, &_readSet) == 0) checkResult = static_cast(checkResult & ~SELECT_CAN_READ); @@ -511,6 +517,9 @@ class IPSocket { } #endif // SMBB_NO_POLL +// TODO: kqueue on BSD/mac os +// TODO: epoll on Linux + private: #if !defined(SMBB_NO_SOCKET_MSG) // Helpers to get the recvmmsg and sendmmsg functions @@ -1248,7 +1257,7 @@ class IPSocket { } #endif // SMBB_NO_SOCKET_MSG - // Gets the number of hops value for outgoing multicast packets + // Gets the number of hops value (TTL) for outgoing multicast packets int GetMulticastHops() const { int hops = -1; @@ -1258,7 +1267,7 @@ class IPSocket { return GetOptionInternalDefault(IPPROTO_IPV6, IPV6_MULTICAST_HOPS, hops); } - // Sets the TTL value of the socket for outgoing unicast packets + // Sets the number of hops value (TTL) for outgoing multicast packets Chainable SetMulticastHops(int value) { if (SetOptionInternal(IPPROTO_IP, IP_MULTICAST_TTL, value)) return Chainable(this, true); @@ -1266,7 +1275,7 @@ class IPSocket { return Chainable(this, SetOptionInternal(IPPROTO_IPV6, IPV6_MULTICAST_HOPS, value)); } - // Gets the number of hops value for outgoing multicast packets + // Gets whether or not loopback is enabled for outgoing multicast packets bool GetMulticastLoopback() const { int loopback = 0; @@ -1276,7 +1285,7 @@ class IPSocket { return GetOptionInternalDefault(IPPROTO_IPV6, IPV6_MULTICAST_LOOP, loopback) != 0; } - // Sets the TTL value of the socket for outgoing unicast packets + // Sets whether or not loopback is enabled for outgoing multicast packets Chainable SetMulticastLoopback(bool value = true) { if (SetOptionInternal(IPPROTO_IP, IP_MULTICAST_LOOP, value ? 1 : 0)) return Chainable(this, true); diff --git a/test/UnitTests.cxx b/test/UnitTests.cxx index f85fe6e..1ba725f 100644 --- a/test/UnitTests.cxx +++ b/test/UnitTests.cxx @@ -275,7 +275,8 @@ static void TestTCP(const char *address, const char *port, IPAddressFamily famil static bool TestMulticastUDP(const char *receiveAddress, const char *multicastAddress, const char *sendAddress, IPAddressFamily family = FAMILY_UNSPECIFIED) { IPAddress ipAddress; - REQUIRE(IPAddress::Parse(&ipAddress, 1, receiveAddress, NULL, true, family) > 0); + int lastError = IPAddress::Parse(&ipAddress, 1, receiveAddress, NULL, true, family) > 0 ? 0 : IPSocket::LastError(); + REQUIRE(lastError == 0); // Setup the read socket AutoCloseIPSocket readSocket(ipAddress, UDP, IPSocket::OPEN_AND_BIND); @@ -284,7 +285,8 @@ static bool TestMulticastUDP(const char *receiveAddress, const char *multicastAd DumpAddress(readSocket.GetAddress()); IPAddress multicast; - REQUIRE(IPAddress::Parse(&multicast, 1, multicastAddress, NULL, false, family) > 0); + lastError = IPAddress::Parse(&multicast, 1, multicastAddress, NULL, false, family) > 0 ? 0 : IPSocket::LastError(); + REQUIRE(lastError == 0); REQUIRE(multicast.IsMulticast()); std::cout << "Subscribing to "; DumpAddress(multicast); @@ -514,7 +516,7 @@ SCENARIO ("Select Test", "[IPSocket]") { REQUIRE(connectToIPv6.SetNonblocking()->Connect(localIPv6Socket.GetAddress()) != IPSocket::CONNECT_SUCCESS); sets.AddSocket(connectToIPv4, IPSocket::SELECT_IS_CONNECTED | IPSocket::SELECT_CONNECT_FAILED); - REQUIRE(sets.Wait(10000000) == 1); // Wait up to 10 seconds + REQUIRE(sets.Wait(100000000) == 1); // Wait up to 100 seconds REQUIRE(sets.TestSocket(connectToIPv4, IPSocket::SELECT_IS_CONNECTED | IPSocket::SELECT_CONNECT_FAILED) == IPSocket::SELECT_CONNECT_FAILED); sets.RemoveSocket(connectToIPv4, IPSocket::SELECT_CONNECT_FAILED); @@ -644,7 +646,7 @@ SCENARIO ("Poll Test", "[IPSocket]") { pollSet[0] = IPSocket::PollItem::Make(connectToIPv4, IPSocket::POLL_IS_CONNECTED); REQUIRE(pollSet[0].GetMonitor() == IPSocket::POLL_IS_CONNECTED); - REQUIRE(IPSocket::Poll(pollSet, 1, 2000) >= 0); // Wait up to 3 seconds + REQUIRE(IPSocket::Poll(pollSet, 1, 200000) >= 0); // Wait up to 200 seconds REQUIRE(pollSet[0].HasFailedConnectionResult()); pollSet[0].Disable();