pyxcp 0.21.10__cp39-cp39-win_amd64.whl → 0.22.23__cp39-cp39-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyxcp might be problematic. Click here for more details.
- pyxcp/__init__.py +12 -20
- pyxcp/aml/EtasCANMonitoring.a2l +82 -83
- pyxcp/aml/XCP_Common.aml +0 -1
- pyxcp/aml/XCPonUSB.aml +1 -1
- pyxcp/aml/ifdata_CAN.a2l +0 -1
- pyxcp/aml/ifdata_Eth.a2l +0 -1
- pyxcp/aml/ifdata_Flx.a2l +0 -1
- pyxcp/aml/ifdata_SxI.a2l +0 -1
- pyxcp/aml/ifdata_USB.a2l +0 -1
- pyxcp/asam/types.py +4 -4
- pyxcp/asamkeydll.c +0 -1
- pyxcp/checksum.py +0 -1
- pyxcp/cmdline.py +32 -50
- pyxcp/config/__init__.py +1100 -0
- pyxcp/config/legacy.py +120 -0
- pyxcp/constants.py +12 -13
- pyxcp/cpp_ext/__init__.py +0 -0
- pyxcp/cpp_ext/bin.hpp +104 -0
- pyxcp/cpp_ext/blockmem.hpp +58 -0
- pyxcp/cpp_ext/cpp_ext.cp38-win_amd64.pyd +0 -0
- pyxcp/cpp_ext/cpp_ext.cp39-win_amd64.pyd +0 -0
- pyxcp/cpp_ext/daqlist.hpp +200 -0
- pyxcp/cpp_ext/event.hpp +67 -0
- pyxcp/cpp_ext/extension_wrapper.cpp +96 -0
- pyxcp/cpp_ext/helper.hpp +280 -0
- pyxcp/cpp_ext/mcobject.hpp +246 -0
- pyxcp/cpp_ext/tsqueue.hpp +46 -0
- pyxcp/daq_stim/__init__.py +228 -0
- pyxcp/daq_stim/optimize/__init__.py +67 -0
- pyxcp/daq_stim/optimize/binpacking.py +41 -0
- pyxcp/daq_stim/scheduler.cpp +28 -0
- pyxcp/daq_stim/scheduler.hpp +75 -0
- pyxcp/daq_stim/stim.cp38-win_amd64.pyd +0 -0
- pyxcp/daq_stim/stim.cp39-win_amd64.pyd +0 -0
- pyxcp/daq_stim/stim.cpp +13 -0
- pyxcp/daq_stim/stim.hpp +604 -0
- pyxcp/daq_stim/stim_wrapper.cpp +48 -0
- pyxcp/dllif.py +21 -18
- pyxcp/errormatrix.py +5 -3
- pyxcp/examples/conf_can.toml +4 -2
- pyxcp/examples/conf_can_vector.json +9 -9
- pyxcp/examples/conf_can_vector.toml +4 -2
- pyxcp/examples/conf_eth.toml +5 -2
- pyxcp/examples/conf_nixnet.json +18 -18
- pyxcp/examples/conf_sxi.json +7 -7
- pyxcp/examples/ex_arrow.py +109 -0
- pyxcp/examples/ex_csv.py +85 -0
- pyxcp/examples/ex_excel.py +95 -0
- pyxcp/examples/ex_mdf.py +124 -0
- pyxcp/examples/ex_sqlite.py +128 -0
- pyxcp/examples/run_daq.py +148 -0
- pyxcp/examples/xcp_policy.py +6 -7
- pyxcp/examples/xcp_read_benchmark.py +8 -6
- pyxcp/examples/xcp_skel.py +0 -2
- pyxcp/examples/xcp_unlock.py +1 -1
- pyxcp/examples/xcp_user_supplied_driver.py +1 -2
- pyxcp/examples/xcphello.py +6 -3
- pyxcp/examples/xcphello_recorder.py +4 -4
- pyxcp/master/__init__.py +1 -2
- pyxcp/master/errorhandler.py +107 -74
- pyxcp/master/master.py +201 -119
- pyxcp/py.typed +0 -0
- pyxcp/recorder/__init__.py +27 -6
- pyxcp/recorder/converter/__init__.py +37 -0
- pyxcp/recorder/lz4.c +129 -51
- pyxcp/recorder/lz4.h +45 -28
- pyxcp/recorder/lz4hc.c +560 -156
- pyxcp/recorder/lz4hc.h +1 -1
- pyxcp/recorder/mio.hpp +721 -767
- pyxcp/recorder/reader.hpp +139 -0
- pyxcp/recorder/reco.py +5 -8
- pyxcp/recorder/rekorder.cp38-win_amd64.pyd +0 -0
- pyxcp/recorder/rekorder.cp39-win_amd64.pyd +0 -0
- pyxcp/recorder/rekorder.cpp +18 -22
- pyxcp/recorder/rekorder.hpp +200 -587
- pyxcp/recorder/setup.py +11 -10
- pyxcp/recorder/test_reko.py +2 -3
- pyxcp/recorder/unfolder.hpp +1332 -0
- pyxcp/recorder/wrap.cpp +171 -9
- pyxcp/recorder/writer.hpp +302 -0
- pyxcp/scripts/pyxcp_probe_can_drivers.py +0 -2
- pyxcp/scripts/xcp_examples.py +64 -0
- pyxcp/scripts/xcp_fetch_a2l.py +15 -10
- pyxcp/scripts/xcp_id_scanner.py +2 -6
- pyxcp/scripts/xcp_info.py +101 -63
- pyxcp/scripts/xcp_profile.py +27 -0
- pyxcp/stim/__init__.py +0 -0
- pyxcp/tests/test_asam_types.py +2 -2
- pyxcp/tests/test_binpacking.py +186 -0
- pyxcp/tests/test_can.py +1132 -38
- pyxcp/tests/test_checksum.py +2 -1
- pyxcp/tests/test_daq.py +193 -0
- pyxcp/tests/test_frame_padding.py +6 -3
- pyxcp/tests/test_master.py +42 -31
- pyxcp/tests/test_transport.py +12 -12
- pyxcp/tests/test_utils.py +2 -5
- pyxcp/timing.py +0 -2
- pyxcp/transport/__init__.py +9 -9
- pyxcp/transport/base.py +149 -127
- pyxcp/transport/base_transport.hpp +0 -0
- pyxcp/transport/can.py +194 -167
- pyxcp/transport/eth.py +80 -82
- pyxcp/transport/sxi.py +106 -60
- pyxcp/transport/transport_wrapper.cpp +0 -0
- pyxcp/transport/usb_transport.py +65 -83
- pyxcp/types.py +69 -20
- pyxcp/utils.py +47 -16
- pyxcp/vector/map.py +1 -3
- {pyxcp-0.21.10.dist-info → pyxcp-0.22.23.dist-info}/METADATA +28 -23
- pyxcp-0.22.23.dist-info/RECORD +131 -0
- {pyxcp-0.21.10.dist-info → pyxcp-0.22.23.dist-info}/WHEEL +1 -1
- {pyxcp-0.21.10.dist-info → pyxcp-0.22.23.dist-info}/entry_points.txt +2 -0
- pyxcp/config.py +0 -57
- pyxcp/cxx/asynchiofactory.hpp +0 -24
- pyxcp/cxx/blocking_client.cpp +0 -44
- pyxcp/cxx/blocking_socket.cpp +0 -43
- pyxcp/cxx/blocking_socket.hpp +0 -558
- pyxcp/cxx/concurrent_queue.hpp +0 -60
- pyxcp/cxx/eth.hpp +0 -57
- pyxcp/cxx/exceptions.hpp +0 -30
- pyxcp/cxx/iasyncioservice.hpp +0 -31
- pyxcp/cxx/iresource.hpp +0 -17
- pyxcp/cxx/isocket.hpp +0 -22
- pyxcp/cxx/linux/epoll.cpp +0 -51
- pyxcp/cxx/linux/epoll.hpp +0 -87
- pyxcp/cxx/linux/lit_tester.cpp +0 -19
- pyxcp/cxx/linux/socket.hpp +0 -234
- pyxcp/cxx/linux/timeout.hpp +0 -81
- pyxcp/cxx/memoryblock.hpp +0 -42
- pyxcp/cxx/pool.hpp +0 -81
- pyxcp/cxx/poolmgr.cpp +0 -6
- pyxcp/cxx/poolmgr.hpp +0 -31
- pyxcp/cxx/test_queue.cpp +0 -69
- pyxcp/cxx/timestamp.hpp +0 -84
- pyxcp/cxx/utils.cpp +0 -38
- pyxcp/cxx/utils.hpp +0 -29
- pyxcp/cxx/win/iocp.cpp +0 -242
- pyxcp/cxx/win/iocp.hpp +0 -42
- pyxcp/cxx/win/perhandledata.hpp +0 -24
- pyxcp/cxx/win/periodata.hpp +0 -97
- pyxcp/cxx/win/socket.hpp +0 -185
- pyxcp/cxx/win/timeout.hpp +0 -83
- pyxcp/examples/conf_can.json +0 -20
- pyxcp/examples/conf_eth.json +0 -8
- pyxcp/logger.py +0 -67
- pyxcp/tests/test_config.py +0 -62
- pyxcp/transport/candriver/__init__.py +0 -2
- pyxcp/transport/candriver/pc_canalystii.py +0 -27
- pyxcp/transport/candriver/pc_etas.py +0 -25
- pyxcp/transport/candriver/pc_gsusb.py +0 -23
- pyxcp/transport/candriver/pc_iscan.py +0 -23
- pyxcp/transport/candriver/pc_ixxat.py +0 -27
- pyxcp/transport/candriver/pc_kvaser.py +0 -39
- pyxcp/transport/candriver/pc_neovi.py +0 -31
- pyxcp/transport/candriver/pc_nican.py +0 -23
- pyxcp/transport/candriver/pc_nixnet.py +0 -23
- pyxcp/transport/candriver/pc_pcan.py +0 -25
- pyxcp/transport/candriver/pc_seeed.py +0 -28
- pyxcp/transport/candriver/pc_serial.py +0 -27
- pyxcp/transport/candriver/pc_slcan.py +0 -29
- pyxcp/transport/candriver/pc_socketcan.py +0 -23
- pyxcp/transport/candriver/pc_systec.py +0 -29
- pyxcp/transport/candriver/pc_usb2can.py +0 -30
- pyxcp/transport/candriver/pc_vector.py +0 -34
- pyxcp/transport/candriver/python_can.py +0 -101
- pyxcp/transport/cxx_ext/CMakeLists.txt +0 -51
- pyxcp/transport/cxx_ext/setup.py +0 -49
- pyxcp/transport/cxx_ext/tests/test_basic_socket.cpp +0 -39
- pyxcp/transport/cxx_ext/tests/test_pool.cpp +0 -39
- pyxcp/transport/cxx_ext/tests/test_timestamp.cpp +0 -27
- pyxcp-0.21.10.dist-info/RECORD +0 -147
- rekorder.cp39-win_amd64.pyd +0 -0
- {pyxcp-0.21.10.dist-info/licenses → pyxcp-0.22.23.dist-info}/LICENSE +0 -0
pyxcp/cxx/blocking_socket.hpp
DELETED
|
@@ -1,558 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
#include <array>
|
|
3
|
-
|
|
4
|
-
#include "utils.hpp"
|
|
5
|
-
|
|
6
|
-
#if !defined(__BLOCKING_SOCKET_HPP)
|
|
7
|
-
#define __BLOCKING_SOCKET_HPP
|
|
8
|
-
|
|
9
|
-
#if defined(_WIN32)
|
|
10
|
-
#include <WinSock2.h>
|
|
11
|
-
#include <Ws2tcpip.h>
|
|
12
|
-
#include <Mstcpip.h>
|
|
13
|
-
#include <MSWSock.h>
|
|
14
|
-
#include <Windows.h>
|
|
15
|
-
#elif defined(__unix__)
|
|
16
|
-
#include <ctype.h>
|
|
17
|
-
#include <errno.h>
|
|
18
|
-
#include <fcntl.h>
|
|
19
|
-
#include <limits.h>
|
|
20
|
-
#include <signal.h>
|
|
21
|
-
#include <stdlib.h>
|
|
22
|
-
#include <stdio.h>
|
|
23
|
-
#include <string.h>
|
|
24
|
-
#include <time.h>
|
|
25
|
-
#include <stdbool.h>
|
|
26
|
-
#include <unistd.h>
|
|
27
|
-
#include <sys/types.h>
|
|
28
|
-
#include <sys/socket.h>
|
|
29
|
-
#include <netinet/in.h>
|
|
30
|
-
#include <netdb.h>
|
|
31
|
-
#include <arpa/inet.h>
|
|
32
|
-
#include <sys/wait.h>
|
|
33
|
-
|
|
34
|
-
#define INVALID_SOCKET (-1)
|
|
35
|
-
#define SOCKET_ERROR (-1)
|
|
36
|
-
#define ADDRINFO addrinfo
|
|
37
|
-
#define SOCKADDR struct sockaddr
|
|
38
|
-
#define SOCKADDR_STORAGE sockaddr_storage
|
|
39
|
-
|
|
40
|
-
typedef int SOCKET;
|
|
41
|
-
#endif
|
|
42
|
-
|
|
43
|
-
#include <pthread.h>
|
|
44
|
-
|
|
45
|
-
#define ADDR_LEN sizeof(SOCKADDR_STORAGE)
|
|
46
|
-
|
|
47
|
-
template <std::size_t N> using buffer_t = std::array<unsigned char, N>;
|
|
48
|
-
|
|
49
|
-
void * blockingReceiverThread(void * param);
|
|
50
|
-
|
|
51
|
-
struct CAddress {
|
|
52
|
-
int length;
|
|
53
|
-
struct sockaddr address;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
class Socket {
|
|
57
|
-
public:
|
|
58
|
-
|
|
59
|
-
explicit Socket(int family = PF_INET, int socktype = SOCK_STREAM, int protocol = IPPROTO_TCP) : m_family(family), m_socktype(socktype),
|
|
60
|
-
m_protocol(protocol), m_connected(false), m_addr(nullptr), m_thread(0) {
|
|
61
|
-
m_socket = ::socket(m_family, m_socktype, m_protocol);
|
|
62
|
-
m_connected_socket = 0;
|
|
63
|
-
if (m_socket == INVALID_SOCKET) {
|
|
64
|
-
SocketErrorExit("Socket::Socket()");
|
|
65
|
-
}
|
|
66
|
-
blocking(true);
|
|
67
|
-
ZeroOut(&m_peerAddress, sizeof(SOCKADDR_STORAGE));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
~Socket() {
|
|
71
|
-
#if defined(__unix__)
|
|
72
|
-
::close(m_socket);
|
|
73
|
-
#elif #defined(_WIN32)
|
|
74
|
-
::closesocket(m_socket);
|
|
75
|
-
#endif
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
void blocking(bool enabled) {
|
|
79
|
-
int flags = ::fcntl(m_socket, F_GETFL);
|
|
80
|
-
|
|
81
|
-
if (flags == -1) {
|
|
82
|
-
SocketErrorExit("blocking::fcntl()");
|
|
83
|
-
}
|
|
84
|
-
flags = enabled ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK);
|
|
85
|
-
if (::fcntl(m_socket, F_SETFL, flags) == -1) {
|
|
86
|
-
SocketErrorExit("blocking::fcntl()");
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
void set_option(int optname, int level, int value) {
|
|
91
|
-
|
|
92
|
-
if (::setsockopt(m_socket, level, optname, (const char*) &value, sizeof(value)) == SOCKET_ERROR) {
|
|
93
|
-
SocketErrorExit("Socket::set_option()");
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
int get_option(int optname, int level) {
|
|
98
|
-
int value;
|
|
99
|
-
socklen_t len;
|
|
100
|
-
|
|
101
|
-
len = sizeof(value);
|
|
102
|
-
if (::getsockopt(m_socket, level, optname, (char*) &value, &len) == SOCKET_ERROR) {
|
|
103
|
-
SocketErrorExit("Socket::get_option()");
|
|
104
|
-
}
|
|
105
|
-
return value;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
bool get_reuse_addr() {
|
|
109
|
-
return static_cast<bool>(get_option(SO_REUSEADDR, SOL_SOCKET));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
void set_reuse_addr(bool on) {
|
|
113
|
-
set_option(SO_REUSEADDR, SOL_SOCKET, static_cast<int>(on));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
int get_send_buffer_size() {
|
|
117
|
-
return get_option(SO_SNDBUF, SOL_SOCKET);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
void set_send_buffer_size(int size) {
|
|
121
|
-
set_option(SO_SNDBUF, SOL_SOCKET, size);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
int get_rcv_buffer_size() {
|
|
125
|
-
return get_option(SO_RCVBUF, SOL_SOCKET);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
void set_rcv_buffer_size(int size) {
|
|
129
|
-
set_option(SO_RCVBUF, SOL_SOCKET, size);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
bool getaddrinfo(int family, int socktype, int protocol, const char * hostname, int port, CAddress & address, int flags = AI_PASSIVE) {
|
|
133
|
-
int err;
|
|
134
|
-
ADDRINFO hints;
|
|
135
|
-
ADDRINFO * t_addr;
|
|
136
|
-
char port_str[16] = {0};
|
|
137
|
-
|
|
138
|
-
ZeroOut(&hints, sizeof(hints));
|
|
139
|
-
hints.ai_family = family;
|
|
140
|
-
hints.ai_socktype = socktype;
|
|
141
|
-
hints.ai_protocol = protocol;
|
|
142
|
-
hints.ai_flags = flags;
|
|
143
|
-
::sprintf(port_str, "%d", port);
|
|
144
|
-
err = ::getaddrinfo(hostname, port_str, &hints, &t_addr);
|
|
145
|
-
if (err != 0) {
|
|
146
|
-
printf("%s\n", gai_strerror(err));
|
|
147
|
-
::freeaddrinfo(t_addr);
|
|
148
|
-
SocketErrorExit("getaddrinfo()");
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
address.length = t_addr->ai_addrlen;
|
|
152
|
-
CopyMemory(&address.address, t_addr->ai_addr, sizeof(SOCKADDR));
|
|
153
|
-
::freeaddrinfo(t_addr);
|
|
154
|
-
return true;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
void connect(CAddress & address) {
|
|
158
|
-
if (::connect(m_socket, &address.address, address.length) == SOCKET_ERROR) {
|
|
159
|
-
SocketErrorExit("Socket::connect()");
|
|
160
|
-
}
|
|
161
|
-
m_connected_socket = m_socket;
|
|
162
|
-
printf("Sock-conn: %d\n", m_connected_socket);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
void bind(CAddress & address) {
|
|
166
|
-
if (::bind(m_socket, &address.address, address.length) == SOCKET_ERROR) {
|
|
167
|
-
SocketErrorExit("Socket::bind()");
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
void listen(int backlog = 1) {
|
|
172
|
-
if (::listen(m_socket, backlog) == SOCKET_ERROR) {
|
|
173
|
-
SocketErrorExit("Socket::listen()");
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
void accept(CAddress & peerAddress) {
|
|
178
|
-
|
|
179
|
-
peerAddress.length = sizeof peerAddress.address;
|
|
180
|
-
m_connected_socket = ::accept(m_socket, (SOCKADDR *)&peerAddress.address, (socklen_t*)&peerAddress.length);
|
|
181
|
-
|
|
182
|
-
if (m_connected_socket == INVALID_SOCKET) {
|
|
183
|
-
SocketErrorExit("Socket::accept()");
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
void startReceiverThread() {
|
|
188
|
-
int res = 0;
|
|
189
|
-
|
|
190
|
-
res = ::pthread_create(&m_thread, NULL, blockingReceiverThread, this);
|
|
191
|
-
if (res == -1) {
|
|
192
|
-
OsErrorExit("startReceiverThread::pthread_create");
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
void shutdownReceiverThread() {
|
|
197
|
-
int res = 0;
|
|
198
|
-
|
|
199
|
-
res = ::pthread_kill(m_thread, SIGINT);
|
|
200
|
-
if (res == -1) {
|
|
201
|
-
OsErrorExit("shutdownReceiverThread::pthread_kill");
|
|
202
|
-
}
|
|
203
|
-
res = pthread_join(m_thread, NULL);
|
|
204
|
-
if (res == -1) {
|
|
205
|
-
OsErrorExit("shutdownReceiverThread::pthread_join");
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
template <typename T, size_t N>
|
|
210
|
-
int read(std::array<T, N>& arr, size_t len) {
|
|
211
|
-
int nbytes;
|
|
212
|
-
|
|
213
|
-
nbytes = ::recv(m_connected_socket, (char*)arr.data(), len, 0);
|
|
214
|
-
if (nbytes == -1) {
|
|
215
|
-
OsErrorExit("read::recv");
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return nbytes;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
template <typename T, size_t N>
|
|
222
|
-
void write(std::array<T, N>& arr) {
|
|
223
|
-
if (m_socktype == SOCK_DGRAM) {
|
|
224
|
-
#if 0
|
|
225
|
-
if (sendto(m_socket, (char const *)arr.data(), arr.size(), 0,
|
|
226
|
-
(SOCKADDR * )(SOCKADDR_STORAGE const *)&XcpTl_Connection.connectionAddress, ADDR_LEN) == SOCKET_ERROR) {
|
|
227
|
-
SocketErrorExit("send::sendto()");
|
|
228
|
-
}
|
|
229
|
-
#endif
|
|
230
|
-
} else if (m_socktype == SOCK_STREAM) {
|
|
231
|
-
if (::send(m_connected_socket, (char const *)arr.data(), arr.size(), 0) == SOCKET_ERROR) {
|
|
232
|
-
SocketErrorExit("send::send()");
|
|
233
|
-
#if defined(_WIN32)
|
|
234
|
-
closesocket(m_connected_socket);
|
|
235
|
-
#elif defined(__unix__)
|
|
236
|
-
close(m_connected_socket);
|
|
237
|
-
#endif
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
SOCKET getSocket() const {
|
|
243
|
-
return m_socket;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
protected:
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
private:
|
|
250
|
-
int m_family;
|
|
251
|
-
int m_socktype;
|
|
252
|
-
int m_protocol;
|
|
253
|
-
bool m_connected;
|
|
254
|
-
addrinfo * m_addr;
|
|
255
|
-
pthread_t m_thread;
|
|
256
|
-
//TimeoutTimer m_timeout {150};
|
|
257
|
-
|
|
258
|
-
SOCKET m_socket;
|
|
259
|
-
SOCKET m_connected_socket;
|
|
260
|
-
//CAddress ourAddress;
|
|
261
|
-
SOCKADDR_STORAGE m_peerAddress;
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
#endif // __BLOCKING_SOCKET_HPP
|
|
266
|
-
|
|
267
|
-
/*
|
|
268
|
-
* pyXCP
|
|
269
|
-
*
|
|
270
|
-
* (C) 2021 by Christoph Schueler <github.com/Christoph2,
|
|
271
|
-
* cpu12.gems@googlemail.com>
|
|
272
|
-
*
|
|
273
|
-
* All Rights Reserved
|
|
274
|
-
*
|
|
275
|
-
* This program is free software; you can redistribute it and/or modify
|
|
276
|
-
* it under the terms of the GNU General Public License as published by
|
|
277
|
-
* the Free Software Foundation; either version 2 of the License, or
|
|
278
|
-
* (at your option) any later version.
|
|
279
|
-
*
|
|
280
|
-
* This program is distributed in the hope that it will be useful,
|
|
281
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
282
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
283
|
-
* GNU General Public License for more details.
|
|
284
|
-
*
|
|
285
|
-
* You should have received a copy of the GNU General Public License along
|
|
286
|
-
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
287
|
-
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
288
|
-
*
|
|
289
|
-
* s. FLOSS-EXCEPTION.txt
|
|
290
|
-
*/
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
#include <array>
|
|
294
|
-
#include <functional>
|
|
295
|
-
#include <thread>
|
|
296
|
-
|
|
297
|
-
#include "utils.hpp"
|
|
298
|
-
|
|
299
|
-
#if !defined(__BLOCKING_SOCKET_HPP)
|
|
300
|
-
#define __BLOCKING_SOCKET_HPP
|
|
301
|
-
|
|
302
|
-
#if defined(_WIN32)
|
|
303
|
-
#include <WinSock2.h>
|
|
304
|
-
#include <Ws2tcpip.h>
|
|
305
|
-
#include <Mstcpip.h>
|
|
306
|
-
#include <MSWSock.h>
|
|
307
|
-
#include <Windows.h>
|
|
308
|
-
#elif defined(__unix__)
|
|
309
|
-
#include <ctype.h>
|
|
310
|
-
#include <errno.h>
|
|
311
|
-
#include <fcntl.h>
|
|
312
|
-
#include <limits.h>
|
|
313
|
-
#include <signal.h>
|
|
314
|
-
#include <stdlib.h>
|
|
315
|
-
#include <stdio.h>
|
|
316
|
-
#include <string.h>
|
|
317
|
-
#include <time.h>
|
|
318
|
-
#include <stdbool.h>
|
|
319
|
-
#include <unistd.h>
|
|
320
|
-
#include <sys/types.h>
|
|
321
|
-
#include <sys/socket.h>
|
|
322
|
-
#include <netinet/in.h>
|
|
323
|
-
#include <netdb.h>
|
|
324
|
-
#include <arpa/inet.h>
|
|
325
|
-
#include <sys/wait.h>
|
|
326
|
-
|
|
327
|
-
#define INVALID_SOCKET (-1)
|
|
328
|
-
#define SOCKET_ERROR (-1)
|
|
329
|
-
#define ADDRINFO addrinfo
|
|
330
|
-
#define SOCKADDR struct sockaddr
|
|
331
|
-
#define SOCKADDR_STORAGE sockaddr_storage
|
|
332
|
-
|
|
333
|
-
typedef int SOCKET;
|
|
334
|
-
#endif
|
|
335
|
-
|
|
336
|
-
#include <pthread.h>
|
|
337
|
-
|
|
338
|
-
#define ADDR_LEN sizeof(SOCKADDR_STORAGE)
|
|
339
|
-
|
|
340
|
-
template <std::size_t N> using buffer_t = std::array<unsigned char, N>;
|
|
341
|
-
|
|
342
|
-
class Socket;
|
|
343
|
-
|
|
344
|
-
[[noreturn]] void blockingReceiverThread(Socket * socket);
|
|
345
|
-
|
|
346
|
-
struct CAddress {
|
|
347
|
-
int length;
|
|
348
|
-
struct sockaddr address;
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
class Socket {
|
|
352
|
-
public:
|
|
353
|
-
|
|
354
|
-
using listen_thread_t = std::function<void(const Socket&)>;
|
|
355
|
-
|
|
356
|
-
explicit Socket(int family = PF_INET, int socktype = SOCK_STREAM, int protocol = IPPROTO_TCP) : m_family(family), m_socktype(socktype),
|
|
357
|
-
m_protocol(protocol), m_connected(false), m_addr(nullptr) {
|
|
358
|
-
m_socket = ::socket(m_family, m_socktype, m_protocol);
|
|
359
|
-
m_connected_socket = 0;
|
|
360
|
-
if (m_socket == INVALID_SOCKET) {
|
|
361
|
-
SocketErrorExit("Socket::Socket()");
|
|
362
|
-
}
|
|
363
|
-
blocking(true);
|
|
364
|
-
ZeroOut(&m_peerAddress, sizeof(SOCKADDR_STORAGE));
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
~Socket() {
|
|
368
|
-
#if defined(__unix__)
|
|
369
|
-
::close(m_socket);
|
|
370
|
-
#elif #defined(_WIN32)
|
|
371
|
-
::closesocket(m_socket);
|
|
372
|
-
#endif
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
void blocking(bool enabled) {
|
|
376
|
-
int flags = ::fcntl(m_socket, F_GETFL);
|
|
377
|
-
|
|
378
|
-
if (flags == -1) {
|
|
379
|
-
SocketErrorExit("blocking::fcntl()");
|
|
380
|
-
}
|
|
381
|
-
flags = enabled ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK);
|
|
382
|
-
if (::fcntl(m_socket, F_SETFL, flags) == -1) {
|
|
383
|
-
SocketErrorExit("blocking::fcntl()");
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
void set_option(int optname, int level, int value) {
|
|
388
|
-
|
|
389
|
-
if (::setsockopt(m_socket, level, optname, (const char*) &value, sizeof(value)) == SOCKET_ERROR) {
|
|
390
|
-
SocketErrorExit("Socket::set_option()");
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
int get_option(int optname, int level) {
|
|
395
|
-
int value;
|
|
396
|
-
socklen_t len;
|
|
397
|
-
|
|
398
|
-
len = sizeof(value);
|
|
399
|
-
if (::getsockopt(m_socket, level, optname, (char*) &value, &len) == SOCKET_ERROR) {
|
|
400
|
-
SocketErrorExit("Socket::get_option()");
|
|
401
|
-
}
|
|
402
|
-
return value;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
bool get_reuse_addr() {
|
|
406
|
-
return static_cast<bool>(get_option(SO_REUSEADDR, SOL_SOCKET));
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
void set_reuse_addr(bool on) {
|
|
410
|
-
set_option(SO_REUSEADDR, SOL_SOCKET, static_cast<int>(on));
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
int get_send_buffer_size() {
|
|
414
|
-
return get_option(SO_SNDBUF, SOL_SOCKET);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
void set_send_buffer_size(int size) {
|
|
418
|
-
set_option(SO_SNDBUF, SOL_SOCKET, size);
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
int get_rcv_buffer_size() {
|
|
422
|
-
return get_option(SO_RCVBUF, SOL_SOCKET);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
void set_rcv_buffer_size(int size) {
|
|
426
|
-
set_option(SO_RCVBUF, SOL_SOCKET, size);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
bool getaddrinfo(int family, int socktype, int protocol, const char * hostname, int port, CAddress & address, int flags = AI_PASSIVE) {
|
|
430
|
-
int err;
|
|
431
|
-
ADDRINFO hints;
|
|
432
|
-
ADDRINFO * t_addr;
|
|
433
|
-
char port_str[16] = {0};
|
|
434
|
-
|
|
435
|
-
ZeroOut(&hints, sizeof(hints));
|
|
436
|
-
hints.ai_family = family;
|
|
437
|
-
hints.ai_socktype = socktype;
|
|
438
|
-
hints.ai_protocol = protocol;
|
|
439
|
-
hints.ai_flags = flags;
|
|
440
|
-
::sprintf(port_str, "%d", port);
|
|
441
|
-
err = ::getaddrinfo(hostname, port_str, &hints, &t_addr);
|
|
442
|
-
if (err != 0) {
|
|
443
|
-
printf("%s\n", gai_strerror(err));
|
|
444
|
-
::freeaddrinfo(t_addr);
|
|
445
|
-
SocketErrorExit("getaddrinfo()");
|
|
446
|
-
return false;
|
|
447
|
-
}
|
|
448
|
-
address.length = t_addr->ai_addrlen;
|
|
449
|
-
CopyMemory(&address.address, t_addr->ai_addr, sizeof(SOCKADDR));
|
|
450
|
-
::freeaddrinfo(t_addr);
|
|
451
|
-
return true;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
void connect(CAddress & address) {
|
|
455
|
-
if (::connect(m_socket, &address.address, address.length) == SOCKET_ERROR) {
|
|
456
|
-
SocketErrorExit("Socket::connect()");
|
|
457
|
-
}
|
|
458
|
-
m_connected_socket = m_socket;
|
|
459
|
-
printf("Sock-conn: %d\n", m_connected_socket);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
void bind(CAddress & address) {
|
|
463
|
-
if (::bind(m_socket, &address.address, address.length) == SOCKET_ERROR) {
|
|
464
|
-
SocketErrorExit("Socket::bind()");
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
void listen(int backlog = 1) {
|
|
469
|
-
if (::listen(m_socket, backlog) == SOCKET_ERROR) {
|
|
470
|
-
SocketErrorExit("Socket::listen()");
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
void accept(CAddress & peerAddress) {
|
|
475
|
-
|
|
476
|
-
peerAddress.length = sizeof peerAddress.address;
|
|
477
|
-
m_connected_socket = ::accept(m_socket, (SOCKADDR *)&peerAddress.address, (socklen_t*)&peerAddress.length);
|
|
478
|
-
|
|
479
|
-
if (m_connected_socket == INVALID_SOCKET) {
|
|
480
|
-
SocketErrorExit("Socket::accept()");
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
void startReceiverThread() {
|
|
485
|
-
int res = 0;
|
|
486
|
-
|
|
487
|
-
m_thread = new std::thread(blockingReceiverThread, this);
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
void shutdownReceiverThread() {
|
|
491
|
-
int res = 0;
|
|
492
|
-
|
|
493
|
-
//res = ::pthread_kill(m_thread->native_handle(), SIGINT);
|
|
494
|
-
res = ::pthread_cancel(m_thread->native_handle());
|
|
495
|
-
if (res == -1) {
|
|
496
|
-
OsErrorExit("shutdownReceiverThread::pthread_kill");
|
|
497
|
-
}
|
|
498
|
-
m_thread->join();
|
|
499
|
-
delete m_thread;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
template <typename T, size_t N>
|
|
503
|
-
int read(std::array<T, N>& arr, size_t len) {
|
|
504
|
-
int nbytes;
|
|
505
|
-
|
|
506
|
-
nbytes = ::recv(m_connected_socket, (char*)arr.data(), len, 0);
|
|
507
|
-
if (nbytes == -1) {
|
|
508
|
-
OsErrorExit("read::recv");
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
return nbytes;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
template <typename T, size_t N>
|
|
515
|
-
void write(std::array<T, N>& arr) {
|
|
516
|
-
if (m_socktype == SOCK_DGRAM) {
|
|
517
|
-
#if 0
|
|
518
|
-
if (sendto(m_socket, (char const *)arr.data(), arr.size(), 0,
|
|
519
|
-
(SOCKADDR * )(SOCKADDR_STORAGE const *)&XcpTl_Connection.connectionAddress, ADDR_LEN) == SOCKET_ERROR) {
|
|
520
|
-
SocketErrorExit("send::sendto()");
|
|
521
|
-
}
|
|
522
|
-
#endif
|
|
523
|
-
} else if (m_socktype == SOCK_STREAM) {
|
|
524
|
-
if (::send(m_connected_socket, (char const *)arr.data(), arr.size(), 0) == SOCKET_ERROR) {
|
|
525
|
-
SocketErrorExit("send::send()");
|
|
526
|
-
#if defined(_WIN32)
|
|
527
|
-
closesocket(m_connected_socket);
|
|
528
|
-
#elif defined(__unix__)
|
|
529
|
-
close(m_connected_socket);
|
|
530
|
-
#endif
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
SOCKET getSocket() const {
|
|
536
|
-
return m_socket;
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
protected:
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
private:
|
|
543
|
-
int m_family;
|
|
544
|
-
int m_socktype;
|
|
545
|
-
int m_protocol;
|
|
546
|
-
bool m_connected;
|
|
547
|
-
addrinfo * m_addr;
|
|
548
|
-
std::thread * m_thread = nullptr;
|
|
549
|
-
//TimeoutTimer m_timeout {150};
|
|
550
|
-
|
|
551
|
-
SOCKET m_socket;
|
|
552
|
-
SOCKET m_connected_socket;
|
|
553
|
-
//CAddress ourAddress;
|
|
554
|
-
SOCKADDR_STORAGE m_peerAddress;
|
|
555
|
-
};
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
#endif // __BLOCKING_SOCKET_HPP
|
pyxcp/cxx/concurrent_queue.hpp
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
#if !defined(__CONCURRENT_QUEUE)
|
|
3
|
-
#define __CONCURRENT_QUEUE
|
|
4
|
-
|
|
5
|
-
#include <chrono>
|
|
6
|
-
#include <condition_variable>
|
|
7
|
-
#include <deque>
|
|
8
|
-
#include <mutex>
|
|
9
|
-
#include <queue>
|
|
10
|
-
|
|
11
|
-
template <typename _Ty> class ConcurrentQueue {
|
|
12
|
-
public:
|
|
13
|
-
|
|
14
|
-
explicit ConcurrentQueue<_Ty>() = default;
|
|
15
|
-
|
|
16
|
-
ConcurrentQueue<_Ty>(const ConcurrentQueue<_Ty>& other) noexcept :
|
|
17
|
-
m_elements(other.m_elements), m_mtx(), m_cond()
|
|
18
|
-
{}
|
|
19
|
-
|
|
20
|
-
bool empty() const {
|
|
21
|
-
std::unique_lock<std::mutex> lock(m_mtx);
|
|
22
|
-
|
|
23
|
-
return m_elements.empty();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
void enqueue(const _Ty& item) {
|
|
27
|
-
std::lock_guard<std::mutex> lock(m_mtx);
|
|
28
|
-
bool const empty = m_elements.empty();
|
|
29
|
-
|
|
30
|
-
m_elements.emplace_back(std::move(item));
|
|
31
|
-
m_mtx.unlock();
|
|
32
|
-
|
|
33
|
-
if (empty) {
|
|
34
|
-
m_cond.notify_one();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
bool dequeue(_Ty& item, uint32_t timeout = 50) {
|
|
40
|
-
std::unique_lock<std::mutex> lock(m_mtx);
|
|
41
|
-
|
|
42
|
-
while (m_elements.empty()) {
|
|
43
|
-
if (m_cond.wait_for(lock, std::chrono::milliseconds(timeout)) == std::cv_status::timeout) {
|
|
44
|
-
return false; // Wait timed out.
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
item = std::move(m_elements.front());
|
|
49
|
-
m_elements.pop_front();
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
private:
|
|
54
|
-
//std::queue<_Ty> m_elements {};
|
|
55
|
-
std::deque<_Ty> m_elements {};
|
|
56
|
-
mutable std::mutex m_mtx {};
|
|
57
|
-
std::condition_variable m_cond {};
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
#endif // __CONCURRENT_QUEUE
|
pyxcp/cxx/eth.hpp
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
#if !defined(__ETH_HPP)
|
|
2
|
-
#define __ETH_HPP
|
|
3
|
-
|
|
4
|
-
#if defined(_WIN32)
|
|
5
|
-
#include <WinSock2.h>
|
|
6
|
-
#else
|
|
7
|
-
#include <ctype.h>
|
|
8
|
-
#include <errno.h>
|
|
9
|
-
#include <fcntl.h>
|
|
10
|
-
#include <limits.h>
|
|
11
|
-
#include <signal.h>
|
|
12
|
-
#include <stdlib.h>
|
|
13
|
-
#include <stdio.h>
|
|
14
|
-
#include <string.h>
|
|
15
|
-
#include <time.h>
|
|
16
|
-
#include <stdbool.h>
|
|
17
|
-
#include <unistd.h>
|
|
18
|
-
#include <sys/types.h>
|
|
19
|
-
#include <sys/socket.h>
|
|
20
|
-
#include <netinet/in.h>
|
|
21
|
-
#include <netdb.h>
|
|
22
|
-
#include <arpa/inet.h>
|
|
23
|
-
#include <sys/wait.h>
|
|
24
|
-
#endif
|
|
25
|
-
|
|
26
|
-
#include "config.h"
|
|
27
|
-
#include "utils.hpp"
|
|
28
|
-
|
|
29
|
-
#include <stdio.h>
|
|
30
|
-
|
|
31
|
-
#if defined(_WIN32)
|
|
32
|
-
|
|
33
|
-
struct Eth {
|
|
34
|
-
|
|
35
|
-
Eth() {
|
|
36
|
-
WSAData data;
|
|
37
|
-
if (::WSAStartup(MAKEWORD(2, 2), &data) != 0) {
|
|
38
|
-
OsErrorExit("Eth::Eth() -- WSAStartup");
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
~Eth() {
|
|
43
|
-
::WSACleanup();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
#else
|
|
48
|
-
|
|
49
|
-
struct Eth {
|
|
50
|
-
|
|
51
|
-
Eth() = default;
|
|
52
|
-
~Eth() = default;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
#endif
|
|
56
|
-
|
|
57
|
-
#endif // __ETH_HPP
|
pyxcp/cxx/exceptions.hpp
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
#if !defined(__EXCEPTIONS_HPP)
|
|
2
|
-
#define __EXCEPTIONS_HPP
|
|
3
|
-
|
|
4
|
-
#include <exception>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
struct OSException : public std::exception {
|
|
8
|
-
const char * what () const throw() {
|
|
9
|
-
return "OS Exception";
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
struct TimeoutException : public std::exception {
|
|
14
|
-
const char * what () const throw() {
|
|
15
|
-
return "Timeout Exception";
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
struct CapacityExhaustedException : public std::exception {
|
|
20
|
-
const char * what () const throw() {
|
|
21
|
-
return "Capacity Exhausted Exception";
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
struct InvalidObjectException : public std::exception {
|
|
26
|
-
const char * what () const throw() {
|
|
27
|
-
return "Invalid Object Exception";
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
#endif // __EXCEPTIONS_HPP
|