Skip to content

Commit e371290

Browse files
Add github workflow
1 parent 0c11c7a commit e371290

6 files changed

Lines changed: 74 additions & 18 deletions

File tree

.github/workflows/build.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build
2+
3+
on: [push]
4+
5+
jobs:
6+
linux:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v1
12+
13+
- name: Run tests
14+
run: make clean check
15+
16+
windows:
17+
18+
runs-on: windows-latest
19+
20+
steps:
21+
- uses: actions/checkout@v1
22+
23+
- name: Add cl.exe to PATH
24+
# uses: microsoft/setup-msbuild@v1
25+
uses: seanmiddleditch/gha-setup-vsdevenv@v1
26+
27+
- name: Run tests
28+
# run: msbuild -p:WindowsTargetPlatformVersion=10 test/UnitTests.vcxproj
29+
run: make CXX="cl.exe" CXXFLAGS="-W4" LDLIBS="ws2_32.lib iphlpapi.lib qwave.lib" clean check
30+
31+
macos:
32+
33+
runs-on: macos-latest
34+
35+
steps:
36+
- uses: actions/checkout@v1
37+
38+
- name: Run tests
39+
run: make CXX="clang++ -std=c++11" LDLIBS=-ldl clean check

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ Debug
55
*.VC.*db
66
.vs
77

8-
# Makefile files
8+
# Makefile created files
99
obj
10-
UnitTests
10+
*.a
11+
*.exe
1112

1213
*.log

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11

2+
# Required variables
23
PROJECT_NAME :=smbb
3-
COMPILE_ARGS :=-D_FILE_OFFSET_BITS=64 -D_LARGE_FILES=1
4-
LINK_ARGS :=-lrt -ldl
4+
DEFINE_ARGS :=-D_FILE_OFFSET_BITS=64 -D_LARGE_FILES=1 -D_WIN32_WINNT=0x0600
5+
LDLIBS :=-lrt -ldl
56
DIR :=.
67

