Skip to content

Commit e1f87ef

Browse files
committed
fix: Include ipc sample on Windows as well, and mark it as not implemented.
1 parent a426908 commit e1f87ef

File tree

9 files changed

+62
-55
lines changed

9 files changed

+62
-55
lines changed

include/asock/asock_ipc_client.hpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#endif
99

1010
namespace asock {
11-
#if defined __APPLE__ || defined __linux__
1211
class ASockIpcClient: public asock::ASockBase {
1312
public :
13+
#if defined __APPLE__ || defined __linux__
1414
// - If you know the maximum data size you will be sending and receiving in advance,
1515
// it is better to allocate a buffer large enough to match that.
1616
// - If you do not know the size in advance or if it exceeds the buffer,
@@ -36,7 +36,20 @@ public :
3636
sock_usage_ = SOCK_USAGE_IPC_CLIENT;
3737
}
3838
#elif WIN32
39-
//TODO: windows
39+
// TODO: Not implemented on Windows.
40+
bool InitIpcClient(const char* sock_path,
41+
int connect_timeout_secs=10,
42+
size_t max_data_len=asock::DEFAULT_BUFFER_SIZE) {
43+
err_msg_ = "not implemented";
44+
ELOG(err_msg_);
45+
return false;
46+
}
47+
48+
void SetUsage() override {
49+
err_msg_ = "not implemented";
50+
ELOG(err_msg_);
51+
sock_usage_ = SOCK_USAGE_UNKNOWN;
52+
}
4053
#endif
4154
};
4255
} //namespace

include/asock/asock_ipc_server.hpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#endif
99

1010
namespace asock {
11-
#if defined __APPLE__ || defined __linux__
1211
class ASockIpcServer: public asock::ASockBase {
1312
public :
13+
#if defined __APPLE__ || defined __linux__
1414
// - If you know the maximum data size you will be sending and receiving in advance,
1515
// it is better to allocate a buffer large enough to match that.
1616
// - If you do not know the size in advance or if it exceeds the buffer,
@@ -34,9 +34,22 @@ public :
3434
void SetUsage() override {
3535
sock_usage_ = SOCK_USAGE_IPC_SERVER;
3636
}
37-
};
3837
#elif WIN32
39-
//TODO: windows
38+
// TODO: Not implemented on Windows.
39+
bool RunIpcServer (const char* sock_path,
40+
size_t max_data_len=asock::DEFAULT_BUFFER_SIZE,
41+
size_t max_event=asock::DEFAULT_MAX_EVENT){
42+
err_msg_ = "not implemented";
43+
ELOG(err_msg_);
44+
return false;
45+
}
46+
47+
void SetUsage() override {
48+
err_msg_ = "not implemented";
49+
ELOG(err_msg_);
50+
sock_usage_ = SOCK_USAGE_UNKNOWN;
51+
}
4052
#endif
53+
};
4154
} //namespace
4255
#endif

sample/CMakeLists.txt

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,22 @@ elseif(APPLE OR CMAKE_SYSTEM_NAME MATCHES "Linux")
2727
add_definitions(-Wall -Werror -Wextra -Wpedantic)
2828
endif()
2929

30-
if(WIN32)
31-
set(SAMPLE_FILES
32-
client_tcp_comp.cpp
33-
client_tcp_eo.cpp
34-
client_tcp_inh.cpp
35-
client_udp_comp.cpp
36-
client_udp_inh.cpp
37-
server_tcp_comp.cpp
38-
server_tcp_eo.cpp
39-
server_tcp_inh.cpp
40-
server_udp_comp.cpp
41-
server_udp_inh.cpp
42-
)
43-
elseif(APPLE OR CMAKE_SYSTEM_NAME MATCHES "Linux")
44-
set(SAMPLE_FILES
45-
client_tcp_comp.cpp
46-
client_tcp_eo.cpp
47-
client_tcp_inh.cpp
48-
client_udp_comp.cpp
49-
client_udp_inh.cpp
50-
server_tcp_comp.cpp
51-
server_tcp_eo.cpp
52-
server_tcp_inh.cpp
53-
server_udp_comp.cpp
54-
server_udp_inh.cpp
55-
client_ipc_comp.cpp
56-
client_ipc_inh.cpp
57-
server_ipc_comp.cpp
58-
server_ipc_inh.cpp
59-
)
60-
endif()
30+
set(SAMPLE_FILES
31+
client_tcp_comp.cpp
32+
client_tcp_eo.cpp
33+
client_tcp_inh.cpp
34+
client_udp_comp.cpp
35+
client_udp_inh.cpp
36+
server_tcp_comp.cpp
37+
server_tcp_eo.cpp
38+
server_tcp_inh.cpp
39+
server_udp_comp.cpp
40+
server_udp_inh.cpp
41+
client_ipc_comp.cpp
42+
client_ipc_inh.cpp
43+
server_ipc_comp.cpp
44+
server_ipc_inh.cpp
45+
)
6146

