AsyncFw 1.2
Async Framework is c++ runtime with timers, poll notifiers, sockets, coroutines, etc.
 
Loading...
Searching...
No Matches
DataArrayAbstractTcp.h
1/*
2Copyright (c) 2026 Alexandr Kuzmuk
3
4This file is part of the AsyncFw project. Licensed under the MIT License.
5See {Link: LICENSE file https://mit-license.org} in the project root for full license information.
6*/
7
8#pragma once
9
10#include "../core/FunctionConnector.h"
11#include "ThreadPool.h"
12
13namespace AsyncFw {
14class DataArraySocket;
15class DataArray;
16class TlsContext;
17
19class DataArrayAbstractTcp : public AbstractThreadPool {
20public:
21 enum Result {
22 ErrorTransmitInvoke = -100,
23 ErrorTransmitNotActive = -101,
24 ErrorTransmit = -102,
25 };
26 DataArrayAbstractTcp(const std::string &);
27 void init(int readTimeout = 30000, int waitKeepAliveAnswerTimeout = 0, int waitForEncryptedTimeout = 10000, int maxThreads = 4, int maxSockets = 8, int maxReadBuffers = 16, int maxReadSize = 16 * 1024 * 1024, int maxWriteBuffers = 16, int maxWriteSize = 16 * 1024 * 1024, int socketReadBufferSize = 1024 * 512) {
28 this->readTimeout = readTimeout;
29 this->waitKeepAliveAnswerTimeout = waitKeepAliveAnswerTimeout;
30 this->waitForEncryptedTimeout = waitForEncryptedTimeout;
31 this->maxThreads = maxThreads;
32 this->maxSockets = maxSockets;
33 this->maxReadBuffers = maxReadBuffers;
34 this->maxReadSize = maxReadSize;
35 this->maxWriteBuffers = maxWriteBuffers;
36 this->maxWriteSize = maxWriteSize;
37 this->socketReadBufferSize = socketReadBufferSize;
38 }
39 int transmit(const DataArraySocket *, const DataArray &, uint32_t, bool = false);
40 void disconnectFromHost(const DataArraySocket *);
41 int sockets(std::vector<DataArraySocket *> * = nullptr);
42
43 FunctionConnectorProtected<DataArrayAbstractTcp>::Connector<const DataArraySocket *, const DataArray *, uint32_t> received {AbstractFunctionConnector::DirectOnly};
44
45 void setEncryptDisabled(const std::vector<std::string> &list) { disabledEncrypt_ = list; }
46 void setEncryptDisabled(const std::string &, bool = true);
47 void initTls(DataArraySocket *, const TlsContext &);
48
49protected:
50 class Thread : public AbstractThreadPool::Thread {
51 friend class DataArrayAbstractTcp;
52
53 public:
54 Thread(const std::string &name, DataArrayAbstractTcp *_pool) : AbstractThreadPool::Thread(name, _pool), pool(_pool) {};
55
56 protected:
57 void socketInit(DataArraySocket *);
58 void removeSocket(DataArraySocket *);
59 AbstractThreadPool *pool;
60 };
61 Thread *findMinimalSocketsThread();
62 int readTimeout;
63 int waitKeepAliveAnswerTimeout;
64 int waitForEncryptedTimeout;
65 std::size_t maxThreads;
66 std::size_t maxSockets;
67 int socketReadBufferSize;
68 int maxReadBuffers;
69 int maxReadSize;
70 int maxWriteBuffers;
71 int maxWriteSize;
72 std::vector<std::string> disabledEncrypt_ = {"127.0.0.1"};
73};
74} // namespace AsyncFw
The DataArraySocket class.
Definition DataArraySocket.h:17
The DataArray class.
Definition DataArray.h:20
The TlsContext class provides functionality for managing TLS certificates.
Definition TlsContext.h:24