pyxcp 0.21.9__cp311-cp311-win_amd64.whl → 0.22.23__cp311-cp311-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.cp310-win_amd64.pyd +0 -0
- pyxcp/cpp_ext/cpp_ext.cp311-win_amd64.pyd +0 -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.cp310-win_amd64.pyd +0 -0
- pyxcp/daq_stim/stim.cp311-win_amd64.pyd +0 -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 +196 -114
- 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.cp310-win_amd64.pyd +0 -0
- pyxcp/recorder/rekorder.cp311-win_amd64.pyd +0 -0
- 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.9.dist-info → pyxcp-0.22.23.dist-info}/METADATA +28 -23
- pyxcp-0.22.23.dist-info/RECORD +137 -0
- {pyxcp-0.21.9.dist-info → pyxcp-0.22.23.dist-info}/WHEEL +1 -1
- {pyxcp-0.21.9.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.9.dist-info/RECORD +0 -147
- rekorder.cp311-win_amd64.pyd +0 -0
- {pyxcp-0.21.9.dist-info/licenses → pyxcp-0.22.23.dist-info}/LICENSE +0 -0
pyxcp/cxx/iasyncioservice.hpp
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
*
|
|
3
|
-
* Interface for asynchronous I/O services (IOCP, epoll, kqueue...).
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
#if !defined(__IASYNCHIOSERVICE_HPP)
|
|
9
|
-
#define __IASYNCHIOSERVICE_HPP
|
|
10
|
-
|
|
11
|
-
#include <cstdlib>
|
|
12
|
-
#include <cstdint>
|
|
13
|
-
|
|
14
|
-
#include "socket.hpp"
|
|
15
|
-
|
|
16
|
-
enum class MessageCode : uint64_t {
|
|
17
|
-
QUIT,
|
|
18
|
-
TIMEOUT
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
class IAsyncIoService {
|
|
22
|
-
public:
|
|
23
|
-
virtual ~IAsyncIoService() = default;
|
|
24
|
-
virtual void registerSocket(Socket& socket) = 0;
|
|
25
|
-
virtual void postUserMessage(MessageCode messageCode, void * data = nullptr) const = 0;
|
|
26
|
-
virtual void postQuitMessage() const = 0;
|
|
27
|
-
virtual HANDLE getHandle() const = 0;
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
#endif // __IASYNCHIOSERVICE_HPP
|
pyxcp/cxx/iresource.hpp
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#if !defined(__IRESOURCE_HPP)
|
|
2
|
-
#define __IRESOURCE_HPP
|
|
3
|
-
|
|
4
|
-
/*
|
|
5
|
-
*
|
|
6
|
-
* Interface for pool-able resources.
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
class IResource {
|
|
10
|
-
public:
|
|
11
|
-
|
|
12
|
-
virtual ~IResource() = default;
|
|
13
|
-
virtual void reset() = 0;
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
#endif // __IRESOURCE_HPP
|
pyxcp/cxx/isocket.hpp
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#if !defined(__ISOCKET_HPP)
|
|
2
|
-
#define __ISOCKET_HPP
|
|
3
|
-
|
|
4
|
-
struct CAddress {
|
|
5
|
-
int length;
|
|
6
|
-
struct sockaddr address;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class ISocket {
|
|
11
|
-
public:
|
|
12
|
-
~ISocket() = default;
|
|
13
|
-
|
|
14
|
-
virtual void connect(CAddress & address) = 0;
|
|
15
|
-
virtual void bind(CAddress & address) = 0;
|
|
16
|
-
virtual void listen(int backlog = 10) = 0;
|
|
17
|
-
virtual void accept(CAddress & peerAddress) = 0;
|
|
18
|
-
virtual void option(int optname, int level, int * value) = 0;
|
|
19
|
-
virtual bool getaddrinfo(int family, int socktype, int protocol, const char * hostname, int port, CAddress & address, int flags = AI_PASSIVE) = 0;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
#endif // __ISOCKET_HPP
|
pyxcp/cxx/linux/epoll.cpp
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
#include "epoll.hpp"
|
|
2
|
-
|
|
3
|
-
constexpr size_t MAX_EVENTS = 8;
|
|
4
|
-
|
|
5
|
-
static struct epoll_event events[MAX_EVENTS];
|
|
6
|
-
|
|
7
|
-
void * WorkerThread(void * param)
|
|
8
|
-
{
|
|
9
|
-
Epoll const * const epoll = reinterpret_cast<Epoll const * const>(param);
|
|
10
|
-
Socket const * socket;
|
|
11
|
-
TimeoutTimer const * timeout_timer;
|
|
12
|
-
EventRecord * event_record;
|
|
13
|
-
int nfds;
|
|
14
|
-
int idx;
|
|
15
|
-
char buffer[128];
|
|
16
|
-
int evt_mask;
|
|
17
|
-
uint64_t timeout_value;
|
|
18
|
-
|
|
19
|
-
printf("Entering worker thread...\n");
|
|
20
|
-
|
|
21
|
-
for (;;) {
|
|
22
|
-
nfds = epoll_wait(epoll->getHandle() ,events, MAX_EVENTS, 500);
|
|
23
|
-
for (idx = 0; idx < nfds; ++idx) {
|
|
24
|
-
evt_mask = events[idx].events;
|
|
25
|
-
event_record = reinterpret_cast<EventRecord*>(events[idx].data.ptr);
|
|
26
|
-
printf("Evt#%d: %x %d\n", idx, evt_mask, event_record->event_type);
|
|
27
|
-
if (event_record->event_type == EventType::SOCKET) {
|
|
28
|
-
socket = event_record->obj.socket;
|
|
29
|
-
printf("Socket-Handle: %d\n", socket->getHandle());
|
|
30
|
-
if (evt_mask & EPOLLIN) {
|
|
31
|
-
read(socket->getHandle(), buffer, 128);
|
|
32
|
-
printf("R: %s\n", buffer);
|
|
33
|
-
} else if (evt_mask & EPOLLHUP) {
|
|
34
|
-
printf("HANG-UP\n");
|
|
35
|
-
//SocketErrorExit("HANG-UP");
|
|
36
|
-
} else if (evt_mask & EPOLLERR) {
|
|
37
|
-
SocketErrorExit("WorkerThread::epoll_wait()");
|
|
38
|
-
}
|
|
39
|
-
} else if (event_record->event_type == EventType::TIMEOUT) {
|
|
40
|
-
timeout_timer = event_record->obj.timeout_timer;
|
|
41
|
-
printf("Timeout-Handle: %d\n", timeout_timer->getHandle());
|
|
42
|
-
read(timeout_timer->getHandle(), &timeout_value, sizeof(uint64_t));
|
|
43
|
-
printf("Timeout\n");
|
|
44
|
-
} else {
|
|
45
|
-
printf("Invalid event type.\n");
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return nullptr;
|
|
51
|
-
}
|
pyxcp/cxx/linux/epoll.hpp
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#if !defined(__EPOLL_HPP)
|
|
2
|
-
#define __EPOLL_HPP
|
|
3
|
-
|
|
4
|
-
#include <memory>
|
|
5
|
-
#include <vector>
|
|
6
|
-
|
|
7
|
-
#include <unistd.h>
|
|
8
|
-
#include <pthread.h>
|
|
9
|
-
#include <sys/epoll.h>
|
|
10
|
-
|
|
11
|
-
#include "socket.hpp"
|
|
12
|
-
#include "iasyncioservice.hpp"
|
|
13
|
-
|
|
14
|
-
void * WorkerThread(void * param);
|
|
15
|
-
|
|
16
|
-
enum class EventType {
|
|
17
|
-
SOCKET,
|
|
18
|
-
TIMEOUT
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
struct EventRecord {
|
|
22
|
-
EventType event_type;
|
|
23
|
-
union {
|
|
24
|
-
Socket const * socket;
|
|
25
|
-
TimeoutTimer const * timeout_timer;
|
|
26
|
-
} obj;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
class Epoll : public IAsyncIoService {
|
|
30
|
-
public:
|
|
31
|
-
Epoll(size_t numProcessors = 1, size_t multiplier = 1) {
|
|
32
|
-
int ret;
|
|
33
|
-
|
|
34
|
-
m_epoll_fd = ::epoll_create(42);
|
|
35
|
-
ret = pthread_create(&m_worker_thread, nullptr, &WorkerThread, reinterpret_cast<void*>(this));
|
|
36
|
-
if (ret != 0) {
|
|
37
|
-
OsErrorExit("Epoll:Epoll() -- Create worker thread");
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
~Epoll() {
|
|
42
|
-
::close(m_epoll_fd);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
void registerSocket(Socket& socket) {
|
|
46
|
-
|
|
47
|
-
registerHandle(socket.getHandle(), reinterpret_cast<void const*>(&socket), EventType::SOCKET);
|
|
48
|
-
registerHandle(socket.getTimeout().getHandle(), reinterpret_cast<void const*>(&socket.getTimeout()), EventType::TIMEOUT);
|
|
49
|
-
printf("S: %d T: %d\n", socket.getHandle(), socket.getTimeout().getHandle());
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
void postUserMessage(MessageCode messageCode, void * data = nullptr) const {}
|
|
53
|
-
void postQuitMessage() const {}
|
|
54
|
-
|
|
55
|
-
HANDLE getHandle() const {
|
|
56
|
-
return m_epoll_fd;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
protected:
|
|
60
|
-
|
|
61
|
-
void registerHandle(HANDLE handle, void const * data_ptr, EventType event_type) {
|
|
62
|
-
|
|
63
|
-
struct epoll_event event;
|
|
64
|
-
auto event_record = std::make_shared<EventRecord>();
|
|
65
|
-
m_events.emplace_back(event_record);
|
|
66
|
-
|
|
67
|
-
event_record->event_type = event_type;
|
|
68
|
-
if (event_type == EventType::SOCKET) {
|
|
69
|
-
event_record->obj.socket = reinterpret_cast<Socket const*>(data_ptr);
|
|
70
|
-
} else if (event_type == EventType::TIMEOUT) {
|
|
71
|
-
event_record->obj.timeout_timer = static_cast<TimeoutTimer const*>(data_ptr);
|
|
72
|
-
}
|
|
73
|
-
event.data.ptr = event_record.get();
|
|
74
|
-
event.events = EPOLLIN;
|
|
75
|
-
if (::epoll_ctl(m_epoll_fd, EPOLL_CTL_ADD, handle, &event) == -1) {
|
|
76
|
-
OsErrorExit("Epoll::registerHandle()");
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private:
|
|
81
|
-
int m_epoll_fd;
|
|
82
|
-
pthread_t m_worker_thread;
|
|
83
|
-
std::vector<std::shared_ptr<EventRecord>> m_events;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
#endif // __EPOLL_HPP
|
pyxcp/cxx/linux/lit_tester.cpp
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
#include <iostream>
|
|
3
|
-
#include <chrono>
|
|
4
|
-
|
|
5
|
-
#include <cstdint>
|
|
6
|
-
|
|
7
|
-
using namespace std::literals;
|
|
8
|
-
using namespace std;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
int main()
|
|
12
|
-
{
|
|
13
|
-
// cout << static_cast<unsignedI>(23ms) << endl;
|
|
14
|
-
auto d1 = 250ns;
|
|
15
|
-
|
|
16
|
-
std::chrono::nanoseconds d2 = 1us;
|
|
17
|
-
std::cout << "250ns = " << d1.count() << " nanoseconds\n" << "1us = " << d2.count() << " nanoseconds\n";
|
|
18
|
-
|
|
19
|
-
}
|
pyxcp/cxx/linux/socket.hpp
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
#if !defined(__SOCKET_HPP)
|
|
2
|
-
#define __SOCKET_HPP
|
|
3
|
-
|
|
4
|
-
#include <array>
|
|
5
|
-
#include <ctype.h>
|
|
6
|
-
#include <errno.h>
|
|
7
|
-
#include <fcntl.h>
|
|
8
|
-
#include <limits.h>
|
|
9
|
-
#include <signal.h>
|
|
10
|
-
#include <stdlib.h>
|
|
11
|
-
#include <stdio.h>
|
|
12
|
-
#include <string.h>
|
|
13
|
-
#include <time.h>
|
|
14
|
-
#include <stdbool.h>
|
|
15
|
-
#include <unistd.h>
|
|
16
|
-
#include <sys/types.h>
|
|
17
|
-
#include <sys/socket.h>
|
|
18
|
-
#include <netinet/in.h>
|
|
19
|
-
#include <netdb.h>
|
|
20
|
-
#include <arpa/inet.h>
|
|
21
|
-
#include <sys/wait.h>
|
|
22
|
-
|
|
23
|
-
#include "isocket.hpp"
|
|
24
|
-
#include "utils.hpp"
|
|
25
|
-
#include "timeout.hpp"
|
|
26
|
-
|
|
27
|
-
#define SOCKET_ERROR (-1)
|
|
28
|
-
#define INVALID_SOCKET (-1)
|
|
29
|
-
|
|
30
|
-
using HANDLE = int;
|
|
31
|
-
using SOCKET = int;
|
|
32
|
-
|
|
33
|
-
class Socket : public ISocket {
|
|
34
|
-
public:
|
|
35
|
-
|
|
36
|
-
Socket(int family = PF_INET, int socktype = SOCK_STREAM, int protocol = IPPROTO_TCP) :
|
|
37
|
-
m_family(family), m_socktype(socktype), m_protocol(protocol), m_connected(false),
|
|
38
|
-
m_addr(nullptr), m_timeout(150) {
|
|
39
|
-
m_socket = ::socket(m_family, m_socktype, m_protocol);
|
|
40
|
-
if (m_socket == INVALID_SOCKET) {
|
|
41
|
-
SocketErrorExit("Socket::Socket()");
|
|
42
|
-
}
|
|
43
|
-
blocking(false);
|
|
44
|
-
ZeroOut(&m_peerAddress, sizeof(sockaddr_storage));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
~Socket() {
|
|
48
|
-
::close(m_socket);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
void blocking(bool enabled) {
|
|
52
|
-
int flags = fcntl(m_socket, F_GETFL);
|
|
53
|
-
|
|
54
|
-
if (flags == -1) {
|
|
55
|
-
SocketErrorExit("Socket::blocking()");
|
|
56
|
-
}
|
|
57
|
-
flags = enabled ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK);
|
|
58
|
-
if (fcntl(m_socket, F_SETFL, flags) == -1) {
|
|
59
|
-
SocketErrorExit("Socket::blocking()");
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
void option(int optname, int level, int * value) {
|
|
64
|
-
socklen_t len;
|
|
65
|
-
|
|
66
|
-
len = sizeof(*value);
|
|
67
|
-
if (*value == 0) {
|
|
68
|
-
::getsockopt(m_socket, level, optname, (char*) value, &len);
|
|
69
|
-
} else {
|
|
70
|
-
::setsockopt(m_socket, level, optname, (const char*) value, len);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
bool getaddrinfo(int family, int socktype, int protocol, const char * hostname, int port, CAddress & address, int flags = AI_PASSIVE) {
|
|
75
|
-
int err;
|
|
76
|
-
addrinfo hints;
|
|
77
|
-
addrinfo * t_addr;
|
|
78
|
-
char port_str[16] = {0};
|
|
79
|
-
|
|
80
|
-
ZeroOut(&hints, sizeof(hints));
|
|
81
|
-
hints.ai_family = family;
|
|
82
|
-
hints.ai_socktype = socktype;
|
|
83
|
-
hints.ai_protocol = protocol;
|
|
84
|
-
hints.ai_flags = flags;
|
|
85
|
-
|
|
86
|
-
::sprintf(port_str, "%d", port);
|
|
87
|
-
err = ::getaddrinfo(hostname, port_str, &hints, &t_addr);
|
|
88
|
-
if (err != 0) {
|
|
89
|
-
printf("%s\n", gai_strerror(err));
|
|
90
|
-
::freeaddrinfo(t_addr);
|
|
91
|
-
SocketErrorExit("getaddrinfo()");
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
address.length = t_addr->ai_addrlen;
|
|
96
|
-
::memcpy(&address.address, t_addr->ai_addr, sizeof(struct sockaddr));
|
|
97
|
-
|
|
98
|
-
::freeaddrinfo(t_addr);
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
void connect(CAddress & address) {
|
|
103
|
-
blocking(true);
|
|
104
|
-
if (::connect(m_socket, &address.address, address.length) == SOCKET_ERROR) {
|
|
105
|
-
if (errno != EINPROGRESS) {
|
|
106
|
-
SocketErrorExit("Socket::connect()");
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
blocking(false);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
void bind(CAddress & address) {
|
|
113
|
-
if (::bind(m_socket, &address.address, address.length) == SOCKET_ERROR) {
|
|
114
|
-
SocketErrorExit("Socket::bind()");
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
void listen(int backlog = 5) {
|
|
119
|
-
if (::listen(m_socket, backlog) == SOCKET_ERROR) {
|
|
120
|
-
SocketErrorExit("Socket::listen()");
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
void accept(CAddress & peerAddress) {
|
|
125
|
-
int sock;
|
|
126
|
-
|
|
127
|
-
peerAddress.length = sizeof peerAddress.address;
|
|
128
|
-
sock = ::accept(m_socket, (sockaddr *)&peerAddress.address, (socklen_t*)&peerAddress.length);
|
|
129
|
-
|
|
130
|
-
if (sock == INVALID_SOCKET) {
|
|
131
|
-
SocketErrorExit("Socket::accept()");
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
template <typename T, size_t N>
|
|
136
|
-
void write(std::array<T, N>& arr, bool alloc = true) {
|
|
137
|
-
size_t bytesWritten = 0;
|
|
138
|
-
int addrLen;
|
|
139
|
-
|
|
140
|
-
m_timeout.arm();
|
|
141
|
-
|
|
142
|
-
if (m_socktype == SOCK_DGRAM) {
|
|
143
|
-
#if 0
|
|
144
|
-
if (sendto(m_socket, (char const *)arr.data(), arr.size(), 0, (struct sockaddr const *)&XcpTl_Connection.connectionAddress, addrSize) == -1) {
|
|
145
|
-
SocketErrorExit("Socket::write() -- sendto()");
|
|
146
|
-
}
|
|
147
|
-
#endif
|
|
148
|
-
} else if (m_socktype == SOCK_STREAM) {
|
|
149
|
-
if (send(m_socket, (char const *)arr.data(), arr.size(), 0) == -1) {
|
|
150
|
-
SocketErrorExit("Socket::write() -- send()");
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
#if 0
|
|
154
|
-
//PerIoData * iod = new PerIoData(128);
|
|
155
|
-
PerIoData * iod;
|
|
156
|
-
|
|
157
|
-
if (alloc == true) {
|
|
158
|
-
iod = m_pool_mgr.get_iod().acquire();
|
|
159
|
-
//iod = m_iod_pool.acquire();
|
|
160
|
-
}
|
|
161
|
-
iod->reset();
|
|
162
|
-
iod->set_buffer(arr);
|
|
163
|
-
iod->set_opcode(IoType::IO_WRITE);
|
|
164
|
-
iod->set_transfer_length(arr.size());
|
|
165
|
-
if (m_socktype == SOCK_DGRAM) {
|
|
166
|
-
addrLen = sizeof(SOCKADDR_STORAGE);
|
|
167
|
-
if (::WSASendTo(m_socket,
|
|
168
|
-
iod->get_buffer(),
|
|
169
|
-
1,
|
|
170
|
-
&bytesWritten,
|
|
171
|
-
0,
|
|
172
|
-
(LPSOCKADDR)&m_peerAddress,
|
|
173
|
-
addrLen,
|
|
174
|
-
(LPWSAOVERLAPPED)iod,
|
|
175
|
-
nullptr
|
|
176
|
-
) == SOCKET_ERROR) {
|
|
177
|
-
// WSA_IO_PENDING
|
|
178
|
-
SocketErrorExit("Socket::send()");
|
|
179
|
-
}
|
|
180
|
-
} else if (m_socktype == SOCK_STREAM) {
|
|
181
|
-
if (::WSASend(
|
|
182
|
-
m_socket,
|
|
183
|
-
iod->get_buffer(),
|
|
184
|
-
1,
|
|
185
|
-
&bytesWritten,
|
|
186
|
-
0,
|
|
187
|
-
(LPWSAOVERLAPPED)iod,
|
|
188
|
-
nullptr) == SOCKET_ERROR) {
|
|
189
|
-
SocketErrorExit("Socket::send()");
|
|
190
|
-
closesocket(m_socket);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
#endif
|
|
194
|
-
printf("Status: %d bytes_written: %d\n", errno, bytesWritten);
|
|
195
|
-
}
|
|
196
|
-
#if 0
|
|
197
|
-
void read(size_t count) {
|
|
198
|
-
if ( (n = read(sockfd, line, MAXLINE)) < 0) {
|
|
199
|
-
if (errno == ECONNRESET) {
|
|
200
|
-
close(sockfd);
|
|
201
|
-
events[i].data.fd = -1;
|
|
202
|
-
} else printf("readline error\n");
|
|
203
|
-
} else if (n == 0) {
|
|
204
|
-
close(sockfd);
|
|
205
|
-
events[i].data.fd = -1;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
#endif
|
|
210
|
-
|
|
211
|
-
void triggerRead(unsigned int len);
|
|
212
|
-
|
|
213
|
-
HANDLE getHandle() const {
|
|
214
|
-
return m_socket;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const TimeoutTimer& getTimeout() const {
|
|
218
|
-
return m_timeout;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
private:
|
|
222
|
-
int m_family;
|
|
223
|
-
int m_socktype;
|
|
224
|
-
int m_protocol;
|
|
225
|
-
bool m_connected;
|
|
226
|
-
// PoolManager m_pool_mgr;
|
|
227
|
-
addrinfo * m_addr;
|
|
228
|
-
TimeoutTimer m_timeout {150};
|
|
229
|
-
int m_socket;
|
|
230
|
-
//CAddress ourAddress;
|
|
231
|
-
sockaddr_storage m_peerAddress;
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
#endif // __SOCKET_HPP
|
pyxcp/cxx/linux/timeout.hpp
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
#if !defined(__TIMEOUT_HPP)
|
|
3
|
-
#define __TIMEOUT_HPP
|
|
4
|
-
|
|
5
|
-
#include <sys/timerfd.h>
|
|
6
|
-
#include <time.h>
|
|
7
|
-
#include <unistd.h>
|
|
8
|
-
#include <stdlib.h>
|
|
9
|
-
#include <stdio.h>
|
|
10
|
-
#include <stdint.h>
|
|
11
|
-
|
|
12
|
-
#include "utils.hpp"
|
|
13
|
-
|
|
14
|
-
#include <chrono>
|
|
15
|
-
|
|
16
|
-
using namespace std::literals;
|
|
17
|
-
|
|
18
|
-
/*
|
|
19
|
-
*
|
|
20
|
-
* Implements a file descriptor based time-out.
|
|
21
|
-
*
|
|
22
|
-
* Resolution is milli-seconds.
|
|
23
|
-
*
|
|
24
|
-
* Could be used together with poll(), epoll(), or select().
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
class TimeoutTimer {
|
|
29
|
-
public:
|
|
30
|
-
|
|
31
|
-
explicit TimeoutTimer(uint64_t value) : m_millis(value), m_timer_fd(-1) {
|
|
32
|
-
m_timer_fd = ::timerfd_create(CLOCK_MONOTONIC, 0);
|
|
33
|
-
if (m_timer_fd == -1)
|
|
34
|
-
OsErrorExit("TimeoutTimer::TimeoutTimer() -- timerfd_create");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
~TimeoutTimer() {
|
|
38
|
-
::close(m_timer_fd);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
void arm() {
|
|
42
|
-
struct itimerspec new_value {0};
|
|
43
|
-
|
|
44
|
-
new_value.it_interval = {0};
|
|
45
|
-
new_value.it_value.tv_sec = m_millis / 1000;
|
|
46
|
-
new_value.it_value.tv_nsec = (m_millis % 1000) * (1000 * 1000);
|
|
47
|
-
|
|
48
|
-
settime(new_value);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
void disarm() {
|
|
52
|
-
struct itimerspec new_value {0};
|
|
53
|
-
|
|
54
|
-
settime(new_value);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
int getHandle() const {
|
|
58
|
-
return m_timer_fd;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
uint64_t getValue() const {
|
|
62
|
-
return m_millis;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
void setValue(uint64_t new_millis) {
|
|
66
|
-
m_millis = new_millis;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private:
|
|
70
|
-
|
|
71
|
-
void settime(const itimerspec& new_value) {
|
|
72
|
-
if (::timerfd_settime(m_timer_fd, 0, &new_value, nullptr) == -1) {
|
|
73
|
-
OsErrorExit("TimeoutTimer::disarm() -- timerfd_settime");
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
uint64_t m_millis;
|
|
78
|
-
int m_timer_fd;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
#endif // __TIMEOUT_HPP
|
pyxcp/cxx/memoryblock.hpp
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
#if !defined(__MEMORYBLOCK_HPP)
|
|
2
|
-
#define __MEMORYBLOCK_HPP
|
|
3
|
-
|
|
4
|
-
#include "iresource.hpp"
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
*
|
|
8
|
-
* Fixed size memory block.
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
template <typename T, int N> class MemoryBlock : IResource {
|
|
12
|
-
|
|
13
|
-
public:
|
|
14
|
-
|
|
15
|
-
explicit MemoryBlock() : m_memory(nullptr) {
|
|
16
|
-
m_memory = new T[N];
|
|
17
|
-
//printf("MemBlock-ctor: %p\n", m_memory);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
~MemoryBlock() {
|
|
21
|
-
//printf("MemoryBlock-dtor: %p\n", m_memory);
|
|
22
|
-
if (m_memory) {
|
|
23
|
-
delete[] m_memory;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
T * data() {
|
|
28
|
-
return m_memory;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
void reset() {
|
|
32
|
-
#if !defined(NDEBUG)
|
|
33
|
-
|
|
34
|
-
#endif
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
private:
|
|
38
|
-
T * m_memory;
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
#endif // __MEMORYBLOCK_HPP
|
pyxcp/cxx/pool.hpp
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
#if !defined(__POOL_H)
|
|
2
|
-
#define __POOL_H
|
|
3
|
-
|
|
4
|
-
#include <algorithm>
|
|
5
|
-
#include <list>
|
|
6
|
-
#include <deque>
|
|
7
|
-
#include <mutex>
|
|
8
|
-
#include <thread>
|
|
9
|
-
|
|
10
|
-
#include "exceptions.hpp"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/*
|
|
14
|
-
*
|
|
15
|
-
* Fixed-size generic resource pool.
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
template <typename Obj> void dump(std::deque<Obj>& list) {
|
|
20
|
-
|
|
21
|
-
for (auto elem: list) {
|
|
22
|
-
printf("%p ", elem);
|
|
23
|
-
}
|
|
24
|
-
printf("\n");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
template<typename Obj, int N> class Pool {
|
|
28
|
-
public:
|
|
29
|
-
|
|
30
|
-
explicit Pool() : m_mtx(), m_high_water_mark(N), m_allocation_count(0) {
|
|
31
|
-
for (size_t i = 0; i < N; ++i) {
|
|
32
|
-
m_free_objs.push_back(new Obj());
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
~Pool() noexcept {
|
|
37
|
-
for (auto elem: m_used_objs) {
|
|
38
|
-
delete elem;
|
|
39
|
-
}
|
|
40
|
-
for (auto elem: m_free_objs) {
|
|
41
|
-
delete elem;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
Obj * acquire() {
|
|
46
|
-
const std::lock_guard<std::mutex> lock(m_mtx);
|
|
47
|
-
if (m_free_objs.empty()) {
|
|
48
|
-
throw CapacityExhaustedException();
|
|
49
|
-
}
|
|
50
|
-
auto obj = m_free_objs.front();
|
|
51
|
-
m_free_objs.pop_front();
|
|
52
|
-
m_used_objs.push_back(obj);
|
|
53
|
-
//printf("ACQ %p\n", obj);
|
|
54
|
-
return obj;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
void release(Obj * obj)
|
|
58
|
-
{
|
|
59
|
-
const std::lock_guard<std::mutex> lock(m_mtx);
|
|
60
|
-
//printf("REL: %p\n", obj);
|
|
61
|
-
auto iter = std::find(std::begin(m_used_objs), std::end(m_used_objs), obj);
|
|
62
|
-
auto found = iter != std::end(m_used_objs);
|
|
63
|
-
if (found) {
|
|
64
|
-
obj->reset();
|
|
65
|
-
m_free_objs.push_front(obj);
|
|
66
|
-
m_used_objs.erase(iter);
|
|
67
|
-
} else {
|
|
68
|
-
throw InvalidObjectException();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private:
|
|
73
|
-
|
|
74
|
-
std::mutex m_mtx;
|
|
75
|
-
size_t m_high_water_mark;
|
|
76
|
-
size_t m_allocation_count;
|
|
77
|
-
std::deque<Obj*> m_used_objs;
|
|
78
|
-
std::deque<Obj*> m_free_objs;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
#endif // __POOL_H
|