Skip to content

Commit 6165340

Browse files
authored
Merge 0152bc6 into 99dfd60
2 parents 99dfd60 + 0152bc6 commit 6165340

File tree

6 files changed

+118
-136
lines changed

6 files changed

+118
-136
lines changed

.github/workflows/clang-tidy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ jobs:
3131
- name: Run clang-tidy
3232
run: |
3333
cmake -B ${{github.workspace}}/build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
34-
clang-tidy -p ${{github.workspace}}/build inc/cppsocket.hpp test/TestCppSocket.cpp
34+
clang-tidy -p ${{github.workspace}}/build -header-filter=.* inc/cppsocket.hpp test/Testcppsocket.cpp
3535

.github/workflows/cppcheck.yml

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,14 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- uses: actions/checkout@v3
17-
18-
- name: Install cppcheck
19-
run: apt install cppcheck -y
20-
21-
22-
- name: cppcheck
23-
uses: deep5050/cppcheck-action@main
24-
with:
25-
github_token: ${{ secrets.GITHUB_TOKEN}}
26-
enable: all
27-
force_language: c++
28-
std: c++20
29-
platform: unix64
30-
other_options: --bug-hunting -I inc --verbose --suppress=missingIncludeSystem --enable=warning
31-
32-
- name: publish report
33-
uses: mikeal/publish-to-github-action@master
34-
env:
35-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36-
BRANCH_NAME: '--force main'
16+
- uses: actions/checkout@v2
17+
- name: cppcheck
18+
uses: chmorgan/cppcheck-action-jackson@main
19+
with:
20+
github_token: ${{ secrets.GITHUB_TOKEN}}
21+
enable: all
22+
inline_suppression: enable
23+
force_language: c++
24+
platform: unix64
25+
std: c++20
26+
other_options: -I inc --verbose --suppress=missingIncludeSystem

README.md

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,118 +38,120 @@ Socket::initSocket(domain, type, protocol); // creates socket
3838
// create socket from previously created file descriptor
3939
Socket(int);
4040

41-
// create socket
41+
// create socket of the given type
4242
Socket(domain, type, protocol);
43+
44+
4345
```
4446
4547
### TCP server/client
4648
4749
Create a TCP server object for accepting TCP connections.
4850
4951
```cpp
50-
// default no SSL and not IP/port bound
52+
// default no IP/port bound but TCP socket created
5153
TcpServer();
5254
53-
// default SSL and not IP/port bound
54-
TcpServer(const std::string& keyFile, const std::string& certFile);
55-
56-
// No SSL and IP/port bound
57-
explicit TcpServer(const uint16_t port, const std::string& ip = "0.0.0.0", const int backlog = 3);
55+
// TCP socket created, IP/port bound, but not listening
56+
TcpServer(const uint16_t port, const std::string& ipAddr = "0.0.0.0");
5857
59-
/// SSL and IP/port bound
60-
TcpServer(const uint16_t port, const std::string& ip, const std::string& keyFile, const std::string& certFile, const int backlog = 3);
58+
// TCP socket created, IP/port bound, and listening for clients
59+
TcpServer(const std::string& ipAddr, const uint16_t port, const int backlog);
6160
```
6261

6362
Create a TCP client object to connect to a known TCP server.
6463

6564
```cpp
66-
TcpClient(const std::string& ip, const uint16_t port, const bool ssl = false);
67-
explicit TcpClient(const int fd, SSL_CTX* sslctx = nullptr);
65+
// default TCP socket created but no server connection
66+
TcpClient();
67+
68+
// create TcpClient with given TCP socket file descriptor
69+
TcpClient(const int filedescriptor);
70+
71+
// TcpClient connected to a TcpServer IP/port
72+
TcpClient(const std::string& ipAddr, const uint16_t port);
73+
```
74+
75+
Create a SSL TCP Server for accepting SSL TCP clients.
76+
77+
```cpp
78+
// Create a SSL TCP Server not bound to IP/port
79+
SecureTcpServer(const std::string& keyFile, const std::string& certFile);
80+
81+
// Create a SSL TCP Server bound to a given port and IP or default IP
82+
SecureTcpServer(const std::string& keyFile, const std::string& certFile, const uint16_t port, const std::string& ipAddr = "0.0.0.0");
83+
```
84+
85+
Create a SSL TCP client for connecting to SSL TCP servers.
86+
87+
```cpp
88+
// create a SSL TCP client with a given SSL context - used with SecureTcpServer::accept return
89+
SecureTcpClient(const int filedescriptor, SSL_CTX *sslctx);
90+
91+
// create a SSL TCP client connected to a SSL TCP server
92+
SecureTcpClient(const std::string& ipAddr, const uint16_t port);
6893
```
6994
7095
For a BSD-like approach, the following sequence can be followed:
7196
7297
```cpp
7398
// Server
7499
75-
// create server socket
76-
TcpServer server; // add key file and cert file here for secure connection
77-
78-
// bind to port 54321 on IP 0.0.0.0
79-
server.bindAndListen(54321);
100+
// create server socket and bind to all IP and 54321 port
101+
TcpServer server(54321);
80102
103+
// wait for a client connection
81104
TcpClient client = server.accept();
82105
```
83106

84107
```cpp
85108
// Client
86109

