@scrypted/server 0.7.97 → 0.7.99
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 @scrypted/server might be problematic. Click here for more details.
- package/package.json +1 -1
- package/python/rpc_reader.py +22 -12
package/package.json
CHANGED
package/python/rpc_reader.py
CHANGED
@@ -5,10 +5,10 @@ import base64
|
|
5
5
|
import json
|
6
6
|
import os
|
7
7
|
import threading
|
8
|
+
from concurrent.futures import ThreadPoolExecutor
|
8
9
|
from asyncio.events import AbstractEventLoop
|
9
10
|
from typing import List, Any
|
10
11
|
import multiprocessing.connection
|
11
|
-
import aiofiles
|
12
12
|
import rpc
|
13
13
|
import concurrent.futures
|
14
14
|
import json
|
@@ -52,29 +52,39 @@ class RpcTransport:
|
|
52
52
|
|
53
53
|
|
54
54
|
class RpcFileTransport(RpcTransport):
|
55
|
-
|
55
|
+
executor: ThreadPoolExecutor
|
56
56
|
|
57
57
|
def __init__(self, readFd: int, writeFd: int) -> None:
|
58
58
|
super().__init__()
|
59
59
|
self.readFd = readFd
|
60
60
|
self.writeFd = writeFd
|
61
|
-
self.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
61
|
+
self.executor = ThreadPoolExecutor(1, 'rpc-read')
|
62
|
+
|
63
|
+
def osReadExact(self, size: int):
|
64
|
+
b = bytes(0)
|
65
|
+
while size:
|
66
|
+
got = os.read(self.readFd, size)
|
67
|
+
if not len(got):
|
68
|
+
self.executor.shutdown(False)
|
69
|
+
raise Exception('rpc end of stream reached')
|
70
|
+
size -= len(got)
|
71
|
+
b += got
|
72
|
+
return b
|
73
|
+
|
74
|
+
def readMessageInternal(self):
|
75
|
+
lengthBytes = self.osReadExact(4)
|
76
|
+
typeBytes = self.osReadExact(1)
|
70
77
|
type = typeBytes[0]
|
71
78
|
length = int.from_bytes(lengthBytes, 'big')
|
72
|
-
data =
|
79
|
+
data = self.osReadExact(length - 1)
|
73
80
|
if type == 1:
|
74
81
|
return data
|
75
82
|
message = json.loads(data)
|
76
83
|
return message
|
77
84
|
|
85
|
+
async def read(self):
|
86
|
+
return await asyncio.get_event_loop().run_in_executor(self.executor, lambda: self.readMessageInternal())
|
87
|
+
|
78
88
|
def writeMessage(self, type: int, buffer, reject):
|
79
89
|
length = len(buffer) + 1
|
80
90
|
lb = length.to_bytes(4, 'big')
|