File tree Expand file tree Collapse file tree 9 files changed +82
-45
lines changed Expand file tree Collapse file tree 9 files changed +82
-45
lines changed Original file line number Diff line number Diff line change 4
4
## Author Francois Michaut
5
5
##
6
6
## Started on Sun Aug 28 19:26:51 2022 Francois Michaut
7
- ## Last update Tue May 9 11:51:16 2023 Francois Michaut
7
+ ## Last update Wed May 10 08:24:03 2023 Francois Michaut
8
8
##
9
9
## CMakeLists.txt : CMake to build the CppSockets library
10
10
##
@@ -40,5 +40,5 @@ add_custom_target(test
40
40
COMMAND ${CMAKE_COMMAND}
41
41
--build "${CMAKE_CURRENT_BINARY_DIR} /tests" -- --quiet
42
42
COMMAND ${CMAKE_MAKE_PROGRAM}
43
- -C "${CMAKE_CURRENT_BINARY_DIR} /tests" test
43
+ -C "${CMAKE_CURRENT_BINARY_DIR} /tests" test ARGS=--output-on-failure
44
44
)
Original file line number Diff line number Diff line change 4
4
** Author Francois Michaut
5
5
**
6
6
** Started on Sun Feb 13 17:09:05 2022 Francois Michaut
7
- ** Last update Thu Feb 9 08:55:11 2023 Francois Michaut
7
+ ** Last update Tue Jul 18 13:34:19 2023 Francois Michaut
8
8
**
9
9
** Address.hpp : Interface to represent network addresses
10
10
*/
11
11
12
12
#pragma once
13
13
14
+ #include < cstdint>
14
15
#include < string>
15
16
#include < type_traits>
16
17
Original file line number Diff line number Diff line change
1
+ /*
2
+ ** Project CppSockets, 2023
3
+ **
4
+ ** Author Francois Michaut
5
+ **
6
+ ** Started on Tue May 9 23:20:20 2023 Francois Michaut
7
+ ** Last update Sun May 14 14:03:20 2023 Francois Michaut
8
+ **
9
+ ** OSDetection.hpp : OS Detection macros
10
+ */
11
+
12
+ #pragma once
13
+
14
+ #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
15
+ #define OS_WINDOWS
16
+ #elif defined (__APPLE__)
17
+ #define OS_UNIX
18
+ #define OS_APPLE
19
+ #elif defined(__linux__)
20
+ #define OS_UNIX
21
+ #define OS_LINUX
22
+ #elif defined(__unix__)
23
+ #define OS_UNIX
24
+ #else
25
+ #error "Unknown compiler, please open a issue or pull request to support your compiler"
26
+ #endif
Original file line number Diff line number Diff line change 4
4
** Author Francois Michaut
5
5
**
6
6
** Started on Sat Jan 15 01:17:42 2022 Francois Michaut
7
- ** Last update Tue Feb 7 22 :31:12 2023 Francois Michaut
7
+ ** Last update Tue May 9 23 :31:24 2023 Francois Michaut
8
8
**
9
9
** Socket.hpp : Portable C++ socket class
10
10
*/
11
11
12
12
#pragma once
13
13
14
- #ifdef _WIN32
15
- #define NOMINMAX
16
- #include < winsock2.h>
17
- using RawSocketType=SOCKET;
18
- using socklen_t =int ;
14
+ #include " CppSockets/OSDetection.hpp"
15
+
16
+ #ifdef OS_WINDOWS
17
+ #define NOMINMAX
18
+ #include < winsock2.h>
19
+ using RawSocketType=SOCKET;
20
+ using socklen_t =int ;
19
21
#else
20
- #include < sys/socket.h>
21
- using RawSocketType=int ;
22
+ #include < sys/socket.h>
23
+ using RawSocketType=int ;
22
24
#endif
23
25
24
26
#include < memory>
Original file line number Diff line number Diff line change 4
4
** Author Francois Michaut
5
5
**
6
6
** Started on Wed Sep 14 20:51:23 2022 Francois Michaut
7
- ** Last update Mon May 8 19:57:05 2023 Francois Michaut
7
+ ** Last update Tue May 9 23:29:53 2023 Francois Michaut
8
8
**
9
9
** SecureSocket.hpp : TLS socket wrapper using openssl
10
10
*/
11
11
12
12
#pragma once
13
13
14
- #ifdef _WIN32
14
+ #include " CppSockets/OSDetection.hpp"
15
+
16
+ #ifdef OS_WINDOWS
15
17
// TODO Currently disabling TlsSocket for windows
16
18
#else
17
19
18
20
#include " CppSockets/IPv4.hpp"
19
- #include < CppSockets/Socket.hpp>
21
+ #include " CppSockets/Socket.hpp"
20
22
21
23
#include < functional>
22
24
Original file line number Diff line number Diff line change 4
4
** Author Francois Michaut
5
5
**
6
6
** Started on Sat Jan 15 01:27:40 2022 Francois Michaut
7
- ** Last update Sun Feb 19 11:01:09 2023 Francois Michaut
7
+ ** Last update Tue May 9 23:33:46 2023 Francois Michaut
8
8
**
9
9
** Socket.cpp : Protable C++ socket class implementation
10
10
*/
11
11
12
- #include < arpa/inet.h>
13
- #include < cerrno>
14
- #include < cstring>
15
- #include < stdexcept>
16
- #include < unistd.h>
12
+ #include " CppSockets/IPv4.hpp"
13
+ #include " CppSockets/OSDetection.hpp"
14
+ #include " CppSockets/Socket.hpp"
17
15
18
- #ifdef _WIN32
19
- #include < ws2tcpip.h>
16
+ #ifdef OS_WINDOWS
17
+ #include < ws2tcpip.h>
20
18
#else
21
- #include < fcntl.h>
22
- #include < netinet/in.h>
19
+ #include < fcntl.h>
20
+ #include < netinet/in.h>
23
21
// To match windows's constants
24
- static constexpr int INVALID_SOCKET = -1 ;
25
- static constexpr int SOCKET_ERROR = -1 ;
22
+ static constexpr int INVALID_SOCKET = -1 ;
23
+ static constexpr int SOCKET_ERROR = -1 ;
26
24
#endif
27
25
28
26
static constexpr int BUFF_SIZE = 4096 ;
29
27
30
28
#include < array>
29
+ #include < cerrno>
30
+ #include < cstring>
31
+ #include < stdexcept>
31
32
32
- #include " CppSockets/IPv4.hpp "
33
- #include " CppSockets/Socket.hpp "
33
+ #include < arpa/inet.h >
34
+ #include < unistd.h >
34
35
35
36
// TODO add exceptions on error retunrs
36
37
// TODO throw custom exceptions on invalid status (eg: socket already connected)
@@ -58,7 +59,7 @@ namespace CppSockets {
58
59
}
59
60
60
61
Socket::~Socket () {
61
- #ifdef _WIN32
62
+ #ifdef OS_WINDOWS
62
63
closesocket (raw_socket);
63
64
#else
64
65
close (sockfd);
@@ -79,14 +80,14 @@ namespace CppSockets {
79
80
}
80
81
81
82
char *Socket::strerror (int err) {
82
- #ifdef _WIN32
83
+ #ifdef OS_WINDOWS
83
84
#else
84
85
return ::strerror (err);
85
86
#endif
86
87
}
87
88
88
89
int Socket::get_errno () {
89
- #ifdef _WIN32
90
+ #ifdef OS_WINDOWS
90
91
#else
91
92
return errno;
92
93
#endif
Original file line number Diff line number Diff line change 4
4
** Author Francois Michaut
5
5
**
6
6
** Started on Wed Sep 14 21:04:42 2022 Francois Michaut
7
- ** Last update Wed Oct 12 20:10:27 2022 Francois Michaut
7
+ ** Last update Tue May 9 23:34:24 2023 Francois Michaut
8
8
**
9
9
** SecureSocket.cpp : TLS socket wrapper implementation
10
10
*/
11
11
12
- #ifdef _WIN32
12
+ #include " CppSockets/OSDetection.hpp"
13
+ #include " CppSockets/TlsSocket.hpp"
14
+
15
+ #ifdef OS_WINDOWS
13
16
// TODO Currently disabling TlsSocket for windows
14
17
#else
15
18
16
- #include " CppSockets/TlsSocket.hpp"
17
-
18
19
#include < openssl/err.h>
19
20
#include < openssl/ssl.h>
20
21
Original file line number Diff line number Diff line change 4
4
** Author Francois Michaut
5
5
**
6
6
** Started on Thu Sep 15 14:24:25 2022 Francois Michaut
7
- ** Last update Thu Sep 15 21:06:20 2022 Francois Michaut
7
+ ** Last update Tue May 9 23:34:46 2023 Francois Michaut
8
8
**
9
9
** init.cpp : Startup/Cleanup functions implementation
10
10
*/
11
11
12
- #ifdef _WIN32
13
- #include < winsock2.h>
12
+ #include " CppSockets/OSDetection.hpp"
13
+
14
+ #ifdef OS_WINDOWS
15
+ #include < winsock2.h>
14
16
#else
15
- #include < openssl/err.h>
16
- #include < openssl/ssl.h>
17
+ #include < openssl/err.h>
18
+ #include < openssl/ssl.h>
17
19
#endif
18
20
19
21
namespace CppSockets {
20
22
void init (bool init_ssl, bool init_wsa) {
21
- #ifdef _WIN32
23
+ #ifdef OS_WINDOWS
22
24
if (init_wsa) {
23
25
WSADATA wsa_data;
24
26
@@ -41,7 +43,7 @@ namespace CppSockets {
41
43
}
42
44
43
45
void deinit (bool deinit_ssl, bool deinit_wsa) {
44
- #ifdef _WIN32
46
+ #ifdef OS_WINDOWS
45
47
if (deinit_wsa) {
46
48
if (WSACleanup () == SOCKET_ERROR) {
47
49
// TODO use FormatMessage to get the error string
Original file line number Diff line number Diff line change 4
4
## Author Francois Michaut
5
5
##
6
6
## Started on Mon Feb 14 19:35:41 2022 Francois Michaut
7
- ## Last update Sun Aug 28 19:55:12 2022 Francois Michaut
7
+ ## Last update Wed May 10 09:47:41 2023 Francois Michaut
8
8
##
9
9
## CMakeLists.txt : CMake building and running tests for CppSockets
10
10
##
@@ -19,14 +19,16 @@ include(CTest)
19
19
20
20
create_test_sourcelist (TestFiles test_driver.cpp
21
21
TestSockets.cpp
22
- )
22
+ )
23
23
24
24
add_executable (unit_tests
25
25
../source/Address.cpp
26
26
../source/Socket.cpp
27
27
../source/IPv4.cpp
28
28
${TestFiles}
29
- )
29
+ )
30
+
31
+ target_compile_definitions (unit_tests PRIVATE DEBUG )
30
32
31
33
foreach (test ${TestFiles} )
32
34
if (NOT ${test} STREQUAL test_driver.cpp )
You can’t perform that action at this time.
0 commit comments