@litmusio/miravo-cli-linux-x64 0.0.0-stage → 0.15.10
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.
- package/LICENSE +199 -0
- package/NOTICE +9 -0
- package/README.md +6 -2
- package/THIRD_PARTY_LICENSES.txt +15289 -0
- package/THIRD_PARTY_NOTICES.md +995 -0
- package/console-dist/assets/AnimatePresence-DWGUB15i.js +9 -0
- package/console-dist/assets/activity-DruTYzT1.js +1 -0
- package/console-dist/assets/api-V5Tf5xfh.js +57 -0
- package/console-dist/assets/arrow-up-right-DOENs04V.js +1 -0
- package/console-dist/assets/asset-detail-D_icTa2K.js +1 -0
- package/console-dist/assets/asset-detail-actions-DIYego9D.js +1 -0
- package/console-dist/assets/backup-power-Q84DVs_z.js +1 -0
- package/console-dist/assets/badge-CdRB4Nd_.js +1 -0
- package/console-dist/assets/boiler-s_q0j7rz.js +1 -0
- package/console-dist/assets/by-path-Cm2TEP7z.js +1 -0
- package/console-dist/assets/check-BTUv4z-H.js +1 -0
- package/console-dist/assets/chevron-down-CqA_2_CH.js +1 -0
- package/console-dist/assets/chevron-right-CVrgKBLR.js +1 -0
- package/console-dist/assets/chiller-r7DzAhJq.js +1 -0
- package/console-dist/assets/chunk-6KYCQHYJ-ga3Yekab.js +3 -0
- package/console-dist/assets/circle-x-BRkh0A1P.js +1 -0
- package/console-dist/assets/commercial-building-Cezt2R6W.js +1 -0
- package/console-dist/assets/compressor-ChZLMC94.js +1 -0
- package/console-dist/assets/console-panel-BnSjjW6l.js +1 -0
- package/console-dist/assets/dialog-BYkdndf9.js +1 -0
- package/console-dist/assets/district-heating-By_6QdGQ.js +1 -0
- package/console-dist/assets/dom-BxZbg3NX.js +1 -0
- package/console-dist/assets/download-CvjDP5mu.js +1 -0
- package/console-dist/assets/fira-code-cyrillic-ext-wght-normal-DhYMMuQd.woff2 +0 -0
- package/console-dist/assets/fira-code-cyrillic-wght-normal-Y3u8pIsh.woff2 +0 -0
- package/console-dist/assets/fira-code-greek-ext-wght-normal-wWus70Ix.woff2 +0 -0
- package/console-dist/assets/fira-code-greek-wght-normal-B2SviObF.woff2 +0 -0
- package/console-dist/assets/fira-code-latin-ext-wght-normal-Dvfvaomy.woff2 +0 -0
- package/console-dist/assets/fira-code-latin-wght-normal-CHoedHDv.woff2 +0 -0
- package/console-dist/assets/fira-code-symbols2-wght-normal-CE6EOz_n.woff2 +0 -0
- package/console-dist/assets/floor-page-DIUJBBhh.js +1 -0
- package/console-dist/assets/floor-page-E-0txA4z.css +1 -0
- package/console-dist/assets/format-YLUJ7AXt.js +1 -0
- package/console-dist/assets/genset-C6_EUoFo.js +1 -0
- package/console-dist/assets/index-BrlZMcSu.js +15 -0
- package/console-dist/assets/index-eZjXAdLh.css +2 -0
- package/console-dist/assets/loader-circle-w3T2fxvn.js +1 -0
- package/console-dist/assets/login-CpbaxAVs.js +136 -0
- package/console-dist/assets/not-found-CZjkulKD.js +1 -0
- package/console-dist/assets/pharma-cleanroom-CT2M_Mbh.js +1 -0
- package/console-dist/assets/preload-helper-7y9sWmk5.js +1 -0
- package/console-dist/assets/react-DRt7cCXI.js +1 -0
- package/console-dist/assets/rolldown-runtime-BWaJ3C7D.js +1 -0
- package/console-dist/assets/rtu-ByogcRPI.js +1 -0
- package/console-dist/assets/runtime-link-D88Db2wY.js +1 -0
- package/console-dist/assets/schibsted-grotesk-latin-ext-wght-normal-hsMS0n0O.woff2 +0 -0
- package/console-dist/assets/schibsted-grotesk-latin-wght-normal-Bb8VGrTG.woff2 +0 -0
- package/console-dist/assets/server-B0q1NVkV.js +1 -0
- package/console-dist/assets/shallow-mIK1Qu8X.js +1 -0
- package/console-dist/assets/smart-factory-gfMWfMWM.js +1 -0
- package/console-dist/assets/source-host-miravo-BW-SKMTe.js +1 -0
- package/console-dist/assets/stages-EYRT12Yp.js +1 -0
- package/console-dist/assets/status-DQYLUbXs.js +1 -0
- package/console-dist/assets/tank-Btg5piqB.js +1 -0
- package/console-dist/assets/tooltip-Dfmuq2yz.js +1 -0
- package/console-dist/assets/trash-2-BAh5-hxl.js +1 -0
- package/console-dist/assets/triangle-alert-3Ab-dBrN.js +1 -0
- package/console-dist/assets/use-engine-command-mutation-BmSUqrCp.js +1 -0
- package/console-dist/assets/use-transition-navigate-DIfW9U34.js +2 -0
- package/console-dist/assets/useQuery-yLeYL5Es.js +1 -0
- package/console-dist/assets/utils-D6wrZy-b.js +1 -0
- package/console-dist/assets/validation-DEb_QCoK.js +1 -0
- package/console-dist/assets/vendor-charts-Bquh2dWE.js +56 -0
- package/console-dist/assets/vendor-table-5YnGQUhO.js +4 -0
- package/console-dist/assets/vendor-ui-BGeFlRLR.js +1 -0
- package/console-dist/assets/water-treatment-DbSVGWoj.js +1 -0
- package/console-dist/icon.png +0 -0
- package/console-dist/index.html +53 -0
- package/console-dist/miravo-logo.webp +0 -0
- package/licenses/EPL-2.0.txt +80 -0
- package/licenses/GCC-exception-3.1.txt +33 -0
- package/licenses/GPL-2.0-only.txt +117 -0
- package/licenses/GPL-3.0-only.txt +232 -0
- package/licenses/LGPL-2.1-only.txt +176 -0
- package/licenses/MPL-2.0.txt +373 -0
- package/licenses/OFL-1.1.txt +93 -0
- package/licenses/overrides/@headlessui+vue@1.7.23.txt +24 -0
- package/licenses/overrides/@next+env@16.4.6.txt +24 -0
- package/licenses/overrides/@radix-ui+react-compose-refs@1.1.2.txt +24 -0
- package/licenses/overrides/@radix-ui+react-context@1.1.2.txt +24 -0
- package/licenses/overrides/@radix-ui+react-direction@1.1.1.txt +24 -0
- package/licenses/overrides/@radix-ui+react-id@1.1.1.txt +24 -0
- package/licenses/overrides/@radix-ui+react-use-callback-ref@1.1.1.txt +24 -0
- package/licenses/overrides/@radix-ui+react-use-escape-keydown@1.1.1.txt +24 -0
- package/licenses/overrides/@radix-ui+react-use-layout-effect@1.1.1.txt +24 -0
- package/licenses/overrides/@radix-ui+react-use-rect@1.1.1.txt +24 -0
- package/licenses/overrides/@radix-ui+react-use-size@1.1.1.txt +24 -0
- package/licenses/overrides/@radix-ui+rect@1.1.1.txt +24 -0
- package/licenses/overrides/@replit+codemirror-css-color-picker@6.3.0.txt +6 -0
- package/licenses/overrides/@scalar+openapi-types@0.8.0.txt +24 -0
- package/licenses/overrides/@scalar+openapi-types@0.9.10.txt +24 -0
- package/licenses/overrides/@scalar+openapi-types@0.9.7.txt +24 -0
- package/licenses/overrides/@scalar+openapi-types@0.9.9.txt +24 -0
- package/licenses/overrides/@scalar+postman-to-openapi@0.7.1.txt +24 -0
- package/licenses/overrides/@scalar+schemas@0.19.0.txt +24 -0
- package/licenses/overrides/@scalar+workspace-store@0.46.3.txt +24 -0
- package/licenses/overrides/@scalar+workspace-store@0.75.0.txt +24 -0
- package/licenses/overrides/assert-plus@1.0.0.txt +24 -0
- package/licenses/overrides/client-only@0.0.1.txt +24 -0
- package/licenses/overrides/embla-carousel-react@8.6.0.txt +24 -0
- package/licenses/overrides/embla-carousel-reactive-utils@8.6.0.txt +24 -0
- package/licenses/overrides/embla-carousel@8.6.0.txt +24 -0
- package/licenses/overrides/fastdom@1.0.12.txt +12 -0
- package/licenses/overrides/precond@0.2.3.txt +22 -0
- package/licenses/overrides/react-remove-scroll-bar@2.3.8.txt +24 -0
- package/licenses/overrides/strictdom@1.0.1.txt +12 -0
- package/licenses/overrides/victory-vendor@36.9.2.txt +33 -0
- package/licenses/runtime/Bun-1.4.3-LICENSE.md +85 -0
- package/licenses/runtime/ICU-78.1-LICENSE.txt +568 -0
- package/licenses/runtime/bun-components/boringssl.txt +238 -0
- package/licenses/runtime/bun-components/brotli.txt +19 -0
- package/licenses/runtime/bun-components/c-ares.txt +24 -0
- package/licenses/runtime/bun-components/highway.txt +371 -0
- package/licenses/runtime/bun-components/libarchive.txt +65 -0
- package/licenses/runtime/bun-components/libbase64.txt +28 -0
- package/licenses/runtime/bun-components/libdeflate.txt +22 -0
- package/licenses/runtime/bun-components/libjpeg-turbo.txt +147 -0
- package/licenses/runtime/bun-components/libspng.txt +25 -0
- package/licenses/runtime/bun-components/libuv.txt +19 -0
- package/licenses/runtime/bun-components/libwebp.txt +30 -0
- package/licenses/runtime/bun-components/llvm.txt +311 -0
- package/licenses/runtime/bun-components/lol-html.txt +27 -0
- package/licenses/runtime/bun-components/ls-hpack.txt +21 -0
- package/licenses/runtime/bun-components/ls-qpack.txt +21 -0
- package/licenses/runtime/bun-components/lsquic-chrome.txt +32 -0
- package/licenses/runtime/bun-components/lsquic.txt +21 -0
- package/licenses/runtime/bun-components/mimalloc.txt +21 -0
- package/licenses/runtime/bun-components/picohttpparser.txt +24 -0
- package/licenses/runtime/bun-components/simdutf-apache.txt +201 -0
- package/licenses/runtime/bun-components/simdutf-mit.txt +18 -0
- package/licenses/runtime/bun-components/tigerbeetle.txt +177 -0
- package/licenses/runtime/bun-components/tinycc.txt +504 -0
- package/licenses/runtime/bun-components/typescript-go.txt +55 -0
- package/licenses/runtime/bun-components/usockets.txt +201 -0
- package/licenses/runtime/bun-components/uucode.txt +30 -0
- package/licenses/runtime/bun-components/uwebsockets.txt +201 -0
- package/licenses/runtime/bun-components/xxhash.txt +31 -0
- package/licenses/runtime/bun-components/zlib-ng.txt +19 -0
- package/licenses/runtime/bun-components/zstd-copying.txt +339 -0
- package/licenses/runtime/bun-components/zstd.txt +30 -0
- package/licenses/runtime/musl-1.2.6-COPYRIGHT.txt +193 -0
- package/miravo +4 -0
- package/native/S7-NOTICES.txt +11 -0
- package/native/miravo-s7.node +0 -0
- package/native/s7-source/CMakeLists.txt +23 -0
- package/native/s7-source/NODE-SNAP7-LICENSE +24 -0
- package/native/s7-source/addon.cpp +124 -0
- package/native/s7-source/bridge.cpp +150 -0
- package/native/s7-source/node-api-headers/LICENSE +21 -0
- package/native/s7-source/node-api-headers/include/js_native_api.h +591 -0
- package/native/s7-source/node-api-headers/include/js_native_api_types.h +213 -0
- package/native/s7-source/node-api-headers/include/node_api.h +265 -0
- package/native/s7-source/node-api-headers/include/node_api_types.h +58 -0
- package/native/s7-source/node-api-windows.h +78 -0
- package/native/s7-source/snap7/HISTORY.txt +277 -0
- package/native/s7-source/snap7/gpl.txt +674 -0
- package/native/s7-source/snap7/lgpl-3.0.txt +165 -0
- package/native/s7-source/snap7/src/core/miravo_request_validation.h +72 -0
- package/native/s7-source/snap7/src/core/s7_client.cpp +503 -0
- package/native/s7-source/snap7/src/core/s7_client.h +104 -0
- package/native/s7-source/snap7/src/core/s7_firmware.h +1256 -0
- package/native/s7-source/snap7/src/core/s7_isotcp.cpp +541 -0
- package/native/s7-source/snap7/src/core/s7_isotcp.h +271 -0
- package/native/s7-source/snap7/src/core/s7_micro_client.cpp +3328 -0
- package/native/s7-source/snap7/src/core/s7_micro_client.h +364 -0
- package/native/s7-source/snap7/src/core/s7_partner.cpp +1178 -0
- package/native/s7-source/snap7/src/core/s7_partner.h +284 -0
- package/native/s7-source/snap7/src/core/s7_peer.cpp +121 -0
- package/native/s7-source/snap7/src/core/s7_peer.h +58 -0
- package/native/s7-source/snap7/src/core/s7_server.cpp +2161 -0
- package/native/s7-source/snap7/src/core/s7_server.h +261 -0
- package/native/s7-source/snap7/src/core/s7_text.cpp +788 -0
- package/native/s7-source/snap7/src/core/s7_text.h +49 -0
- package/native/s7-source/snap7/src/core/s7_types.h +1066 -0
- package/native/s7-source/snap7/src/lib/snap7.def +129 -0
- package/native/s7-source/snap7/src/lib/snap7_libmain.cpp +1196 -0
- package/native/s7-source/snap7/src/lib/snap7_libmain.h +201 -0
- package/native/s7-source/snap7/src/sys/snap_msgsock.cpp +958 -0
- package/native/s7-source/snap7/src/sys/snap_msgsock.h +339 -0
- package/native/s7-source/snap7/src/sys/snap_platform.h +152 -0
- package/native/s7-source/snap7/src/sys/snap_sysutils.cpp +73 -0
- package/native/s7-source/snap7/src/sys/snap_sysutils.h +39 -0
- package/native/s7-source/snap7/src/sys/snap_tcpsrvr.cpp +487 -0
- package/native/s7-source/snap7/src/sys/snap_tcpsrvr.h +247 -0
- package/native/s7-source/snap7/src/sys/snap_threads.cpp +162 -0
- package/native/s7-source/snap7/src/sys/snap_threads.h +45 -0
- package/native/s7-source/snap7/src/sys/sol_threads.h +208 -0
- package/native/s7-source/snap7/src/sys/unix_threads.h +228 -0
- package/native/s7-source/snap7/src/sys/win_threads.h +159 -0
- package/nodesets/.ignore +1 -0
- package/nodesets/1.02/FTNIR.NodeSet2.xml +819 -0
- package/nodesets/1.02/Opc.Ua.Adi.NodeSet2.xml +8301 -0
- package/nodesets/1.02/Opc.Ua.Di.NodeSet2.xml +1785 -0
- package/nodesets/Opc.ISA95.NodeSet2.xml +3589 -0
- package/nodesets/Opc.Ua.AMB.NodeSet2.xml +1395 -0
- package/nodesets/Opc.Ua.Adi.NodeSet2.xml +8301 -0
- package/nodesets/Opc.Ua.Adi.Types.xsd +104 -0
- package/nodesets/Opc.Ua.AutoID.NodeSet2.xml +6062 -0
- package/nodesets/Opc.Ua.CNC.NodeSet.xml +15875 -0
- package/nodesets/Opc.Ua.CommercialKitchenEquipment.NodeSet2.xml +12096 -0
- package/nodesets/Opc.Ua.Di.NodeSet2.xml +6042 -0
- package/nodesets/Opc.Ua.Di.Types.xsd +161 -0
- package/nodesets/Opc.Ua.Eumabois.Nodeset2.xml +2483 -0
- package/nodesets/Opc.Ua.Gds.NodeSet2.xml +8282 -0
- package/nodesets/Opc.Ua.Glass.NodeSet2.xml +5100 -0
- package/nodesets/Opc.Ua.IA.NodeSet2.xml +1782 -0
- package/nodesets/Opc.Ua.IOLink.NodeSet2.xml +4374 -0
- package/nodesets/Opc.Ua.IOLinkIODD.NodeSet2.xml +139 -0
- package/nodesets/Opc.Ua.IRDI.NodeSet2.xml +2243 -0
- package/nodesets/Opc.Ua.Ijt.Base.NodeSet2.xml +19459 -0
- package/nodesets/Opc.Ua.Ijt.Tightening.NodeSet2.xml +883 -0
- package/nodesets/Opc.Ua.LADS.NodeSet2.xml +7086 -0
- package/nodesets/Opc.Ua.MachineTool.NodeSet2.xml +7884 -0
- package/nodesets/Opc.Ua.MachineVision.NodeSet2.xml +17324 -0
- package/nodesets/Opc.Ua.Machinery.Jobs.Nodeset2.xml +1249 -0
- package/nodesets/Opc.Ua.Machinery.NodeSet2.xml +2099 -0
- package/nodesets/Opc.Ua.Machinery.ProcessValues.NodeSet2.xml +1858 -0
- package/nodesets/Opc.Ua.Machinery_Result.NodeSet2.xml +2640 -0
- package/nodesets/Opc.Ua.MetalForming.NodeSet2.xml +1577 -0
- package/nodesets/Opc.Ua.NodeSet2.xml +81975 -0
- package/nodesets/Opc.Ua.PADIM.NodeSet2.xml +14131 -0
- package/nodesets/Opc.Ua.PackML.NodeSet2.xml +3030 -0
- package/nodesets/Opc.Ua.Robotics.NodeSet2.xml +7409 -0
- package/nodesets/Opc.Ua.Scales.NodeSet2.xml +15817 -0
- package/nodesets/Opc.Ua.Types.bsd +3499 -0
- package/nodesets/Opc.Ua.Weihenstephan.NodeSet2.xml +821 -0
- package/nodesets/Opc.Ua.Woodworking.NodeSet2.xml +17831 -0
- package/nodesets/UANodeSet.xsd +497 -0
- package/nodesets/opc.ua.isa95-jobcontrol.nodeset2.xml +4594 -0
- package/package.json +37 -4
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
/*=============================================================================|
|
|
2
|
+
| PROJECT SNAP7 1.3.0 |
|
|
3
|
+
|==============================================================================|
|
|
4
|
+
| Copyright (C) 2013, 2015 Davide Nardella |
|
|
5
|
+
| All rights reserved. |
|
|
6
|
+
|==============================================================================|
|
|
7
|
+
| SNAP7 is free software: you can redistribute it and/or modify |
|
|
8
|
+
| it under the terms of the Lesser GNU General Public License as published by |
|
|
9
|
+
| the Free Software Foundation, either version 3 of the License, or |
|
|
10
|
+
| (at your option) any later version. |
|
|
11
|
+
| |
|
|
12
|
+
| It means that you can distribute your commercial software linked with |
|
|
13
|
+
| SNAP7 without the requirement to distribute the source code of your |
|
|
14
|
+
| application and without the requirement that your application be itself |
|
|
15
|
+
| distributed under LGPL. |
|
|
16
|
+
| |
|
|
17
|
+
| SNAP7 is distributed in the hope that it will be useful, |
|
|
18
|
+
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
19
|
+
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
20
|
+
| Lesser GNU General Public License for more details. |
|
|
21
|
+
| |
|
|
22
|
+
| You should have received a copy of the GNU General Public License and a |
|
|
23
|
+
| copy of Lesser GNU General Public License along with Snap7. |
|
|
24
|
+
| If not, see http://www.gnu.org/licenses/ |
|
|
25
|
+
|=============================================================================*/
|
|
26
|
+
|
|
27
|
+
#include "snap_tcpsrvr.h"
|
|
28
|
+
//---------------------------------------------------------------------------
|
|
29
|
+
// EVENTS QUEUE
|
|
30
|
+
//---------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
TMsgEventQueue::TMsgEventQueue(const int Capacity, const int BlockSize)
|
|
33
|
+
{
|
|
34
|
+
FCapacity = Capacity;
|
|
35
|
+
Max = FCapacity - 1;
|
|
36
|
+
FBlockSize = BlockSize;
|
|
37
|
+
Buffer = new byte[FCapacity * FBlockSize];
|
|
38
|
+
Flush();
|
|
39
|
+
}
|
|
40
|
+
//---------------------------------------------------------------------------
|
|
41
|
+
TMsgEventQueue::~TMsgEventQueue()
|
|
42
|
+
{
|
|
43
|
+
delete[] Buffer;
|
|
44
|
+
}
|
|
45
|
+
//---------------------------------------------------------------------------
|
|
46
|
+
void TMsgEventQueue::Flush()
|
|
47
|
+
{
|
|
48
|
+
IndexIn = 0;
|
|
49
|
+
IndexOut = 0;
|
|
50
|
+
}
|
|
51
|
+
//---------------------------------------------------------------------------
|
|
52
|
+
void TMsgEventQueue::Insert(void *lpdata)
|
|
53
|
+
{
|
|
54
|
+
pbyte PBlock;
|
|
55
|
+
if (!Full())
|
|
56
|
+
{
|
|
57
|
+
// Calc offset
|
|
58
|
+
if (IndexIn < Max) IndexIn++;
|
|
59
|
+
else IndexIn = 0;
|
|
60
|
+
PBlock = Buffer + uintptr_t(IndexIn * FBlockSize);
|
|
61
|
+
memcpy(PBlock, lpdata, FBlockSize);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//---------------------------------------------------------------------------
|
|
65
|
+
bool TMsgEventQueue::Extract(void *lpdata)
|
|
66
|
+
{
|
|
67
|
+
int IdxOut;
|
|
68
|
+
pbyte PBlock;
|
|
69
|
+
|
|
70
|
+
if (!Empty())
|
|
71
|
+
{
|
|
72
|
+
// stores IndexOut
|
|
73
|
+
IdxOut = IndexOut;
|
|
74
|
+
if (IdxOut < Max) IdxOut++;
|
|
75
|
+
else IdxOut = 0;
|
|
76
|
+
PBlock = Buffer + uintptr_t(IdxOut * FBlockSize);
|
|
77
|
+
// moves data
|
|
78
|
+
memcpy(lpdata, PBlock, FBlockSize);
|
|
79
|
+
// Updates IndexOut
|
|
80
|
+
IndexOut = IdxOut;
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
else
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
//---------------------------------------------------------------------------
|
|
87
|
+
bool TMsgEventQueue::Empty()
|
|
88
|
+
{
|
|
89
|
+
return (IndexIn == IndexOut);
|
|
90
|
+
}
|
|
91
|
+
//---------------------------------------------------------------------------
|
|
92
|
+
bool TMsgEventQueue::Full()
|
|
93
|
+
{
|
|
94
|
+
int IdxOut = IndexOut; // To avoid troubles if IndexOut changes during next line
|
|
95
|
+
return ( (IdxOut == IndexIn + 1) || ((IndexIn == Max) && (IdxOut == 0)));
|
|
96
|
+
}
|
|
97
|
+
//---------------------------------------------------------------------------
|
|
98
|
+
// WORKER THREAD
|
|
99
|
+
//---------------------------------------------------------------------------
|
|
100
|
+
TMsgWorkerThread::TMsgWorkerThread(TMsgSocket *Socket, TCustomMsgServer *Server)
|
|
101
|
+
{
|
|
102
|
+
FreeOnTerminate = true;
|
|
103
|
+
WorkerSocket = Socket;
|
|
104
|
+
FServer = Server;
|
|
105
|
+
}
|
|
106
|
+
//---------------------------------------------------------------------------
|
|
107
|
+
void TMsgWorkerThread::Execute()
|
|
108
|
+
{
|
|
109
|
+
bool Exception = false;
|
|
110
|
+
bool SelfClose = false;
|
|
111
|
+
// Working loop
|
|
112
|
+
while (!Terminated && !SelfClose && !Exception && !FServer->Destroying)
|
|
113
|
+
{
|
|
114
|
+
try
|
|
115
|
+
{
|
|
116
|
+
if (!WorkerSocket->Execute()) // False -> End of Activities
|
|
117
|
+
SelfClose = true;
|
|
118
|
+
} catch (...)
|
|
119
|
+
{
|
|
120
|
+
Exception = true;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
if (!FServer->Destroying)
|
|
124
|
+
{
|
|
125
|
+
// Exception detected during Worker activity
|
|
126
|
+
if (Exception)
|
|
127
|
+
{
|
|
128
|
+
WorkerSocket->ForceClose();
|
|
129
|
+
FServer->DoEvent(WorkerSocket->ClientHandle, evcClientException, 0, 0, 0, 0, 0);
|
|
130
|
+
}
|
|
131
|
+
else
|
|
132
|
+
if (SelfClose)
|
|
133
|
+
{
|
|
134
|
+
FServer->DoEvent(WorkerSocket->ClientHandle, evcClientDisconnected, 0, 0, 0, 0, 0);
|
|
135
|
+
}
|
|
136
|
+
else
|
|
137
|
+
FServer->DoEvent(WorkerSocket->ClientHandle, evcClientTerminated, 0, 0, 0, 0, 0);
|
|
138
|
+
}
|
|
139
|
+
delete WorkerSocket;
|
|
140
|
+
// Delete reference from list
|
|
141
|
+
FServer->Delete(Index);
|
|
142
|
+
}
|
|
143
|
+
//---------------------------------------------------------------------------
|
|
144
|
+
// LISTENER THREAD
|
|
145
|
+
//---------------------------------------------------------------------------
|
|
146
|
+
|
|
147
|
+
TMsgListenerThread::TMsgListenerThread(TMsgSocket *Listener, TCustomMsgServer *Server)
|
|
148
|
+
{
|
|
149
|
+
FServer = Server;
|
|
150
|
+
FListener = Listener;
|
|
151
|
+
FreeOnTerminate = false;
|
|
152
|
+
}
|
|
153
|
+
//---------------------------------------------------------------------------
|
|
154
|
+
|
|
155
|
+
void TMsgListenerThread::Execute()
|
|
156
|
+
{
|
|
157
|
+
socket_t Sock;
|
|
158
|
+
bool Valid;
|
|
159
|
+
|
|
160
|
+
while (!Terminated)
|
|
161
|
+
{
|
|
162
|
+
if (FListener->CanRead(FListener->WorkInterval))
|
|
163
|
+
{
|
|
164
|
+
Sock = FListener->SckAccept(); // in any case we must accept
|
|
165
|
+
Valid = Sock != INVALID_SOCKET;
|
|
166
|
+
// check if we are not destroying
|
|
167
|
+
if ((!Terminated) && (!FServer->Destroying))
|
|
168
|
+
{
|
|
169
|
+
if (Valid)
|
|
170
|
+
FServer->Incoming(Sock);
|
|
171
|
+
}
|
|
172
|
+
else
|
|
173
|
+
if (Valid)
|
|
174
|
+
Msg_CloseSocket(Sock);
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//---------------------------------------------------------------------------
|
|
179
|
+
// TCP SERVER
|
|
180
|
+
//---------------------------------------------------------------------------
|
|
181
|
+
TCustomMsgServer::TCustomMsgServer()
|
|
182
|
+
{
|
|
183
|
+
strcpy(FLocalAddress, "0.0.0.0");
|
|
184
|
+
CSList = new TSnapCriticalSection();
|
|
185
|
+
CSEvent = new TSnapCriticalSection();
|
|
186
|
+
FEventQueue = new TMsgEventQueue(MaxEvents, sizeof (TSrvEvent));
|
|
187
|
+
memset(Workers, 0, sizeof (Workers));
|
|
188
|
+
for (int i = 0; i < MaxWorkers; i++)
|
|
189
|
+
Workers[i] = NULL;
|
|
190
|
+
Status = SrvStopped;
|
|
191
|
+
EventMask = 0xFFFFFFFF;
|
|
192
|
+
LogMask = 0xFFFFFFFF;
|
|
193
|
+
Destroying = false;
|
|
194
|
+
FLastError = 0;
|
|
195
|
+
ClientsCount = 0;
|
|
196
|
+
LocalBind = 0;
|
|
197
|
+
MaxClients = MaxWorkers;
|
|
198
|
+
OnEvent = NULL;
|
|
199
|
+
}
|
|
200
|
+
//---------------------------------------------------------------------------
|
|
201
|
+
TCustomMsgServer::~TCustomMsgServer()
|
|
202
|
+
{
|
|
203
|
+
Destroying = true;
|
|
204
|
+
Stop();
|
|
205
|
+
OnEvent = NULL;
|
|
206
|
+
delete CSList;
|
|
207
|
+
delete CSEvent;
|
|
208
|
+
delete FEventQueue;
|
|
209
|
+
}
|
|
210
|
+
//---------------------------------------------------------------------------
|
|
211
|
+
void TCustomMsgServer::LockList()
|
|
212
|
+
{
|
|
213
|
+
CSList->Enter();
|
|
214
|
+
}
|
|
215
|
+
//---------------------------------------------------------------------------
|
|
216
|
+
void TCustomMsgServer::UnlockList()
|
|
217
|
+
{
|
|
218
|
+
CSList->Leave();
|
|
219
|
+
}
|
|
220
|
+
//---------------------------------------------------------------------------
|
|
221
|
+
int TCustomMsgServer::FirstFree()
|
|
222
|
+
{
|
|
223
|
+
int i;
|
|
224
|
+
for (i = 0; i < MaxWorkers; i++)
|
|
225
|
+
{
|
|
226
|
+
if (Workers[i] == 0)
|
|
227
|
+
return i;
|
|
228
|
+
}
|
|
229
|
+
return -1;
|
|
230
|
+
}
|
|
231
|
+
//---------------------------------------------------------------------------
|
|
232
|
+
|
|
233
|
+
int TCustomMsgServer::StartListener()
|
|
234
|
+
{
|
|
235
|
+
int Result;
|
|
236
|
+
// Creates the listener
|
|
237
|
+
SockListener = new TMsgSocket();
|
|
238
|
+
strncpy(SockListener->LocalAddress, FLocalAddress, 16);
|
|
239
|
+
SockListener->LocalPort = LocalPort;
|
|
240
|
+
// Binds
|
|
241
|
+
Result = SockListener->SckBind();
|
|
242
|
+
if (Result == 0)
|
|
243
|
+
{
|
|
244
|
+
LocalBind = SockListener->LocalBind;
|
|
245
|
+
// Listen
|
|
246
|
+
Result = SockListener->SckListen();
|
|
247
|
+
if (Result == 0)
|
|
248
|
+
{
|
|
249
|
+
// Creates the Listener thread
|
|
250
|
+
ServerThread = new TMsgListenerThread(SockListener, this);
|
|
251
|
+
ServerThread->Start();
|
|
252
|
+
}
|
|
253
|
+
else
|
|
254
|
+
delete SockListener;
|
|
255
|
+
}
|
|
256
|
+
else
|
|
257
|
+
delete SockListener;
|
|
258
|
+
|
|
259
|
+
return Result;
|
|
260
|
+
}
|
|
261
|
+
//---------------------------------------------------------------------------
|
|
262
|
+
void TCustomMsgServer::TerminateAll()
|
|
263
|
+
{
|
|
264
|
+
int c;
|
|
265
|
+
longword Elapsed;
|
|
266
|
+
bool Timeout;
|
|
267
|
+
|
|
268
|
+
if (ClientsCount > 0)
|
|
269
|
+
{
|
|
270
|
+
for (c = 0; c < MaxWorkers; c++)
|
|
271
|
+
{
|
|
272
|
+
if (Workers[c] != 0)
|
|
273
|
+
PMsgWorkerThread(Workers[c])->Terminate();
|
|
274
|
+
}
|
|
275
|
+
// Wait for closing
|
|
276
|
+
Elapsed = SysGetTick();
|
|
277
|
+
Timeout = false;
|
|
278
|
+
while (!Timeout && (ClientsCount > 0))
|
|
279
|
+
{
|
|
280
|
+
Timeout = DeltaTime(Elapsed) > WkTimeout;
|
|
281
|
+
if (!Timeout)
|
|
282
|
+
SysSleep(100);
|
|
283
|
+
};
|
|
284
|
+
if (ClientsCount > 0)
|
|
285
|
+
KillAll(); // one o more threads are hanged
|
|
286
|
+
ClientsCount = 0;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
//---------------------------------------------------------------------------
|
|
290
|
+
void TCustomMsgServer::KillAll()
|
|
291
|
+
{
|
|
292
|
+
int c, cnt = 0;
|
|
293
|
+
LockList();
|
|
294
|
+
for (c = 0; c < MaxWorkers; c++)
|
|
295
|
+
{
|
|
296
|
+
if (Workers[c] != 0)
|
|
297
|
+
try
|
|
298
|
+
{
|
|
299
|
+
PMsgWorkerThread(Workers[c])->Kill();
|
|
300
|
+
PMsgWorkerThread(Workers[c])->WorkerSocket->ForceClose();
|
|
301
|
+
delete PMsgWorkerThread(Workers[c]);
|
|
302
|
+
Workers[c] = 0;
|
|
303
|
+
cnt++;
|
|
304
|
+
} catch (...)
|
|
305
|
+
{
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
UnlockList();
|
|
309
|
+
DoEvent(0, evcClientsDropped, 0, cnt, 0, 0, 0);
|
|
310
|
+
}
|
|
311
|
+
//---------------------------------------------------------------------------
|
|
312
|
+
bool TCustomMsgServer::CanAccept(socket_t Socket)
|
|
313
|
+
{
|
|
314
|
+
return ((MaxClients == 0) || (ClientsCount < MaxClients));
|
|
315
|
+
}
|
|
316
|
+
//---------------------------------------------------------------------------
|
|
317
|
+
PWorkerSocket TCustomMsgServer::CreateWorkerSocket(socket_t Sock)
|
|
318
|
+
{
|
|
319
|
+
PWorkerSocket Result;
|
|
320
|
+
// Creates a funny default class : a tcp echo worker
|
|
321
|
+
Result = new TEcoTcpWorker();
|
|
322
|
+
Result->SetSocket(Sock);
|
|
323
|
+
return Result;
|
|
324
|
+
}
|
|
325
|
+
//---------------------------------------------------------------------------
|
|
326
|
+
void TCustomMsgServer::DoEvent(int Sender, longword Code, word RetCode, word Param1, word Param2, word Param3, word Param4)
|
|
327
|
+
{
|
|
328
|
+
TSrvEvent SrvEvent;
|
|
329
|
+
bool GoLog = (Code & LogMask) != 0;
|
|
330
|
+
bool GoEvent = (Code & EventMask) != 0;
|
|
331
|
+
|
|
332
|
+
if (!Destroying && (GoLog || GoEvent))
|
|
333
|
+
{
|
|
334
|
+
CSEvent->Enter();
|
|
335
|
+
|
|
336
|
+
time(&SrvEvent.EvtTime);
|
|
337
|
+
SrvEvent.EvtSender = Sender;
|
|
338
|
+
SrvEvent.EvtCode = Code;
|
|
339
|
+
SrvEvent.EvtRetCode = RetCode;
|
|
340
|
+
SrvEvent.EvtParam1 = Param1;
|
|
341
|
+
SrvEvent.EvtParam2 = Param2;
|
|
342
|
+
SrvEvent.EvtParam3 = Param3;
|
|
343
|
+
SrvEvent.EvtParam4 = Param4;
|
|
344
|
+
|
|
345
|
+
if (GoEvent && (OnEvent != NULL))
|
|
346
|
+
try
|
|
347
|
+
{ // callback is outside here, we have to shield it
|
|
348
|
+
OnEvent(FUsrPtr, &SrvEvent, sizeof (TSrvEvent));
|
|
349
|
+
} catch (...)
|
|
350
|
+
{
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
if (GoLog)
|
|
354
|
+
FEventQueue->Insert(&SrvEvent);
|
|
355
|
+
|
|
356
|
+
CSEvent->Leave();
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
//---------------------------------------------------------------------------
|
|
360
|
+
void TCustomMsgServer::Delete(int Index)
|
|
361
|
+
{
|
|
362
|
+
LockList();
|
|
363
|
+
Workers[Index] = 0;
|
|
364
|
+
ClientsCount--;
|
|
365
|
+
UnlockList();
|
|
366
|
+
}
|
|
367
|
+
//---------------------------------------------------------------------------
|
|
368
|
+
void TCustomMsgServer::Incoming(socket_t Sock)
|
|
369
|
+
{
|
|
370
|
+
int idx;
|
|
371
|
+
PWorkerSocket WorkerSocket;
|
|
372
|
+
longword ClientHandle = Msg_GetSockAddr(Sock);
|
|
373
|
+
|
|
374
|
+
if (CanAccept(Sock))
|
|
375
|
+
{
|
|
376
|
+
LockList();
|
|
377
|
+
// First position available in the thread buffer
|
|
378
|
+
idx = FirstFree();
|
|
379
|
+
if (idx >= 0)
|
|
380
|
+
{
|
|
381
|
+
// Creates the Worker and assigns it the connected socket
|
|
382
|
+
WorkerSocket = CreateWorkerSocket(Sock);
|
|
383
|
+
// Creates the Worker thread
|
|
384
|
+
Workers[idx] = new TMsgWorkerThread(WorkerSocket, this);
|
|
385
|
+
PMsgWorkerThread(Workers[idx])->Index = idx;
|
|
386
|
+
// Update the number
|
|
387
|
+
ClientsCount++;
|
|
388
|
+
// And Starts the worker
|
|
389
|
+
PMsgWorkerThread(Workers[idx])->Start();
|
|
390
|
+
DoEvent(WorkerSocket->ClientHandle, evcClientAdded, 0, 0, 0, 0, 0);
|
|
391
|
+
}
|
|
392
|
+
else
|
|
393
|
+
{
|
|
394
|
+
DoEvent(ClientHandle, evcClientNoRoom, 0, 0, 0, 0, 0);
|
|
395
|
+
Msg_CloseSocket(Sock);
|
|
396
|
+
}
|
|
397
|
+
UnlockList();
|
|
398
|
+
}
|
|
399
|
+
else
|
|
400
|
+
{
|
|
401
|
+
Msg_CloseSocket(Sock);
|
|
402
|
+
DoEvent(ClientHandle, evcClientRejected, 0, 0, 0, 0, 0);
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
//---------------------------------------------------------------------------
|
|
406
|
+
int TCustomMsgServer::Start()
|
|
407
|
+
{
|
|
408
|
+
int Result = 0;
|
|
409
|
+
if (Status != SrvRunning)
|
|
410
|
+
{
|
|
411
|
+
Result = StartListener();
|
|
412
|
+
if (Result != 0)
|
|
413
|
+
{
|
|
414
|
+
DoEvent(0, evcListenerCannotStart, Result, 0, 0, 0, 0);
|
|
415
|
+
Status = SrvError;
|
|
416
|
+
}
|
|
417
|
+
else
|
|
418
|
+
{
|
|
419
|
+
DoEvent(0, evcServerStarted, SockListener->ClientHandle, LocalPort, 0, 0, 0);
|
|
420
|
+
Status = SrvRunning;
|
|
421
|
+
};
|
|
422
|
+
};
|
|
423
|
+
FLastError = Result;
|
|
424
|
+
return Result;
|
|
425
|
+
}
|
|
426
|
+
//---------------------------------------------------------------------------
|
|
427
|
+
int TCustomMsgServer::StartTo(const char *Address, word Port)
|
|
428
|
+
{
|
|
429
|
+
strncpy(FLocalAddress, Address, 16);
|
|
430
|
+
LocalPort = Port;
|
|
431
|
+
return Start();
|
|
432
|
+
}
|
|
433
|
+
//---------------------------------------------------------------------------
|
|
434
|
+
void TCustomMsgServer::Stop()
|
|
435
|
+
{
|
|
436
|
+
if (Status == SrvRunning)
|
|
437
|
+
{
|
|
438
|
+
// Kills the listener thread
|
|
439
|
+
ServerThread->Terminate();
|
|
440
|
+
if (ServerThread->WaitFor(ThTimeout) != WAIT_OBJECT_0)
|
|
441
|
+
ServerThread->Kill();
|
|
442
|
+
delete ServerThread;
|
|
443
|
+
// Kills the listener
|
|
444
|
+
delete SockListener;
|
|
445
|
+
|
|
446
|
+
// Terminate all client threads
|
|
447
|
+
TerminateAll();
|
|
448
|
+
|
|
449
|
+
Status = SrvStopped;
|
|
450
|
+
LocalBind = 0;
|
|
451
|
+
DoEvent(0, evcServerStopped, 0, 0, 0, 0, 0);
|
|
452
|
+
};
|
|
453
|
+
FLastError = 0;
|
|
454
|
+
}
|
|
455
|
+
//---------------------------------------------------------------------------
|
|
456
|
+
int TCustomMsgServer::SetEventsCallBack(pfn_SrvCallBack PCallBack, void *UsrPtr)
|
|
457
|
+
{
|
|
458
|
+
OnEvent = PCallBack;
|
|
459
|
+
FUsrPtr = UsrPtr;
|
|
460
|
+
return 0;
|
|
461
|
+
}
|
|
462
|
+
//---------------------------------------------------------------------------
|
|
463
|
+
bool TCustomMsgServer::PickEvent(void *pEvent)
|
|
464
|
+
{
|
|
465
|
+
try
|
|
466
|
+
{
|
|
467
|
+
return FEventQueue->Extract(pEvent);
|
|
468
|
+
} catch (...)
|
|
469
|
+
{
|
|
470
|
+
return false;
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
//---------------------------------------------------------------------------
|
|
474
|
+
bool TCustomMsgServer::EventEmpty()
|
|
475
|
+
{
|
|
476
|
+
return FEventQueue->Empty();
|
|
477
|
+
}
|
|
478
|
+
//---------------------------------------------------------------------------
|
|
479
|
+
void TCustomMsgServer::EventsFlush()
|
|
480
|
+
{
|
|
481
|
+
CSEvent->Enter();
|
|
482
|
+
FEventQueue->Flush();
|
|
483
|
+
CSEvent->Leave();
|
|
484
|
+
}
|
|
485
|
+
//---------------------------------------------------------------------------
|
|
486
|
+
|
|
487
|
+
|