Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
cheatfate committed Aug 9, 2023
1 parent d0dca33 commit 5f83265
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 42 deletions.
36 changes: 4 additions & 32 deletions chronos/apps/http/httpserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -802,15 +802,6 @@ proc init*(value: var HttpConnection, server: HttpServerRef,
mainWriter: newAsyncStreamWriter(transp)
)

proc clean(connection: var HttpConnection) =
connection.transp = nil
connection.server = nil
connection.buffer = default(seq[byte])
connection.mainReader = nil
connection.mainWriter = nil
connection.reader = nil
connection.writer = nil

proc closeUnsecureConnection(conn: HttpConnectionRef) {.async.} =
if conn.state == HttpState.Alive:
conn.state = HttpState.Closing
Expand All @@ -823,7 +814,7 @@ proc closeUnsecureConnection(conn: HttpConnectionRef) {.async.} =
except CancelledError:
await allFutures(pending)
untrackCounter(HttpServerUnsecureConnectionTrackerName)
conn[].clean()
reset(conn[])
conn.state = HttpState.Closed

proc new(ht: typedesc[HttpConnectionRef], server: HttpServerRef,
Expand All @@ -844,25 +835,6 @@ proc gracefulCloseWait*(conn: HttpConnectionRef) {.async.} =
proc closeWait*(conn: HttpConnectionRef): Future[void] =
conn.closeCb(conn)

proc clean(response: HttpResponseRef) =
response.writer = nil
response.connection = nil
response.body = default(seq[byte])
response.headersTable.clear()

proc clean(request: HttpRequestRef) =
request.connection = nil
request.headers.clear()
request.query.clear()
if request.postTable.isSome():
request.postTable = Opt.none(HttpTable)
request.rawPath = default(string)
request.uri = default(Uri)
if request.contentTypeData.isSome():
request.contentTypeData = Opt.none(ContentTypeData)
if request.response.isSome():
request.response = Opt.none(HttpResponseRef)

proc closeWait*(req: HttpRequestRef) {.async.} =
if req.state == HttpState.Alive:
if req.response.isSome():
Expand All @@ -874,9 +846,9 @@ proc closeWait*(req: HttpRequestRef) {.async.} =
await writer
except CancelledError:
await writer
resp.clean()
reset(resp[])
untrackCounter(HttpServerRequestTrackerName)
req.clean()
reset(req[])
req.state = HttpState.Closed

proc createConnection(server: HttpServerRef,
Expand Down Expand Up @@ -1064,7 +1036,7 @@ proc processLoop(holder: HttpConnectionHolderRef) {.async.} =
except CancelledError:
HttpProcessExitType.Immediate
except CatchableError as exc:
raiseAssert "Unexpected error [" & exc.name & "] happens: " & exc.msg
raiseAssert "Unexpected error [" & $exc.name & "] happens: " & $exc.msg

server.connections.del(connectionId)
case runLoop
Expand Down
11 changes: 1 addition & 10 deletions chronos/apps/http/shttpserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ type

SecureHttpConnectionRef* = ref SecureHttpConnection

proc clean(connection: var SecureHttpConnection) =
connection.transp = nil
connection.server = nil
connection.mainReader = nil
connection.mainWriter = nil
connection.tlsStream.sbuffer = default(seq[byte])
connection.tlsStream.reader = nil
connection.tlsStream.writer = nil

proc closeSecConnection(conn: HttpConnectionRef) {.async.} =
if conn.state == HttpState.Alive:
conn.state = HttpState.Closing
Expand All @@ -52,7 +43,7 @@ proc closeSecConnection(conn: HttpConnectionRef) {.async.} =
await allFutures(pending)
except CancelledError:
await allFutures(pending)
cast[SecureHttpConnectionRef](conn)[].clean()
reset(cast[SecureHttpConnectionRef](conn)[])
untrackCounter(HttpServerSecureConnectionTrackerName)
conn.state = HttpState.Closed

Expand Down

0 comments on commit 5f83265

Please sign in to comment.