Compare commits

...

2 Commits

Author SHA1 Message Date
Carlos Sanchez df7fcd2967 Attempt at process pipe full close 2024-02-10 03:26:38 +01:00
Carlos Sanchez f291f341fa Trying to commit the funnee bool
yeah
2024-02-10 03:25:22 +01:00
5 changed files with 56 additions and 17 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/users/
/client/config/
*.swp

View File

@ -14,6 +14,8 @@ sp = pUp(s)
import toml
import subprocess
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)
def addressStr(addr):
return addr[0] + ":" + str(addr[1])
@ -100,7 +102,25 @@ def main():
procs.append(subprocess.Popen(cmds[i],stdin=procs[i - 1].stdout,stdout=subprocess.PIPE))
procs.append(subprocess.Popen(cmds[-1],stdin=procs[-1].stdout))
for proc in reversed(procs):
proc.wait()
# Pwetty pwease add thew funcshun owo uwu xoxoxox
import time
running = True
while running:
for proc in procs:
if proc.poll() is not None:
eprint("Process died: " + str(proc.args))
running = False
break
time.sleep(1)
eprint("Terminating process chain (" + str(len(procs)) + ")...")
for proc in procs:
eprint("Closing: " + str(proc.args))
try:
proc.terminate()
proc.wait()
except Exception as ex:
eprint("Error waiting for process!!! " + str(ex))
main()

View File

@ -23,10 +23,8 @@ def defGet(tbl,key,defv):
bufferSize = int(defGet(os.environ,"fstream_net_buffer","4096")) # max buffer size in bytes for receiving data, lower values shouldn't reduce the delay
bufferSizeStdin = int(defGet(os.environ,"fstream_stdin_buffer","128")) # min buffer size for buffer, lower values DO reduce delay but raise CPU usage
timeout = float(defGet(os.environ,"fstream_net_timeout","15")) # timeout in seconds
useSSL = False
sslIgnoreCert = False
if defGet(os.environ,"fstream_ssl","0") == "1": useSSL = True
if defGet(os.environ,"fstream_ssl_ignoreCert","0") == "1": sslIgnoreCert = True
useSSL = defGet(os.environ,"fstream_ssl","0") == "1"
sslIgnoreCert = defGet(os.environ,"fstream_ssl_ignoreCert","0") == "1"
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
@ -46,10 +44,10 @@ def listToCommand(lst):
def recv(conn,l):
start = time.process_time()
timeo = conn.gettimeout()
bytes = b""
bytes = bytearray()
while l > 0:
b = conn.recv(l)
if b == b"": raise ConnectionResetError
if not b: raise ConnectionResetError
if time.process_time() - start > timeo: raise TimeoutError
bytes += b
l -= len(b)
@ -116,11 +114,11 @@ def main():
eprint("Receiving token...")
while True:
data = connection.recv(bufferSize)
if data != b"":
if data:
token += data
continue
if token == b"":
if not token:
eprint("Connection closed: failure")
os.exit(1)
else:
@ -136,7 +134,7 @@ def main():
eprint("Receiving data...")
while True:
data = connection.recv(bufferSize)
if data == b"":
if not data:
eprint("Connection closed.")
return
unbufferedStdout.write(data)
@ -149,7 +147,7 @@ def main():
eprint("Sending data...")
while True:
data = sys.stdin.buffer.read(bufferSizeStdin)
if data == b"":
if not data:
return
connection.sendall(data)
except:

BIN
client/requirements.txt Normal file

Binary file not shown.

View File

@ -14,6 +14,8 @@ sp = pUp(s)
import toml
import subprocess
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)
def addressStr(addr):
return addr[0] + ":" + str(addr[1])
@ -81,8 +83,26 @@ def main():
for i in range(1,len(cmds) - 1):
procs.append(subprocess.Popen(cmds[i],stdin=procs[i - 1].stdout,stdout=subprocess.PIPE))
procs.append(subprocess.Popen(cmds[-1],stdin=procs[-1].stdout))
for proc in reversed(procs):
proc.wait()
# Pwetty pwease add thew funcshun owo uwu xoxoxox (<S-F10>)
import time
running = True
while running:
for proc in procs:
if proc.poll() is not None:
eprint("Process died: " + str(proc.args))
running = False
break
time.sleep(1)
eprint("Terminating process chain (" + str(len(procs)) + ")...")
for proc in procs:
eprint("Closing: " + str(proc.args))
try:
proc.terminate()
proc.wait()
except Exception as ex:
eprint("Error waiting for process!!! " + str(ex))
main()