6247
foreach(samplefile ${SAMPLE_FILES})
6348
get_filename_component(exename ${samplefile} NAME_WE)

sample/client_ipc_comp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <csignal>
77
#include "asock/asock_ipc_client.hpp"
88

9+
// NOTE: Not implemented on Windows.
910
// The buffer must be large enough to hold the entire data.
1011
#define DEFAULT_PACKET_SIZE 1024
1112
///////////////////////////////////////////////////////////////////////////////
@@ -96,7 +97,7 @@ int main(int argc, char* argv[]) {
9697
while( client.IsConnected() ) {
9798
std::cin.clear();
9899
getline(std::cin, user_msg);
99-
int msg_len = user_msg.length();
100+
int msg_len = (int)user_msg.length();
100101
if(msg_len>0) {
101102
if(! client.SendToServer(user_msg.c_str(),msg_len) ) {
102103
std::cerr << client.GetLastErrMsg() <<"\n";

sample/client_ipc_inh.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <csignal>
77
#include "asock/asock_ipc_client.hpp"
88

9+
// NOTE: Not implemented on Windows.
910
// The buffer must be large enough to hold the entire data.
1011
#define DEFAULT_PACKET_SIZE 1024
1112
///////////////////////////////////////////////////////////////////////////////
@@ -70,7 +71,7 @@ int main(int argc, char* argv[]) {
7071
while( client.IsConnected() ) {
7172
std::cin.clear();
7273
getline(std::cin, user_msg);
73-
int msg_len = user_msg.length();
74+
int msg_len = (int)user_msg.length();
7475
if(msg_len>0) {
7576
if(! client.SendToServer(user_msg.c_str(),user_msg.length()) ) {
7677
std::cerr << client.GetLastErrMsg() <<"\n";

sample/server_ipc_comp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <csignal>
55
#include "asock/asock_ipc_server.hpp"
66

7+
// NOTE: Not implemented on Windows.
78
// The buffer must be large enough to hold the entire data.
89
#define DEFAULT_PACKET_SIZE 1024
910
///////////////////////////////////////////////////////////////////////////////
@@ -100,7 +101,7 @@ int main(int argc, char* argv[]) {
100101
}
101102
std::cout << "server started" << "\n";
102103
while( server.IsServerRunning() ) {
103-
sleep(1);
104+
std::this_thread::sleep_for(std::chrono::seconds(1));
104105
}
105106
std::cout << "server exit...\n";
106107
exit(EXIT_SUCCESS);

sample/server_ipc_inh.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <csignal>
55
#include "asock/asock_ipc_server.hpp"
66

7+
// NOTE: Not implemented on Windows.
78
// The buffer must be large enough to hold the entire data.
89
#define DEFAULT_PACKET_SIZE 1024
910
///////////////////////////////////////////////////////////////////////////////
@@ -74,7 +75,7 @@ int main(int argc, char* argv[]) {
7475
exit(EXIT_FAILURE);
7576
}std::cout << "server started" << "\n";
7677
while( server.IsServerRunning() ) {
77-
sleep(1);
78+
std::this_thread::sleep_for(std::chrono::seconds(1));
7879
}
7980
std::cout << "server exit...\n";
8081
exit(EXIT_SUCCESS);

test/CMakeLists.txt

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,12 @@ elseif(APPLE OR CMAKE_SYSTEM_NAME MATCHES "Linux")
2626
add_definitions(-Wall -Werror -Wextra -Wpedantic)
2727
endif()
2828

29-
if(WIN32)
30-
set(TEST_FILES
31-
buffer_test.cpp
32-
tcp_test.cpp
33-
udp_test.cpp
34-
)
35-
elseif(APPLE OR CMAKE_SYSTEM_NAME MATCHES "Linux")
36-
set(TEST_FILES
37-
buffer_test.cpp
38-
tcp_test.cpp
39-
udp_test.cpp
40-
ipc_test.cpp
41-
)
42-
endif()
29+
set(TEST_FILES
30+
buffer_test.cpp
31+
tcp_test.cpp
32+
udp_test.cpp
33+
ipc_test.cpp
34+
)
4335

4436
enable_testing()
4537
find_package(GTest CONFIG REQUIRED)

test/ipc_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "asock/asock_ipc_server.hpp"
88

99
#define DEFAULT_PACKET_SIZE 1024
10-
10+
// NOTE: Not implemented on Windows.
1111
// This file is created in the current directory and automatically deleted.
1212
#define TEST_IPC_PATH "asock.test.ipc"
1313

0 commit comments

Comments
 (0)