Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
RadKesvat committed Dec 17, 2023
1 parent 733b652 commit 1083681
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/foreign_server.nim
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ proc processConnection(client: Connection) {.async.} =
data.setLen(data.len() + width)
await remote.reader.readExactly(addr data[0 + width], data.len - width)

if not client.closed and client.isClosing: await client.twriter.finish()
if client.closed or client.isClosing:
if client.closed :
client = await acquireClientConnection(true)
if client == nil:
if globals.log_conn_error: echo "[Error] [processRemote] [loop]: ", "no client for tcp !"
Expand All @@ -144,7 +143,13 @@ proc processConnection(client: Connection) {.async.} =

await client.twriter.write(data)
if globals.log_data_len: echo &"[processRemote] Sent {data.len()} bytes -> client"


if client.isClosing:
await client.twriter.finish()
client = await acquireClientConnection(true)
if client == nil:
if globals.log_conn_error: echo "[Error] [processRemote] [loop]: ", "no client for tcp !"
break
except:
if globals.log_conn_error: echo "[Error] [processRemote] [loopEx]: ", getCurrentExceptionMsg()

Expand Down
10 changes: 7 additions & 3 deletions src/iran_server.nim
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,8 @@ proc processTcpConnection(client: Connection) {.async.} =
first_packet = false

#write
if not up_bound.closed and up_bound.isClosing: await up_bound.writer.finish()

if up_bound.closed or up_bound.isClosing:

if up_bound.closed:
up_bound = await acquireRemoteConnection(upload = true, ip = up_bound.transp.remoteAddress())
if up_bound == nil:
if globals.log_conn_error: echo "[Error] [processClient] [loop]: ", "left without connection, closes forcefully."
Expand All @@ -332,6 +330,12 @@ proc processTcpConnection(client: Connection) {.async.} =
except:
echo "[Error] [processClient] [writeUp]: ", getCurrentExceptionMsg()

if up_bound.isClosing:
await up_bound.writer.finish()
up_bound = await acquireRemoteConnection(upload = true, ip = up_bound.transp.remoteAddress())
if up_bound == nil:
if globals.log_conn_error: echo "[Error] [processClient] [loop]: ", "left without connection, closes forcefully."
await closeLine(client, up_bound); return

except:
if globals.log_conn_error: echo "[Error] [processClient] [loopEx]: ", getCurrentExceptionMsg()
Expand Down

0 comments on commit 1083681

Please sign in to comment.