8+
# Optional variables
9+
CPPFLAGS +=$(DEFINE_ARGS)
10+
CXXFLAGS :=-Wall -pedantic -O2
11+
712
SRC :=$(wildcard $(DIR)/src/smbb/*.cxx $(DIR)/src/smbb/*/*.cxx)
813
OBJ :=$(patsubst $(DIR)/src/smbb/%.cxx,obj/%.o,$(SRC))
914
TESTS :=$(patsubst $(DIR)/test/%.cxx,%.exe,$(wildcard $(DIR)/test/*.cxx))
@@ -27,11 +32,11 @@ lib$(PROJECT_NAME).a: $(OBJ)
2732

2833
obj/%.o: $(DIR)/src/smbb/%.cxx
2934
mkdir -p $(@D)
30-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COMPILE_ARGS) -Wall -pedantic -c $< -o $@
35+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
3136

3237
# Tests
3338
%.exe: $(DIR)/test/%.cxx
34-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COMPILE_ARGS) -I$(DIR)/test/catch2 -I$(DIR)/src -Wall -pedantic -o $@ $^ $(LINK_ARGS)
39+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -I$(DIR)/test/catch2 -I$(DIR)/src -o $@ $^ $(LDLIBS)
3540

3641
%.exe.run: %.exe
3742
./$<

src/smbb/IPAddress.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ int smbb::IPAddress::Parse(IPAddress results[], int resultsSize, const char *add
4848
addrinfo *result = NULL;
4949
int i = 0;
5050

51-
if (!address && !service)
52-
service = "";
51+
if (!address && (!service || !service[0]))
52+
service = "0";
5353

5454
info.ai_flags = (bindable ? AI_PASSIVE : 0) | AI_V4MAPPED;
5555
info.ai_family = family;

src/smbb/IPSocket.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ SOFTWARE.
6363
#define GET_OPTION_TYPE(NORMAL_TYPE, WINDOWS_TYPE) NORMAL_TYPE, NORMAL_TYPE
6464
#endif
6565

66+
// BSD IPv6
67+
#if !defined(IPV6_ADD_MEMBERSHIP) && defined(IPV6_JOIN_GROUP)
68+
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
69+
#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
70+
#endif
71+
6672
#include "utilities/Inline.h"
6773
#include "utilities/StaticCast.h"
6874

@@ -404,8 +410,8 @@ class IPSocket {
404410
}
405411
else
406412
#endif
407-
if ((checkResult & SELECT_CAN_WRITE) != 0 && FD_ISSET(socket._handle, &_writeSet) == 0)
408-
checkResult = static_cast<SelectValue>(checkResult & ~SELECT_CAN_WRITE);
413+
if ((checkResult & SELECT_CAN_WRITE) != 0 && FD_ISSET(socket._handle, &_writeSet) == 0)
414+
checkResult = static_cast<SelectValue>(checkResult & ~SELECT_CAN_WRITE);
409415

410416
if ((checkResult & SELECT_CAN_READ) != 0 && FD_ISSET(socket._handle, &_readSet) == 0)
411417
checkResult = static_cast<SelectValue>(checkResult & ~SELECT_CAN_READ);
@@ -476,7 +482,7 @@ class IPSocket {
476482

477483
return select(0, NULL, NULL, &exceptSet, &timeout) == 1;
478484
#else
479-
return (_item.revents & POLL_ERROR) != 0;
485+
return (_item.revents & (POLL_ERROR | POLL_DISCONNECTING)) != 0;
480486
#endif
481487
}
482488

@@ -511,6 +517,9 @@ class IPSocket {
511517
}
512518
#endif // SMBB_NO_POLL
513519

520+
// TODO: kqueue on BSD/mac os
521+
// TODO: epoll on Linux
522+
514523
private:
515524
#if !defined(SMBB_NO_SOCKET_MSG)
516525
// Helpers to get the recvmmsg and sendmmsg functions
@@ -1248,7 +1257,7 @@ class IPSocket {
12481257
}
12491258
#endif // SMBB_NO_SOCKET_MSG
12501259

1251-
// Gets the number of hops value for outgoing multicast packets
1260+
// Gets the number of hops value (TTL) for outgoing multicast packets
12521261
int GetMulticastHops() const {
12531262
int hops = -1;
12541263

@@ -1258,15 +1267,15 @@ class IPSocket {
12581267
return GetOptionInternalDefault<GET_OPTION_TYPE(int, DWORD)>(IPPROTO_IPV6, IPV6_MULTICAST_HOPS, hops);
12591268
}
12601269

1261-
// Sets the TTL value of the socket for outgoing unicast packets
1270+
// Sets the number of hops value (TTL) for outgoing multicast packets
12621271
Chainable<bool> SetMulticastHops(int value) {
12631272
if (SetOptionInternal<GET_OPTION_TYPE(int, DWORD)>(IPPROTO_IP, IP_MULTICAST_TTL, value))
12641273
return Chainable<bool>(this, true);
12651274

12661275
return Chainable<bool>(this, SetOptionInternal<GET_OPTION_TYPE(int, DWORD)>(IPPROTO_IPV6, IPV6_MULTICAST_HOPS, value));
12671276
}
12681277

1269-
// Gets the number of hops value for outgoing multicast packets
1278+
// Gets whether or not loopback is enabled for outgoing multicast packets
12701279
bool GetMulticastLoopback() const {
12711280
int loopback = 0;
12721281

@@ -1276,7 +1285,7 @@ class IPSocket {
12761285
return GetOptionInternalDefault<GET_OPTION_TYPE(int, DWORD)>(IPPROTO_IPV6, IPV6_MULTICAST_LOOP, loopback) != 0;
12771286
}
12781287

1279-
// Sets the TTL value of the socket for outgoing unicast packets
1288+
// Sets whether or not loopback is enabled for outgoing multicast packets
12801289
Chainable<bool> SetMulticastLoopback(bool value = true) {
12811290
if (SetOptionInternal<GET_OPTION_TYPE(int, DWORD)>(IPPROTO_IP, IP_MULTICAST_LOOP, value ? 1 : 0))
12821291
return Chainable<bool>(this, true);

test/UnitTests.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ static void TestTCP(const char *address, const char *port, IPAddressFamily famil
275275

276276
static bool TestMulticastUDP(const char *receiveAddress, const char *multicastAddress, const char *sendAddress, IPAddressFamily family = FAMILY_UNSPECIFIED) {
277277
IPAddress ipAddress;
278-
REQUIRE(IPAddress::Parse(&ipAddress, 1, receiveAddress, NULL, true, family) > 0);
278+
int lastError = IPAddress::Parse(&ipAddress, 1, receiveAddress, NULL, true, family) > 0 ? 0 : IPSocket::LastError();
279+
REQUIRE(lastError == 0);
279280

280281
// Setup the read socket
281282
AutoCloseIPSocket readSocket(ipAddress, UDP, IPSocket::OPEN_AND_BIND);
@@ -284,7 +285,8 @@ static bool TestMulticastUDP(const char *receiveAddress, const char *multicastAd
284285
DumpAddress(readSocket.GetAddress());
285286

286287
IPAddress multicast;
287-
REQUIRE(IPAddress::Parse(&multicast, 1, multicastAddress, NULL, false, family) > 0);
288+
lastError = IPAddress::Parse(&multicast, 1, multicastAddress, NULL, false, family) > 0 ? 0 : IPSocket::LastError();
289+
REQUIRE(lastError == 0);
288290
REQUIRE(multicast.IsMulticast());
289291
std::cout << "Subscribing to ";
290292
DumpAddress(multicast);
@@ -644,7 +646,7 @@ SCENARIO ("Poll Test", "[IPSocket]") {
644646

645647
pollSet[0] = IPSocket::PollItem::Make(connectToIPv4, IPSocket::POLL_IS_CONNECTED);
646648
REQUIRE(pollSet[0].GetMonitor() == IPSocket::POLL_IS_CONNECTED);
647-
REQUIRE(IPSocket::Poll(pollSet, 1, 2000) >= 0); // Wait up to 3 seconds
649+
REQUIRE(IPSocket::Poll(pollSet, 1, 2000) >= 0); // Wait up to 2 seconds
648650
REQUIRE(pollSet[0].HasFailedConnectionResult());
649651

650652
pollSet[0].Disable();

0 commit comments

Comments
 (0)