87110
// Connect to TCP server on IP 127.0.0.1 and port 54321
88-
TcpClient client("127.0.0.1", 54321); // add key file and cert file here for secure connection
111+
TcpClient client("127.0.0.1", 54321);
89112
```
90113
91114
### UDP server/client
92115
93116
Create a UDP server object for accepting UDP connections.
94117
95118
```cpp
96-
// default constructor creates unbound unsecure UDP server socket
97-
UdpServer();
98-
99-
// default DTLS constructor create unbound UDP server socket ready for DTLS
100-
// NOTE: UdpServer s("", ""); results in unbound unsecure UDP server socket
101-
UdpServer(const std::string& keyFile, const std::string& certFile);
102-
103-
// creates unsecure UDP server socket bound to specific port and IP address (default all host IP)
104-
explicit UdpServer(const uint16_t port, const std::string& ip = "0.0.0.0");
119+
// default no IP/port bound but UDP socket created
120+
UdpServer();
105121
106-
// creates bound UDP server socket ready for DTLS
107-
// NOTE: UdpServer s("", ""); results in unbound unsecure UDP server socket
108-
UdpServer(const uint16_t port, const std::string& ip, const std::string& keyFile, const std::string& certFile);
122+
// UDP server socket created, IP/port bound
123+
UdpServer(const uint16_t port, const std::string &ipAddr = "0.0.0.0");
109124
```
110125

111126
Create a UDP client object to connect to a known UDP server.
112127

113128
```cpp
129+
// default UDP socket created but no server connection
130+
UdpClient();
114131

115-
// default constructor creates unconnected UDP client socket
116-
UDPClient();
117-
118-
// creates UDP client socket connected to UDP server
119-
UDPClient(const std::string& remoteIp, const uint16_t remotePort);
120-
121-
// creates unconnected UDP client socket for DTLS communication
122-
UDPClient(const std::string& keyFile, const std::string& certFile);
123-
124-
// created UDP client socket connected to UDP server using DTLS
125-
UDPClient(const std::string& remoteIp, const uint16_t remotePort, const std::string& keyFile, const std::string& certFile);
132+
// UdpClient connected to a UdpServer IP/port
133+
UdpClient(const std::string& ipAddr, const uint16_t port) noexcept(false)
126134
```
127135
128136
For a BSD-like approach, the following sequence can be followed:
129137
130138
```cpp
131139
// Server
132140
133-
// create server socket
134-
UdpServer server; // add key file and cert file here for secure connection
135-
136-
// bind to port 54321 on IP 0.0.0.0
137-
server.bind(54321);
138-
139-
// following not needed for unsecure connection but is needed for DTLS connection
140-
server.accept();
141+
// create server socket bound to all IP and 54321 port
142+
UdpServer server(54321);
141143
```
142144

143145
```cpp
144146
// Client
145147

146148
// Connect to UDP server on IP 127.0.0.1 and port 54321
147-
UDPClient client("127.0.0.1", 54321); // add key file and cert file here for secure connection
149+
UDPClient client("127.0.0.1", 54321);
148150
```
149151
150152
## Thread Safety
151153
152-
Do not share TcpServer, TcpClient, UDPClient or UdpServer objects across threads unless you provide your own thread safety on the send/read and accept calls.
154+
Do not share any of the socket objects across threads unless you provide your own thread safety on the send/read and accept calls.
153155
154156
## Installation
155157

0 commit comments

Comments
 (0)