mirror of
https://github.com/status-im/nim-chronos.git
synced 2025-01-20 16:29:12 +00:00
clean up Defect
(#404)
This commit is contained in:
parent
2ef34c7339
commit
1d6c309d77
@ -29,8 +29,8 @@ type
|
||||
opened*: int64
|
||||
closed*: int64
|
||||
|
||||
proc setupHttpBodyWriterTracker(): HttpBodyTracker {.gcsafe, raises: [Defect].}
|
||||
proc setupHttpBodyReaderTracker(): HttpBodyTracker {.gcsafe, raises: [Defect].}
|
||||
proc setupHttpBodyWriterTracker(): HttpBodyTracker {.gcsafe, raises: [].}
|
||||
proc setupHttpBodyReaderTracker(): HttpBodyTracker {.gcsafe, raises: [].}
|
||||
|
||||
proc getHttpBodyWriterTracker(): HttpBodyTracker {.inline.} =
|
||||
var res = cast[HttpBodyTracker](getTracker(HttpBodyWriterTrackerName))
|
||||
@ -138,7 +138,7 @@ proc closeWait*(bstream: HttpBodyWriter) {.async.} =
|
||||
bstream.bstate = HttpState.Closed
|
||||
untrackHttpBodyWriter(bstream)
|
||||
|
||||
proc hasOverflow*(bstream: HttpBodyReader): bool {.raises: [Defect].} =
|
||||
proc hasOverflow*(bstream: HttpBodyReader): bool {.raises: [].} =
|
||||
if len(bstream.streams) == 1:
|
||||
# If HttpBodyReader has only one stream it has ``BoundedStreamReader``, in
|
||||
# such case its impossible to get more bytes then expected amount.
|
||||
@ -155,5 +155,5 @@ proc hasOverflow*(bstream: HttpBodyReader): bool {.raises: [Defect].} =
|
||||
false
|
||||
|
||||
proc closed*(bstream: HttpBodyReader | HttpBodyWriter): bool {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
bstream.bstate != HttpState.Alive
|
||||
|
@ -205,11 +205,11 @@ type
|
||||
# Open -> (Finished, Error) -> (Closing, Closed)
|
||||
|
||||
proc setupHttpClientConnectionTracker(): HttpClientTracker {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
proc setupHttpClientRequestTracker(): HttpClientTracker {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
proc setupHttpClientResponseTracker(): HttpClientTracker {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
|
||||
proc getHttpClientConnectionTracker(): HttpClientTracker {.inline.} =
|
||||
var res = cast[HttpClientTracker](getTracker(HttpClientConnectionTrackerName))
|
||||
@ -353,7 +353,7 @@ proc new*(t: typedesc[HttpSessionRef],
|
||||
idleTimeout = HttpConnectionIdleTimeout,
|
||||
idlePeriod = HttpConnectionCheckPeriod,
|
||||
socketFlags: set[SocketFlags] = {}): HttpSessionRef {.
|
||||
raises: [Defect] .} =
|
||||
raises: [] .} =
|
||||
## Create new HTTP session object.
|
||||
##
|
||||
## ``maxRedirections`` - maximum number of HTTP 3xx redirections
|
||||
@ -381,7 +381,7 @@ proc new*(t: typedesc[HttpSessionRef],
|
||||
newFuture[void]("session.watcher.placeholder")
|
||||
res
|
||||
|
||||
proc getTLSFlags(flags: HttpClientFlags): set[TLSFlags] {.raises: [Defect] .} =
|
||||
proc getTLSFlags(flags: HttpClientFlags): set[TLSFlags] {.raises: [] .} =
|
||||
var res: set[TLSFlags]
|
||||
if HttpClientFlag.NoVerifyHost in flags:
|
||||
res.incl(TLSFlags.NoVerifyHost)
|
||||
@ -390,7 +390,7 @@ proc getTLSFlags(flags: HttpClientFlags): set[TLSFlags] {.raises: [Defect] .} =
|
||||
res
|
||||
|
||||
proc getAddress*(session: HttpSessionRef, url: Uri): HttpResult[HttpAddress] {.
|
||||
raises: [Defect] .} =
|
||||
raises: [] .} =
|
||||
let scheme =
|
||||
if len(url.scheme) == 0:
|
||||
HttpClientScheme.NonSecure
|
||||
@ -454,13 +454,13 @@ proc getAddress*(session: HttpSessionRef, url: Uri): HttpResult[HttpAddress] {.
|
||||
addresses: addresses))
|
||||
|
||||
proc getAddress*(session: HttpSessionRef,
|
||||
url: string): HttpResult[HttpAddress] {.raises: [Defect].} =
|
||||
url: string): HttpResult[HttpAddress] {.raises: [].} =
|
||||
## Create new HTTP address using URL string ``url`` and .
|
||||
session.getAddress(parseUri(url))
|
||||
|
||||
proc getAddress*(address: TransportAddress,
|
||||
ctype: HttpClientScheme = HttpClientScheme.NonSecure,
|
||||
queryString: string = "/"): HttpAddress {.raises: [Defect].} =
|
||||
queryString: string = "/"): HttpAddress {.raises: [].} =
|
||||
## Create new HTTP address using Transport address ``address``, connection
|
||||
## type ``ctype`` and query string ``queryString``.
|
||||
let uri = parseUri(queryString)
|
||||
@ -579,7 +579,7 @@ proc new(t: typedesc[HttpClientConnectionRef], session: HttpSessionRef,
|
||||
res
|
||||
|
||||
proc setError(request: HttpClientRequestRef, error: ref HttpError) {.
|
||||
raises: [Defect] .} =
|
||||
raises: [] .} =
|
||||
request.error = error
|
||||
request.state = HttpReqRespState.Error
|
||||
if not(isNil(request.connection)):
|
||||
@ -587,7 +587,7 @@ proc setError(request: HttpClientRequestRef, error: ref HttpError) {.
|
||||
request.connection.error = error
|
||||
|
||||
proc setError(response: HttpClientResponseRef, error: ref HttpError) {.
|
||||
raises: [Defect] .} =
|
||||
raises: [] .} =
|
||||
response.error = error
|
||||
response.state = HttpReqRespState.Error
|
||||
if not(isNil(response.connection)):
|
||||
@ -851,7 +851,7 @@ proc closeWait*(response: HttpClientResponseRef) {.async.} =
|
||||
untrackHttpClientResponse(response)
|
||||
|
||||
proc prepareResponse(request: HttpClientRequestRef, data: openArray[byte]
|
||||
): HttpResult[HttpClientResponseRef] {.raises: [Defect] .} =
|
||||
): HttpResult[HttpClientResponseRef] {.raises: [] .} =
|
||||
## Process response headers.
|
||||
let resp = parseResponse(data, false)
|
||||
if resp.failed():
|
||||
@ -990,7 +990,7 @@ proc new*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openArray[HttpHeaderTuple] = [],
|
||||
body: openArray[byte] = []): HttpClientRequestRef {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
let res = HttpClientRequestRef(
|
||||
state: HttpReqRespState.Ready, session: session, meth: meth,
|
||||
version: version, flags: flags, headers: HttpTable.init(headers),
|
||||
@ -1005,7 +1005,7 @@ proc new*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openArray[HttpHeaderTuple] = [],
|
||||
body: openArray[byte] = []): HttpResult[HttpClientRequestRef] {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
let address = ? session.getAddress(parseUri(url))
|
||||
let res = HttpClientRequestRef(
|
||||
state: HttpReqRespState.Ready, session: session, meth: meth,
|
||||
@ -1019,14 +1019,14 @@ proc get*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
url: string, version: HttpVersion = HttpVersion11,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openArray[HttpHeaderTuple] = []
|
||||
): HttpResult[HttpClientRequestRef] {.raises: [Defect].} =
|
||||
): HttpResult[HttpClientRequestRef] {.raises: [].} =
|
||||
HttpClientRequestRef.new(session, url, MethodGet, version, flags, headers)
|
||||
|
||||
proc get*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
ha: HttpAddress, version: HttpVersion = HttpVersion11,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openArray[HttpHeaderTuple] = []
|
||||
): HttpClientRequestRef {.raises: [Defect].} =
|
||||
): HttpClientRequestRef {.raises: [].} =
|
||||
HttpClientRequestRef.new(session, ha, MethodGet, version, flags, headers)
|
||||
|
||||
proc post*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
@ -1034,7 +1034,7 @@ proc post*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openArray[HttpHeaderTuple] = [],
|
||||
body: openArray[byte] = []
|
||||
): HttpResult[HttpClientRequestRef] {.raises: [Defect].} =
|
||||
): HttpResult[HttpClientRequestRef] {.raises: [].} =
|
||||
HttpClientRequestRef.new(session, url, MethodPost, version, flags, headers,
|
||||
body)
|
||||
|
||||
@ -1043,7 +1043,7 @@ proc post*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openArray[HttpHeaderTuple] = [],
|
||||
body: openArray[char] = []): HttpResult[HttpClientRequestRef] {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
HttpClientRequestRef.new(session, url, MethodPost, version, flags, headers,
|
||||
body.toOpenArrayByte(0, len(body) - 1))
|
||||
|
||||
@ -1052,7 +1052,7 @@ proc post*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openArray[HttpHeaderTuple] = [],
|
||||
body: openArray[byte] = []): HttpClientRequestRef {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
HttpClientRequestRef.new(session, ha, MethodPost, version, flags, headers,
|
||||
body)
|
||||
|
||||
@ -1061,12 +1061,12 @@ proc post*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openArray[HttpHeaderTuple] = [],
|
||||
body: openArray[char] = []): HttpClientRequestRef {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
HttpClientRequestRef.new(session, ha, MethodPost, version, flags, headers,
|
||||
body.toOpenArrayByte(0, len(body) - 1))
|
||||
|
||||
proc prepareRequest(request: HttpClientRequestRef): string {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
template hasChunkedEncoding(request: HttpClientRequestRef): bool =
|
||||
toLowerAscii(request.headers.getString(TransferEncodingHeader)) == "chunked"
|
||||
|
||||
|
@ -118,7 +118,7 @@ template newHttpUseClosedError*(): ref HttpUseClosedError =
|
||||
|
||||
iterator queryParams*(query: string,
|
||||
flags: set[QueryParamsFlag] = {}): KeyValueTuple {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Iterate over url-encoded query string.
|
||||
for pair in query.split('&'):
|
||||
let items = pair.split('=', maxsplit = 1)
|
||||
@ -133,7 +133,7 @@ iterator queryParams*(query: string,
|
||||
|
||||
func getTransferEncoding*(ch: openArray[string]): HttpResult[
|
||||
set[TransferEncodingFlags]] {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Parse value of multiple HTTP headers ``Transfer-Encoding`` and return
|
||||
## it as set of ``TransferEncodingFlags``.
|
||||
var res: set[TransferEncodingFlags] = {}
|
||||
@ -164,7 +164,7 @@ func getTransferEncoding*(ch: openArray[string]): HttpResult[
|
||||
|
||||
func getContentEncoding*(ch: openArray[string]): HttpResult[
|
||||
set[ContentEncodingFlags]] {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Parse value of multiple HTTP headers ``Content-Encoding`` and return
|
||||
## it as set of ``ContentEncodingFlags``.
|
||||
var res: set[ContentEncodingFlags] = {}
|
||||
@ -194,7 +194,7 @@ func getContentEncoding*(ch: openArray[string]): HttpResult[
|
||||
ok(res)
|
||||
|
||||
func getContentType*(ch: openArray[string]): HttpResult[ContentTypeData] {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Check and prepare value of ``Content-Type`` header.
|
||||
if len(ch) == 0:
|
||||
err("No Content-Type values found")
|
||||
|
@ -55,12 +55,12 @@ type
|
||||
|
||||
HttpProcessCallback* =
|
||||
proc(req: RequestFence): Future[HttpResponseRef] {.
|
||||
gcsafe, raises: [Defect, CatchableError].}
|
||||
gcsafe, raises: [].}
|
||||
|
||||
HttpConnectionCallback* =
|
||||
proc(server: HttpServerRef,
|
||||
transp: StreamTransport): Future[HttpConnectionRef] {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
|
||||
HttpServer* = object of RootObj
|
||||
instance*: StreamServer
|
||||
@ -133,7 +133,7 @@ type
|
||||
|
||||
proc init(htype: typedesc[HttpProcessError], error: HttpServerError,
|
||||
exc: ref CatchableError, remote: TransportAddress,
|
||||
code: HttpCode): HttpProcessError {.raises: [Defect].} =
|
||||
code: HttpCode): HttpProcessError {.raises: [].} =
|
||||
HttpProcessError(error: error, exc: exc, remote: remote, code: code)
|
||||
|
||||
proc createConnection(server: HttpServerRef,
|
||||
@ -153,7 +153,7 @@ proc new*(htype: typedesc[HttpServerRef],
|
||||
httpHeadersTimeout = 10.seconds,
|
||||
maxHeadersSize: int = 8192,
|
||||
maxRequestBodySize: int = 1_048_576): HttpResult[HttpServerRef] {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
|
||||
let serverUri =
|
||||
if len(serverUri.hostname) > 0:
|
||||
@ -198,7 +198,7 @@ proc new*(htype: typedesc[HttpServerRef],
|
||||
)
|
||||
ok(res)
|
||||
|
||||
proc getResponse*(req: HttpRequestRef): HttpResponseRef {.raises: [Defect].} =
|
||||
proc getResponse*(req: HttpRequestRef): HttpResponseRef {.raises: [].} =
|
||||
if req.response.isNone():
|
||||
var resp = HttpResponseRef(
|
||||
status: Http200,
|
||||
@ -222,7 +222,7 @@ proc getHostname*(server: HttpServerRef): string =
|
||||
else:
|
||||
server.baseUri.hostname
|
||||
|
||||
proc dumbResponse*(): HttpResponseRef {.raises: [Defect].} =
|
||||
proc dumbResponse*(): HttpResponseRef {.raises: [].} =
|
||||
## Create an empty response to return when request processor got no request.
|
||||
HttpResponseRef(state: HttpResponseState.Dumb, version: HttpVersion11)
|
||||
|
||||
@ -233,14 +233,14 @@ proc getId(transp: StreamTransport): Result[string, string] {.inline.} =
|
||||
except TransportOsError as exc:
|
||||
err($exc.msg)
|
||||
|
||||
proc hasBody*(request: HttpRequestRef): bool {.raises: [Defect].} =
|
||||
proc hasBody*(request: HttpRequestRef): bool {.raises: [].} =
|
||||
## Returns ``true`` if request has body.
|
||||
request.requestFlags * {HttpRequestFlags.BoundBody,
|
||||
HttpRequestFlags.UnboundBody} != {}
|
||||
|
||||
proc prepareRequest(conn: HttpConnectionRef,
|
||||
req: HttpRequestHeader): HttpResultCode[HttpRequestRef] {.
|
||||
raises: [Defect].}=
|
||||
raises: [].}=
|
||||
var request = HttpRequestRef(connection: conn, state: HttpState.Alive)
|
||||
|
||||
if req.version notin {HttpVersion10, HttpVersion11}:
|
||||
@ -678,7 +678,7 @@ proc `keepalive=`*(resp: HttpResponseRef, value: bool) =
|
||||
else:
|
||||
resp.flags.excl(HttpResponseFlags.KeepAlive)
|
||||
|
||||
proc keepalive*(resp: HttpResponseRef): bool {.raises: [Defect].} =
|
||||
proc keepalive*(resp: HttpResponseRef): bool {.raises: [].} =
|
||||
HttpResponseFlags.KeepAlive in resp.flags
|
||||
|
||||
proc processLoop(server: HttpServerRef, transp: StreamTransport,
|
||||
@ -882,7 +882,7 @@ proc acceptClientLoop(server: HttpServerRef) {.async.} =
|
||||
if breakLoop:
|
||||
break
|
||||
|
||||
proc state*(server: HttpServerRef): HttpServerState {.raises: [Defect].} =
|
||||
proc state*(server: HttpServerRef): HttpServerState {.raises: [].} =
|
||||
## Returns current HTTP server's state.
|
||||
if server.lifetime.finished():
|
||||
ServerClosed
|
||||
@ -944,7 +944,7 @@ proc join*(server: HttpServerRef): Future[void] =
|
||||
retFuture
|
||||
|
||||
proc getMultipartReader*(req: HttpRequestRef): HttpResult[MultiPartReaderRef] {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Create new MultiPartReader interface for specific request.
|
||||
if req.meth in PostMethods:
|
||||
if MultipartForm in req.requestFlags:
|
||||
@ -1040,30 +1040,30 @@ proc post*(req: HttpRequestRef): Future[HttpTable] {.async.} =
|
||||
raiseHttpCriticalError("Unsupported request body")
|
||||
|
||||
proc setHeader*(resp: HttpResponseRef, key, value: string) {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Sets value of header ``key`` to ``value``.
|
||||
doAssert(resp.state == HttpResponseState.Empty)
|
||||
resp.headersTable.set(key, value)
|
||||
|
||||
proc setHeaderDefault*(resp: HttpResponseRef, key, value: string) {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Sets value of header ``key`` to ``value``, only if header ``key`` is not
|
||||
## present in the headers table.
|
||||
discard resp.headersTable.hasKeyOrPut(key, value)
|
||||
|
||||
proc addHeader*(resp: HttpResponseRef, key, value: string) {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Adds value ``value`` to header's ``key`` value.
|
||||
doAssert(resp.state == HttpResponseState.Empty)
|
||||
resp.headersTable.add(key, value)
|
||||
|
||||
proc getHeader*(resp: HttpResponseRef, key: string,
|
||||
default: string = ""): string {.raises: [Defect].} =
|
||||
default: string = ""): string {.raises: [].} =
|
||||
## Returns value of header with name ``name`` or ``default``, if header is
|
||||
## not present in the table.
|
||||
resp.headersTable.getString(key, default)
|
||||
|
||||
proc hasHeader*(resp: HttpResponseRef, key: string): bool {.raises: [Defect].} =
|
||||
proc hasHeader*(resp: HttpResponseRef, key: string): bool {.raises: [].} =
|
||||
## Returns ``true`` if header with name ``key`` present in the headers table.
|
||||
key in resp.headersTable
|
||||
|
||||
@ -1083,7 +1083,7 @@ func createHeaders(resp: HttpResponseRef): string =
|
||||
answer
|
||||
|
||||
proc prepareLengthHeaders(resp: HttpResponseRef, length: int): string {.
|
||||
raises: [Defect].}=
|
||||
raises: [].}=
|
||||
if not(resp.hasHeader(DateHeader)):
|
||||
resp.setHeader(DateHeader, httpDate())
|
||||
if length > 0:
|
||||
@ -1101,7 +1101,7 @@ proc prepareLengthHeaders(resp: HttpResponseRef, length: int): string {.
|
||||
resp.createHeaders()
|
||||
|
||||
proc prepareChunkedHeaders(resp: HttpResponseRef): string {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
if not(resp.hasHeader(DateHeader)):
|
||||
resp.setHeader(DateHeader, httpDate())
|
||||
if not(resp.hasHeader(ContentTypeHeader)):
|
||||
@ -1118,7 +1118,7 @@ proc prepareChunkedHeaders(resp: HttpResponseRef): string {.
|
||||
resp.createHeaders()
|
||||
|
||||
proc prepareServerSideEventHeaders(resp: HttpResponseRef): string {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
if not(resp.hasHeader(DateHeader)):
|
||||
resp.setHeader(DateHeader, httpDate())
|
||||
if not(resp.hasHeader(ContentTypeHeader)):
|
||||
@ -1131,7 +1131,7 @@ proc prepareServerSideEventHeaders(resp: HttpResponseRef): string {.
|
||||
resp.createHeaders()
|
||||
|
||||
proc preparePlainHeaders(resp: HttpResponseRef): string {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
if not(resp.hasHeader(DateHeader)):
|
||||
resp.setHeader(DateHeader, httpDate())
|
||||
if not(resp.hasHeader(ServerHeader)):
|
||||
@ -1393,7 +1393,7 @@ proc remoteAddress*(request: HttpRequestRef): TransportAddress =
|
||||
request.connection.remoteAddress()
|
||||
|
||||
proc requestInfo*(req: HttpRequestRef, contentType = "text/text"): string {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Returns comprehensive information about request for specific content
|
||||
## type.
|
||||
##
|
||||
|
@ -10,10 +10,7 @@
|
||||
import std/[tables, strutils]
|
||||
import stew/base10
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
type
|
||||
HttpTable* = object
|
||||
|
@ -72,7 +72,7 @@ type
|
||||
BChar* = byte | char
|
||||
|
||||
proc startsWith(s, prefix: openArray[byte]): bool {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
# This procedure is copy of strutils.startsWith() procedure, however,
|
||||
# it is intended to work with arrays of bytes, but not with strings.
|
||||
var i = 0
|
||||
@ -82,7 +82,7 @@ proc startsWith(s, prefix: openArray[byte]): bool {.
|
||||
inc(i)
|
||||
|
||||
proc parseUntil(s, until: openArray[byte]): int {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
# This procedure is copy of parseutils.parseUntil() procedure, however,
|
||||
# it is intended to work with arrays of bytes, but not with strings.
|
||||
var i = 0
|
||||
@ -96,7 +96,7 @@ proc parseUntil(s, until: openArray[byte]): int {.
|
||||
-1
|
||||
|
||||
func setPartNames(part: var MultiPart): HttpResult[void] {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
if part.headers.count("content-disposition") != 1:
|
||||
return err("Content-Disposition header is incorrect")
|
||||
var header = part.headers.getString("content-disposition")
|
||||
@ -121,7 +121,7 @@ func setPartNames(part: var MultiPart): HttpResult[void] {.
|
||||
proc init*[A: BChar, B: BChar](mpt: typedesc[MultiPartReader],
|
||||
buffer: openArray[A],
|
||||
boundary: openArray[B]): MultiPartReader {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Create new MultiPartReader instance with `buffer` interface.
|
||||
##
|
||||
## ``buffer`` - is buffer which will be used to read data.
|
||||
@ -146,7 +146,7 @@ proc new*[B: BChar](mpt: typedesc[MultiPartReaderRef],
|
||||
stream: HttpBodyReader,
|
||||
boundary: openArray[B],
|
||||
partHeadersMaxSize = 4096): MultiPartReaderRef {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Create new MultiPartReader instance with `stream` interface.
|
||||
##
|
||||
## ``stream`` is stream used to read data.
|
||||
@ -270,7 +270,7 @@ proc consumeBody*(mp: MultiPart) {.async.} =
|
||||
discard
|
||||
|
||||
proc getBodyStream*(mp: MultiPart): HttpResult[AsyncStreamReader] {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Get multipart's ``mp`` stream, which can be used to obtain value of the
|
||||
## part.
|
||||
case mp.kind
|
||||
@ -295,7 +295,7 @@ proc closeWait*(mpr: MultiPartReaderRef) {.async.} =
|
||||
else:
|
||||
discard
|
||||
|
||||
proc getBytes*(mp: MultiPart): seq[byte] {.raises: [Defect].} =
|
||||
proc getBytes*(mp: MultiPart): seq[byte] {.raises: [].} =
|
||||
## Returns value for MultiPart ``mp`` as sequence of bytes.
|
||||
case mp.kind
|
||||
of MultiPartSource.Buffer:
|
||||
@ -304,7 +304,7 @@ proc getBytes*(mp: MultiPart): seq[byte] {.raises: [Defect].} =
|
||||
doAssert(not(mp.stream.atEof()), "Value is not obtained yet")
|
||||
mp.buffer
|
||||
|
||||
proc getString*(mp: MultiPart): string {.raises: [Defect].} =
|
||||
proc getString*(mp: MultiPart): string {.raises: [].} =
|
||||
## Returns value for MultiPart ``mp`` as string.
|
||||
case mp.kind
|
||||
of MultiPartSource.Buffer:
|
||||
@ -313,7 +313,7 @@ proc getString*(mp: MultiPart): string {.raises: [Defect].} =
|
||||
doAssert(not(mp.stream.atEof()), "Value is not obtained yet")
|
||||
bytesToString(mp.buffer)
|
||||
|
||||
proc atEoM*(mpr: var MultiPartReader): bool {.raises: [Defect].} =
|
||||
proc atEoM*(mpr: var MultiPartReader): bool {.raises: [].} =
|
||||
## Procedure returns ``true`` if MultiPartReader has reached the end of
|
||||
## multipart message.
|
||||
case mpr.kind
|
||||
@ -322,7 +322,7 @@ proc atEoM*(mpr: var MultiPartReader): bool {.raises: [Defect].} =
|
||||
of MultiPartSource.Stream:
|
||||
mpr.stream.atEof()
|
||||
|
||||
proc atEoM*(mpr: MultiPartReaderRef): bool {.raises: [Defect].} =
|
||||
proc atEoM*(mpr: MultiPartReaderRef): bool {.raises: [].} =
|
||||
## Procedure returns ``true`` if MultiPartReader has reached the end of
|
||||
## multipart message.
|
||||
case mpr.kind
|
||||
@ -332,7 +332,7 @@ proc atEoM*(mpr: MultiPartReaderRef): bool {.raises: [Defect].} =
|
||||
mpr.stream.atEof()
|
||||
|
||||
proc getPart*(mpr: var MultiPartReader): Result[MultiPart, string] {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Get multipart part from MultiPartReader instance.
|
||||
##
|
||||
## This procedure will work only for MultiPartReader with buffer source.
|
||||
@ -423,7 +423,7 @@ proc getPart*(mpr: var MultiPartReader): Result[MultiPart, string] {.
|
||||
err("Incorrect multipart form")
|
||||
|
||||
func isEmpty*(mp: MultiPart): bool {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Returns ``true`` is multipart ``mp`` is not initialized/filled yet.
|
||||
mp.counter == 0
|
||||
|
||||
@ -440,7 +440,7 @@ func validateBoundary[B: BChar](boundary: openArray[B]): HttpResult[void] =
|
||||
ok()
|
||||
|
||||
func getMultipartBoundary*(contentData: ContentTypeData): HttpResult[string] {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Returns ``multipart/form-data`` boundary value from ``Content-Type``
|
||||
## header.
|
||||
##
|
||||
@ -481,7 +481,7 @@ proc quoteCheck(name: string): HttpResult[string] =
|
||||
|
||||
proc init*[B: BChar](mpt: typedesc[MultiPartWriter],
|
||||
boundary: openArray[B]): MultiPartWriter {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Create new MultiPartWriter instance with `buffer` interface.
|
||||
##
|
||||
## ``boundary`` - is multipart boundary, this value must not be empty.
|
||||
@ -511,7 +511,7 @@ proc init*[B: BChar](mpt: typedesc[MultiPartWriter],
|
||||
proc new*[B: BChar](mpt: typedesc[MultiPartWriterRef],
|
||||
stream: HttpBodyWriter,
|
||||
boundary: openArray[B]): MultiPartWriterRef {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
doAssert(validateBoundary(boundary).isOk())
|
||||
doAssert(not(isNil(stream)))
|
||||
|
||||
|
@ -70,7 +70,7 @@ proc new*(htype: typedesc[SecureHttpServerRef],
|
||||
httpHeadersTimeout = 10.seconds,
|
||||
maxHeadersSize: int = 8192,
|
||||
maxRequestBodySize: int = 1_048_576
|
||||
): HttpResult[SecureHttpServerRef] {.raises: [Defect].} =
|
||||
): HttpResult[SecureHttpServerRef] {.raises: [].} =
|
||||
|
||||
doAssert(not(isNil(tlsPrivateKey)), "TLS private key must not be nil!")
|
||||
doAssert(not(isNil(tlsCertificate)), "TLS certificate must not be nil!")
|
||||
|
@ -31,10 +31,7 @@ template LocCompleteIndex*: untyped {.deprecated: "LocFinishIndex".} =
|
||||
LocFinishIndex
|
||||
|
||||
when chronosStrictException:
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.pragma: closureIter, raises: [Defect, CatchableError], gcsafe.}
|
||||
else:
|
||||
{.pragma: closureIter, raises: [CatchableError], gcsafe.}
|
||||
{.pragma: closureIter, raises: [CatchableError], gcsafe.}
|
||||
else:
|
||||
{.pragma: closureIter, raises: [Exception], gcsafe.}
|
||||
|
||||
@ -380,14 +377,14 @@ proc `cancelCallback=`*(future: FutureBase, cb: CallbackFunc) =
|
||||
future.cancelcb = cb
|
||||
|
||||
{.push stackTrace: off.}
|
||||
proc futureContinue*(fut: FutureBase) {.raises: [Defect], gcsafe.}
|
||||
proc futureContinue*(fut: FutureBase) {.raises: [], gcsafe.}
|
||||
|
||||
proc internalContinue(fut: pointer) {.raises: [Defect], gcsafe.} =
|
||||
proc internalContinue(fut: pointer) {.raises: [], gcsafe.} =
|
||||
let asFut = cast[FutureBase](fut)
|
||||
GC_unref(asFut)
|
||||
futureContinue(asFut)
|
||||
|
||||
proc futureContinue*(fut: FutureBase) {.raises: [Defect], gcsafe.} =
|
||||
proc futureContinue*(fut: FutureBase) {.raises: [], gcsafe.} =
|
||||
# This function is responsible for calling the closure iterator generated by
|
||||
# the `{.async.}` transformation either until it has completed its iteration
|
||||
# or raised and error / been cancelled.
|
||||
@ -528,8 +525,7 @@ when chronosStackTrace:
|
||||
# newMsg.add "\n" & $entry
|
||||
error.msg = newMsg
|
||||
|
||||
proc internalCheckComplete*(fut: FutureBase) {.
|
||||
raises: [Defect, CatchableError].} =
|
||||
proc internalCheckComplete*(fut: FutureBase) {.raises: [CatchableError].} =
|
||||
# For internal use only. Used in asyncmacro
|
||||
if not(isNil(fut.error)):
|
||||
when chronosStackTrace:
|
||||
@ -541,8 +537,7 @@ proc internalRead*[T](fut: Future[T]): T {.inline.} =
|
||||
when T isnot void:
|
||||
return fut.value
|
||||
|
||||
proc read*[T](future: Future[T] ): T {.
|
||||
raises: [Defect, CatchableError].} =
|
||||
proc read*[T](future: Future[T] ): T {.raises: [CatchableError].} =
|
||||
## Retrieves the value of ``future``. Future must be finished otherwise
|
||||
## this function will fail with a ``ValueError`` exception.
|
||||
##
|
||||
@ -554,8 +549,7 @@ proc read*[T](future: Future[T] ): T {.
|
||||
# TODO: Make a custom exception type for this?
|
||||
raise newException(ValueError, "Future still in progress.")
|
||||
|
||||
proc readError*(future: FutureBase): ref CatchableError {.
|
||||
raises: [Defect, ValueError].} =
|
||||
proc readError*(future: FutureBase): ref CatchableError {.raises: [ValueError].} =
|
||||
## Retrieves the exception stored in ``future``.
|
||||
##
|
||||
## An ``ValueError`` exception will be thrown if no exception exists
|
||||
@ -682,8 +676,8 @@ proc `or`*[T, Y](fut1: Future[T], fut2: Future[Y]): Future[void] =
|
||||
##
|
||||
## If cancelled, ``fut1`` and ``fut2`` futures WILL NOT BE cancelled.
|
||||
var retFuture = newFuture[void]("chronos.or")
|
||||
var cb: proc(udata: pointer) {.gcsafe, raises: [Defect].}
|
||||
cb = proc(udata: pointer) {.gcsafe, raises: [Defect].} =
|
||||
var cb: proc(udata: pointer) {.gcsafe, raises: [].}
|
||||
cb = proc(udata: pointer) {.gcsafe, raises: [].} =
|
||||
if not(retFuture.finished()):
|
||||
var fut = cast[FutureBase](udata)
|
||||
if cast[pointer](fut1) == udata:
|
||||
@ -996,8 +990,8 @@ proc one*[T](futs: varargs[Future[T]]): Future[Future[T]] =
|
||||
# Because we can't capture varargs[T] in closures we need to create copy.
|
||||
var nfuts = @futs
|
||||
|
||||
var cb: proc(udata: pointer) {.gcsafe, raises: [Defect].}
|
||||
cb = proc(udata: pointer) {.gcsafe, raises: [Defect].} =
|
||||
var cb: proc(udata: pointer) {.gcsafe, raises: [].}
|
||||
cb = proc(udata: pointer) {.gcsafe, raises: [].} =
|
||||
if not(retFuture.finished()):
|
||||
var res: Future[T]
|
||||
var rfut = cast[FutureBase](udata)
|
||||
@ -1044,8 +1038,8 @@ proc race*(futs: varargs[FutureBase]): Future[FutureBase] =
|
||||
# Because we can't capture varargs[T] in closures we need to create copy.
|
||||
var nfuts = @futs
|
||||
|
||||
var cb: proc(udata: pointer) {.gcsafe, raises: [Defect].}
|
||||
cb = proc(udata: pointer) {.gcsafe, raises: [Defect].} =
|
||||
var cb: proc(udata: pointer) {.gcsafe, raises: [].}
|
||||
cb = proc(udata: pointer) {.gcsafe, raises: [].} =
|
||||
if not(retFuture.finished()):
|
||||
var res: FutureBase
|
||||
var rfut = cast[FutureBase](udata)
|
||||
|
@ -8,12 +8,7 @@
|
||||
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
||||
# MIT license (LICENSE-MIT)
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
{.pragma: callbackFunc, stdcall, gcsafe, raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.pragma: callbackFunc, stdcall, gcsafe, raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
from nativesockets import Port
|
||||
import std/[tables, strutils, heapqueue, deques]
|
||||
@ -160,7 +155,7 @@ elif defined(macosx) or defined(freebsd) or defined(netbsd) or
|
||||
export oserrno
|
||||
|
||||
type
|
||||
CallbackFunc* = proc (arg: pointer) {.gcsafe, raises: [Defect].}
|
||||
CallbackFunc* = proc (arg: pointer) {.gcsafe, raises: [].}
|
||||
|
||||
AsyncCallback* = object
|
||||
function*: CallbackFunc
|
||||
@ -177,8 +172,8 @@ type
|
||||
|
||||
TrackerBase* = ref object of RootRef
|
||||
id*: string
|
||||
dump*: proc(): string {.gcsafe, raises: [Defect].}
|
||||
isLeaked*: proc(): bool {.gcsafe, raises: [Defect].}
|
||||
dump*: proc(): string {.gcsafe, raises: [].}
|
||||
isLeaked*: proc(): bool {.gcsafe, raises: [].}
|
||||
|
||||
PDispatcherBase = ref object of RootRef
|
||||
timers*: HeapQueue[TimerCallback]
|
||||
@ -291,6 +286,8 @@ func toException*(v: OSErrorCode): ref OSError = newOSError(v)
|
||||
# Result[T, OSErrorCode] values.
|
||||
|
||||
when defined(windows):
|
||||
{.pragma: stdcallbackFunc, stdcall, gcsafe, raises: [].}
|
||||
|
||||
export SIGINT, SIGQUIT, SIGTERM
|
||||
type
|
||||
CompletionKey = ULONG_PTR
|
||||
@ -419,8 +416,8 @@ when defined(windows):
|
||||
|
||||
var gDisp{.threadvar.}: PDispatcher ## Global dispatcher
|
||||
|
||||
proc setThreadDispatcher*(disp: PDispatcher) {.gcsafe, raises: [Defect].}
|
||||
proc getThreadDispatcher*(): PDispatcher {.gcsafe, raises: [Defect].}
|
||||
proc setThreadDispatcher*(disp: PDispatcher) {.gcsafe, raises: [].}
|
||||
proc getThreadDispatcher*(): PDispatcher {.gcsafe, raises: [].}
|
||||
|
||||
proc getIoHandler*(disp: PDispatcher): HANDLE =
|
||||
## Returns the underlying IO Completion Port handle (Windows) or selector
|
||||
@ -436,7 +433,7 @@ when defined(windows):
|
||||
loop.handles.incl(fd)
|
||||
ok()
|
||||
|
||||
proc register*(fd: AsyncFD) {.raises: [Defect, OSError].} =
|
||||
proc register*(fd: AsyncFD) {.raises: [OSError].} =
|
||||
## Register file descriptor ``fd`` in thread's dispatcher.
|
||||
register2(fd).tryGet()
|
||||
|
||||
@ -446,7 +443,7 @@ when defined(windows):
|
||||
|
||||
{.push stackTrace: off.}
|
||||
proc waitableCallback(param: pointer, timerOrWaitFired: WINBOOL) {.
|
||||
callbackFunc.} =
|
||||
stdcallbackFunc.} =
|
||||
# This procedure will be executed in `wait thread`, so it must not use
|
||||
# GC related objects.
|
||||
# We going to ignore callbacks which was spawned when `isNil(param) == true`
|
||||
@ -568,19 +565,19 @@ when defined(windows):
|
||||
|
||||
proc addProcess*(pid: int, cb: CallbackFunc,
|
||||
udata: pointer = nil): ProcessHandle {.
|
||||
raises: [Defect, OSError].} =
|
||||
raises: [OSError].} =
|
||||
## Registers callback ``cb`` to be called when process with process
|
||||
## identifier ``pid`` exited. Returns process identifier, which can be
|
||||
## used to clear process callback via ``removeProcess``.
|
||||
addProcess2(pid, cb, udata).tryGet()
|
||||
|
||||
proc removeProcess*(procHandle: ProcessHandle) {.
|
||||
raises: [Defect, OSError].} =
|
||||
raises: [ OSError].} =
|
||||
## Remove process' watching using process' descriptor ``procHandle``.
|
||||
removeProcess2(procHandle).tryGet()
|
||||
|
||||
{.push stackTrace: off.}
|
||||
proc consoleCtrlEventHandler(dwCtrlType: DWORD): uint32 {.callbackFunc.} =
|
||||
proc consoleCtrlEventHandler(dwCtrlType: DWORD): uint32 {.stdcallbackFunc.} =
|
||||
## This procedure will be executed in different thread, so it MUST not use
|
||||
## any GC related features (strings, seqs, echo etc.).
|
||||
case dwCtrlType
|
||||
@ -645,7 +642,7 @@ when defined(windows):
|
||||
|
||||
proc addSignal*(signal: int, cb: CallbackFunc,
|
||||
udata: pointer = nil): SignalHandle {.
|
||||
raises: [Defect, ValueError].} =
|
||||
raises: [ValueError].} =
|
||||
## Registers callback ``cb`` to be called when signal ``signal`` will be
|
||||
## raised. Returns signal identifier, which can be used to clear signal
|
||||
## callback via ``removeSignal``.
|
||||
@ -653,7 +650,7 @@ when defined(windows):
|
||||
raise newException(ValueError, osErrorMsg(error))
|
||||
|
||||
proc removeSignal*(signalHandle: SignalHandle) {.
|
||||
raises: [Defect, ValueError].} =
|
||||
raises: [ValueError].} =
|
||||
## Remove signal's watching using signal descriptor ``signalfd``.
|
||||
let res = removeSignal2(signalHandle)
|
||||
if res.isErr():
|
||||
@ -829,8 +826,8 @@ elif defined(macosx) or defined(freebsd) or defined(netbsd) or
|
||||
|
||||
var gDisp{.threadvar.}: PDispatcher ## Global dispatcher
|
||||
|
||||
proc setThreadDispatcher*(disp: PDispatcher) {.gcsafe, raises: [Defect].}
|
||||
proc getThreadDispatcher*(): PDispatcher {.gcsafe, raises: [Defect].}
|
||||
proc setThreadDispatcher*(disp: PDispatcher) {.gcsafe, raises: [].}
|
||||
proc getThreadDispatcher*(): PDispatcher {.gcsafe, raises: [].}
|
||||
|
||||
proc getIoHandler*(disp: PDispatcher): Selector[SelectorData] =
|
||||
## Returns system specific OS queue.
|
||||
@ -905,31 +902,31 @@ elif defined(macosx) or defined(freebsd) or defined(netbsd) or
|
||||
return err(osdefs.EBADF)
|
||||
loop.selector.updateHandle2(cint(fd), newEvents)
|
||||
|
||||
proc register*(fd: AsyncFD) {.raises: [Defect, OSError].} =
|
||||
proc register*(fd: AsyncFD) {.raises: [OSError].} =
|
||||
## Register file descriptor ``fd`` in thread's dispatcher.
|
||||
register2(fd).tryGet()
|
||||
|
||||
proc unregister*(fd: AsyncFD) {.raises: [Defect, OSError].} =
|
||||
proc unregister*(fd: AsyncFD) {.raises: [OSError].} =
|
||||
## Unregister file descriptor ``fd`` from thread's dispatcher.
|
||||
unregister2(fd).tryGet()
|
||||
|
||||
proc addReader*(fd: AsyncFD, cb: CallbackFunc, udata: pointer = nil) {.
|
||||
raises: [Defect, OSError].} =
|
||||
raises: [OSError].} =
|
||||
## Start watching the file descriptor ``fd`` for read availability and then
|
||||
## call the callback ``cb`` with specified argument ``udata``.
|
||||
addReader2(fd, cb, udata).tryGet()
|
||||
|
||||
proc removeReader*(fd: AsyncFD) {.raises: [Defect, OSError].} =
|
||||
proc removeReader*(fd: AsyncFD) {.raises: [OSError].} =
|
||||
## Stop watching the file descriptor ``fd`` for read availability.
|
||||
removeReader2(fd).tryGet()
|
||||
|
||||
proc addWriter*(fd: AsyncFD, cb: CallbackFunc, udata: pointer = nil) {.
|
||||
raises: [Defect, OSError].} =
|
||||
raises: [OSError].} =
|
||||
## Start watching the file descriptor ``fd`` for write availability and then
|
||||
## call the callback ``cb`` with specified argument ``udata``.
|
||||
addWriter2(fd, cb, udata).tryGet()
|
||||
|
||||
proc removeWriter*(fd: AsyncFD) {.raises: [Defect, OSError].} =
|
||||
proc removeWriter*(fd: AsyncFD) {.raises: [OSError].} =
|
||||
## Stop watching the file descriptor ``fd`` for write availability.
|
||||
removeWriter2(fd).tryGet()
|
||||
|
||||
@ -1051,7 +1048,7 @@ elif defined(macosx) or defined(freebsd) or defined(netbsd) or
|
||||
|
||||
proc addSignal*(signal: int, cb: CallbackFunc,
|
||||
udata: pointer = nil): SignalHandle {.
|
||||
raises: [Defect, OSError].} =
|
||||
raises: [OSError].} =
|
||||
## Start watching signal ``signal``, and when signal appears, call the
|
||||
## callback ``cb`` with specified argument ``udata``. Returns signal
|
||||
## identifier code, which can be used to remove signal callback
|
||||
@ -1059,20 +1056,20 @@ elif defined(macosx) or defined(freebsd) or defined(netbsd) or
|
||||
addSignal2(signal, cb, udata).tryGet()
|
||||
|
||||
proc removeSignal*(signalHandle: SignalHandle) {.
|
||||
raises: [Defect, OSError].} =
|
||||
raises: [OSError].} =
|
||||
## Remove watching signal ``signal``.
|
||||
removeSignal2(signalHandle).tryGet()
|
||||
|
||||
proc addProcess*(pid: int, cb: CallbackFunc,
|
||||
udata: pointer = nil): ProcessHandle {.
|
||||
raises: [Defect, OSError].} =
|
||||
raises: [OSError].} =
|
||||
## Registers callback ``cb`` to be called when process with process
|
||||
## identifier ``pid`` exited. Returns process identifier, which can be
|
||||
## used to clear process callback via ``removeProcess``.
|
||||
addProcess2(pid, cb, udata).tryGet()
|
||||
|
||||
proc removeProcess*(procHandle: ProcessHandle) {.
|
||||
raises: [Defect, OSError].} =
|
||||
raises: [OSError].} =
|
||||
## Remove process' watching using process' descriptor ``procHandle``.
|
||||
removeProcess2(procHandle).tryGet()
|
||||
|
||||
@ -1254,7 +1251,7 @@ when defined(macosx) or defined(macos) or defined(freebsd) or
|
||||
defined(netbsd) or defined(openbsd) or defined(dragonfly) or
|
||||
defined(linux) or defined(windows):
|
||||
|
||||
proc waitSignal*(signal: int): Future[void] {.raises: [Defect].} =
|
||||
proc waitSignal*(signal: int): Future[void] {.raises: [].} =
|
||||
var retFuture = newFuture[void]("chronos.waitSignal()")
|
||||
var signalHandle: Opt[SignalHandle]
|
||||
|
||||
@ -1324,8 +1321,8 @@ proc stepsAsync*(number: int): Future[void] =
|
||||
var retFuture = newFuture[void]("chronos.stepsAsync(int)")
|
||||
var counter = 0
|
||||
|
||||
var continuation: proc(data: pointer) {.gcsafe, raises: [Defect].}
|
||||
continuation = proc(data: pointer) {.gcsafe, raises: [Defect].} =
|
||||
var continuation: proc(data: pointer) {.gcsafe, raises: [].}
|
||||
continuation = proc(data: pointer) {.gcsafe, raises: [].} =
|
||||
if not(retFuture.finished()):
|
||||
inc(counter)
|
||||
if counter < number:
|
||||
@ -1376,7 +1373,7 @@ proc withTimeout*[T](fut: Future[T], timeout: Duration): Future[bool] =
|
||||
|
||||
# TODO: raises annotation shouldn't be needed, but likely similar issue as
|
||||
# https://github.com/nim-lang/Nim/issues/17369
|
||||
proc continuation(udata: pointer) {.gcsafe, raises: [Defect].} =
|
||||
proc continuation(udata: pointer) {.gcsafe, raises: [].} =
|
||||
if not(retFuture.finished()):
|
||||
if not(cancelling):
|
||||
if not(fut.finished()):
|
||||
@ -1394,7 +1391,7 @@ proc withTimeout*[T](fut: Future[T], timeout: Duration): Future[bool] =
|
||||
|
||||
# TODO: raises annotation shouldn't be needed, but likely similar issue as
|
||||
# https://github.com/nim-lang/Nim/issues/17369
|
||||
proc cancellation(udata: pointer) {.gcsafe, raises: [Defect].} =
|
||||
proc cancellation(udata: pointer) {.gcsafe, raises: [].} =
|
||||
if not isNil(timer):
|
||||
clearTimer(timer)
|
||||
if not(fut.finished()):
|
||||
@ -1435,7 +1432,7 @@ proc wait*[T](fut: Future[T], timeout = InfiniteDuration): Future[T] =
|
||||
var timer: TimerCallback
|
||||
var cancelling = false
|
||||
|
||||
proc continuation(udata: pointer) {.raises: [Defect].} =
|
||||
proc continuation(udata: pointer) {.raises: [].} =
|
||||
if not(retFuture.finished()):
|
||||
if not(cancelling):
|
||||
if not(fut.finished()):
|
||||
@ -1457,8 +1454,8 @@ proc wait*[T](fut: Future[T], timeout = InfiniteDuration): Future[T] =
|
||||
else:
|
||||
retFuture.fail(newException(AsyncTimeoutError, "Timeout exceeded!"))
|
||||
|
||||
var cancellation: proc(udata: pointer) {.gcsafe, raises: [Defect].}
|
||||
cancellation = proc(udata: pointer) {.gcsafe, raises: [Defect].} =
|
||||
var cancellation: proc(udata: pointer) {.gcsafe, raises: [].}
|
||||
cancellation = proc(udata: pointer) {.gcsafe, raises: [].} =
|
||||
if not isNil(timer):
|
||||
clearTimer(timer)
|
||||
if not(fut.finished()):
|
||||
@ -1504,7 +1501,7 @@ proc runForever*() =
|
||||
while true:
|
||||
poll()
|
||||
|
||||
proc waitFor*[T](fut: Future[T]): T {.raises: [Defect, CatchableError].} =
|
||||
proc waitFor*[T](fut: Future[T]): T {.raises: [CatchableError].} =
|
||||
## **Blocks** the current thread until the specified future completes.
|
||||
## There's no way to tell if poll or read raised the exception
|
||||
while not(fut.finished()):
|
||||
@ -1540,7 +1537,7 @@ when chronosFutureTracking:
|
||||
when defined(windows):
|
||||
proc waitForSingleObject*(handle: HANDLE,
|
||||
timeout: Duration): Future[WaitableResult] {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Waits until the specified object is in the signaled state or the
|
||||
## time-out interval elapses. WaitForSingleObject() for asynchronous world.
|
||||
let flags = WT_EXECUTEONLYONCE
|
||||
|
@ -211,8 +211,6 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
|
||||
let raises = nnkBracket.newTree()
|
||||
when chronosStrictException:
|
||||
raises.add(newIdentNode("CatchableError"))
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
raises.add(newIdentNode("Defect"))
|
||||
else:
|
||||
raises.add(newIdentNode("Exception"))
|
||||
|
||||
@ -268,12 +266,9 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
|
||||
# https://github.com/nim-lang/RFCs/issues/435
|
||||
prc.addPragma(newIdentNode("gcsafe"))
|
||||
|
||||
let raises = nnkBracket.newTree()
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
raises.add(newIdentNode("Defect"))
|
||||
prc.addPragma(nnkExprColonExpr.newTree(
|
||||
newIdentNode("raises"),
|
||||
raises
|
||||
nnkBracket.newTree()
|
||||
))
|
||||
|
||||
if baseTypeIsVoid:
|
||||
|
@ -7,12 +7,8 @@
|
||||
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
||||
# MIT license (LICENSE-MIT)
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
{.pragma: apforward, gcsafe, raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.pragma: apforward, gcsafe, raises: [].}
|
||||
{.push raises: [].}
|
||||
{.pragma: apforward, gcsafe, raises: [].}
|
||||
|
||||
import std/strtabs
|
||||
import "."/[config, asyncloop, handles, osdefs, osutils, oserrno],
|
||||
|
@ -10,10 +10,7 @@
|
||||
|
||||
## This module implements some core synchronization primitives.
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[sequtils, math, deques, tables, typetraits]
|
||||
import ./asyncloop
|
||||
@ -67,17 +64,17 @@ type
|
||||
|
||||
EventBusSubscription*[T] = proc(bus: AsyncEventBus,
|
||||
payload: EventPayload[T]): Future[void] {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
## EventBus subscription callback type.
|
||||
|
||||
EventBusAllSubscription* = proc(bus: AsyncEventBus,
|
||||
event: AwaitableEvent): Future[void] {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
## EventBus subscription callback type.
|
||||
|
||||
EventBusCallback = proc(bus: AsyncEventBus, event: string, key: EventBusKey,
|
||||
data: EventPayloadBase) {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
|
||||
EventBusKey* = object
|
||||
## Unique subscription key.
|
||||
@ -186,7 +183,7 @@ proc locked*(lock: AsyncLock): bool =
|
||||
## Return `true` if the lock ``lock`` is acquired, `false` otherwise.
|
||||
lock.locked
|
||||
|
||||
proc release*(lock: AsyncLock) {.raises: [Defect, AsyncLockError].} =
|
||||
proc release*(lock: AsyncLock) {.raises: [AsyncLockError].} =
|
||||
## Release a lock ``lock``.
|
||||
##
|
||||
## When the ``lock`` is locked, reset it to unlocked, and return. If any
|
||||
@ -224,7 +221,7 @@ proc wait*(event: AsyncEvent): Future[void] =
|
||||
## block until another task calls `fire()` to set the flag to `true`,
|
||||
## then return.
|
||||
let retFuture = newFuture[void]("AsyncEvent.wait")
|
||||
proc cancellation(udata: pointer) {.gcsafe, raises: [Defect].} =
|
||||
proc cancellation(udata: pointer) {.gcsafe, raises: [].} =
|
||||
event.waiters.keepItIf(it != retFuture)
|
||||
if not(event.flag):
|
||||
retFuture.cancelCallback = cancellation
|
||||
@ -298,7 +295,7 @@ proc empty*[T](aq: AsyncQueue[T]): bool {.inline.} =
|
||||
(len(aq.queue) == 0)
|
||||
|
||||
proc addFirstNoWait*[T](aq: AsyncQueue[T], item: T) {.
|
||||
raises: [Defect, AsyncQueueFullError].}=
|
||||
raises: [AsyncQueueFullError].}=
|
||||
## Put an item ``item`` to the beginning of the queue ``aq`` immediately.
|
||||
##
|
||||
## If queue ``aq`` is full, then ``AsyncQueueFullError`` exception raised.
|
||||
@ -308,7 +305,7 @@ proc addFirstNoWait*[T](aq: AsyncQueue[T], item: T) {.
|
||||
aq.getters.wakeupNext()
|
||||
|
||||
proc addLastNoWait*[T](aq: AsyncQueue[T], item: T) {.
|
||||
raises: [Defect, AsyncQueueFullError].}=
|
||||
raises: [AsyncQueueFullError].}=
|
||||
## Put an item ``item`` at the end of the queue ``aq`` immediately.
|
||||
##
|
||||
## If queue ``aq`` is full, then ``AsyncQueueFullError`` exception raised.
|
||||
@ -318,7 +315,7 @@ proc addLastNoWait*[T](aq: AsyncQueue[T], item: T) {.
|
||||
aq.getters.wakeupNext()
|
||||
|
||||
proc popFirstNoWait*[T](aq: AsyncQueue[T]): T {.
|
||||
raises: [Defect, AsyncQueueEmptyError].} =
|
||||
raises: [AsyncQueueEmptyError].} =
|
||||
## Get an item from the beginning of the queue ``aq`` immediately.
|
||||
##
|
||||
## If queue ``aq`` is empty, then ``AsyncQueueEmptyError`` exception raised.
|
||||
@ -329,7 +326,7 @@ proc popFirstNoWait*[T](aq: AsyncQueue[T]): T {.
|
||||
res
|
||||
|
||||
proc popLastNoWait*[T](aq: AsyncQueue[T]): T {.
|
||||
raises: [Defect, AsyncQueueEmptyError].} =
|
||||
raises: [AsyncQueueEmptyError].} =
|
||||
## Get an item from the end of the queue ``aq`` immediately.
|
||||
##
|
||||
## If queue ``aq`` is empty, then ``AsyncQueueEmptyError`` exception raised.
|
||||
@ -396,12 +393,12 @@ proc popLast*[T](aq: AsyncQueue[T]): Future[T] {.async.} =
|
||||
return aq.popLastNoWait()
|
||||
|
||||
proc putNoWait*[T](aq: AsyncQueue[T], item: T) {.
|
||||
raises: [Defect, AsyncQueueFullError].} =
|
||||
raises: [AsyncQueueFullError].} =
|
||||
## Alias of ``addLastNoWait()``.
|
||||
aq.addLastNoWait(item)
|
||||
|
||||
proc getNoWait*[T](aq: AsyncQueue[T]): T {.
|
||||
raises: [Defect, AsyncQueueEmptyError].} =
|
||||
raises: [AsyncQueueEmptyError].} =
|
||||
## Alias of ``popFirstNoWait()``.
|
||||
aq.popFirstNoWait()
|
||||
|
||||
@ -514,7 +511,7 @@ proc waitEvent*(bus: AsyncEventBus, T: typedesc, event: string): Future[T] {.
|
||||
var default: EventItem
|
||||
var retFuture = newFuture[T]("AsyncEventBus.waitEvent")
|
||||
let eventKey = generateKey(T.name, event)
|
||||
proc cancellation(udata: pointer) {.gcsafe, raises: [Defect].} =
|
||||
proc cancellation(udata: pointer) {.gcsafe, raises: [].} =
|
||||
if not(retFuture.finished()):
|
||||
bus.events.withValue(eventKey, item):
|
||||
item.waiters.keepItIf(it != cast[FutureBase](retFuture))
|
||||
@ -531,7 +528,7 @@ proc waitAllEvents*(bus: AsyncEventBus): Future[AwaitableEvent] {.
|
||||
## Returns ``Future`` which holds helper object. Using this object you can
|
||||
## retrieve event's name and payload.
|
||||
var retFuture = newFuture[AwaitableEvent]("AsyncEventBus.waitAllEvents")
|
||||
proc cancellation(udata: pointer) {.gcsafe, raises: [Defect].} =
|
||||
proc cancellation(udata: pointer) {.gcsafe, raises: [].} =
|
||||
if not(retFuture.finished()):
|
||||
bus.waiters.keepItIf(it != retFuture)
|
||||
retFuture.cancelCallback = cancellation
|
||||
@ -547,7 +544,7 @@ proc subscribe*[T](bus: AsyncEventBus, event: string,
|
||||
##
|
||||
## Returns key that can be used to unsubscribe.
|
||||
proc trampoline(tbus: AsyncEventBus, event: string, key: EventBusKey,
|
||||
data: EventPayloadBase) {.gcsafe, raises: [Defect].} =
|
||||
data: EventPayloadBase) {.gcsafe, raises: [].} =
|
||||
let payload = cast[EventPayload[T]](data)
|
||||
asyncSpawn callback(bus, payload)
|
||||
|
||||
@ -571,7 +568,7 @@ proc subscribeAll*(bus: AsyncEventBus,
|
||||
##
|
||||
## Returns key that can be used to unsubscribe.
|
||||
proc trampoline(tbus: AsyncEventBus, event: string, key: EventBusKey,
|
||||
data: EventPayloadBase) {.gcsafe, raises: [Defect].} =
|
||||
data: EventPayloadBase) {.gcsafe, raises: [].} =
|
||||
let event = AwaitableEvent(eventName: event, payload: data)
|
||||
asyncSpawn callback(bus, event)
|
||||
|
||||
@ -660,7 +657,7 @@ template emitWait*[T](bus: AsyncEventBus, event: string,
|
||||
|
||||
proc `==`(a, b: EventQueueKey): bool {.borrow.}
|
||||
|
||||
proc compact(ab: AsyncEventQueue) {.raises: [Defect].} =
|
||||
proc compact(ab: AsyncEventQueue) {.raises: [].} =
|
||||
if len(ab.readers) > 0:
|
||||
let minOffset =
|
||||
block:
|
||||
@ -684,14 +681,14 @@ proc compact(ab: AsyncEventQueue) {.raises: [Defect].} =
|
||||
ab.queue.clear()
|
||||
|
||||
proc getReaderIndex(ab: AsyncEventQueue, key: EventQueueKey): int {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
for index, value in ab.readers.pairs():
|
||||
if value.key == key:
|
||||
return index
|
||||
-1
|
||||
|
||||
proc newAsyncEventQueue*[T](limitSize = 0): AsyncEventQueue[T] {.
|
||||
raises: [Defect].} =
|
||||
raises: [].} =
|
||||
## Creates new ``AsyncEventBus`` maximum size of ``limitSize`` (default is
|
||||
## ``0`` which means that there no limits).
|
||||
##
|
||||
@ -709,10 +706,10 @@ proc newAsyncEventQueue*[T](limitSize = 0): AsyncEventQueue[T] {.
|
||||
initDeque[T](nextPowerOfTwo(limitSize + 1))
|
||||
AsyncEventQueue[T](counter: 0'u64, queue: queue, limit: limitSize)
|
||||
|
||||
proc len*(ab: AsyncEventQueue): int {.raises: [Defect].} =
|
||||
proc len*(ab: AsyncEventQueue): int {.raises: [].} =
|
||||
len(ab.queue)
|
||||
|
||||
proc register*(ab: AsyncEventQueue): EventQueueKey {.raises: [Defect].} =
|
||||
proc register*(ab: AsyncEventQueue): EventQueueKey {.raises: [].} =
|
||||
inc(ab.counter)
|
||||
let reader = EventQueueReader(key: EventQueueKey(ab.counter),
|
||||
offset: ab.offset + len(ab.queue),
|
||||
@ -721,7 +718,7 @@ proc register*(ab: AsyncEventQueue): EventQueueKey {.raises: [Defect].} =
|
||||
EventQueueKey(ab.counter)
|
||||
|
||||
proc unregister*(ab: AsyncEventQueue, key: EventQueueKey) {.
|
||||
raises: [Defect] .} =
|
||||
raises: [] .} =
|
||||
let index = ab.getReaderIndex(key)
|
||||
if index >= 0:
|
||||
let reader = ab.readers[index]
|
||||
@ -731,14 +728,14 @@ proc unregister*(ab: AsyncEventQueue, key: EventQueueKey) {.
|
||||
ab.readers.delete(index)
|
||||
ab.compact()
|
||||
|
||||
proc close*(ab: AsyncEventQueue) {.raises: [Defect].} =
|
||||
proc close*(ab: AsyncEventQueue) {.raises: [].} =
|
||||
for reader in ab.readers.items():
|
||||
if not(isNil(reader.waiter)) and not(reader.waiter.finished()):
|
||||
reader.waiter.complete()
|
||||
ab.readers.reset()
|
||||
ab.queue.clear()
|
||||
|
||||
proc closeWait*(ab: AsyncEventQueue): Future[void] {.raises: [Defect].} =
|
||||
proc closeWait*(ab: AsyncEventQueue): Future[void] {.raises: [].} =
|
||||
var retFuture = newFuture[void]("AsyncEventQueue.closeWait()")
|
||||
proc continuation(udata: pointer) {.gcsafe.} =
|
||||
if not(retFuture.finished()):
|
||||
@ -753,7 +750,7 @@ template readerOverflow*(ab: AsyncEventQueue,
|
||||
reader: EventQueueReader): bool =
|
||||
ab.limit + (reader.offset - ab.offset) <= len(ab.queue)
|
||||
|
||||
proc emit*[T](ab: AsyncEventQueue[T], data: T) {.raises: [Defect].} =
|
||||
proc emit*[T](ab: AsyncEventQueue[T], data: T) {.raises: [].} =
|
||||
if len(ab.readers) > 0:
|
||||
# We enqueue `data` only if there active reader present.
|
||||
var changesPresent = false
|
||||
|
@ -7,10 +7,7 @@
|
||||
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
||||
# MIT license (LICENSE-MIT)
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
import "."/[asyncloop, config]
|
||||
export asyncloop
|
||||
|
@ -7,10 +7,7 @@
|
||||
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
||||
# MIT license (LICENSE-MIT)
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
import "."/[asyncloop, osdefs, osutils]
|
||||
import stew/results
|
||||
@ -156,7 +153,7 @@ proc createAsyncSocket*(domain: Domain, sockType: SockType,
|
||||
return asyncInvalidSocket
|
||||
|
||||
proc wrapAsyncSocket*(sock: cint|SocketHandle): AsyncFD {.
|
||||
raises: [Defect, CatchableError].} =
|
||||
raises: [CatchableError].} =
|
||||
## Wraps socket to asynchronous socket handle.
|
||||
## Return ``asyncInvalidSocket`` on error.
|
||||
wrapAsyncSocket2(sock).valueOr:
|
||||
@ -191,7 +188,7 @@ proc setMaxOpenFiles2*(count: int): Result[void, OSErrorCode] =
|
||||
return err(osLastError())
|
||||
ok()
|
||||
|
||||
proc getMaxOpenFiles*(): int {.raises: [Defect, OSError].} =
|
||||
proc getMaxOpenFiles*(): int {.raises: [OSError].} =
|
||||
## Returns maximum file descriptor number that can be opened by this process.
|
||||
##
|
||||
## Note: On Windows its impossible to obtain such number, so getMaxOpenFiles()
|
||||
@ -202,7 +199,7 @@ proc getMaxOpenFiles*(): int {.raises: [Defect, OSError].} =
|
||||
raiseOSError(res.error())
|
||||
res.get()
|
||||
|
||||
proc setMaxOpenFiles*(count: int) {.raises: [Defect, OSError].} =
|
||||
proc setMaxOpenFiles*(count: int) {.raises: [OSError].} =
|
||||
## Set maximum file descriptor number that can be opened by this process.
|
||||
##
|
||||
## Note: On Windows its impossible to set this value, so it just a nop call.
|
||||
|
@ -11,10 +11,7 @@
|
||||
import std/[deques, tables]
|
||||
import stew/base10
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
type
|
||||
SelectorImpl[T] = object
|
||||
@ -677,70 +674,70 @@ proc select2*[T](s: Selector[T], timeout: int): SelectResult[seq[ReadyKey]] =
|
||||
ok(res)
|
||||
|
||||
proc newSelector*[T](): Selector[T] {.
|
||||
raises: [Defect, OSError].} =
|
||||
raises: [OSError].} =
|
||||
let res = Selector.new(T)
|
||||
if res.isErr(): raiseOSError(res.error())
|
||||
res.get()
|
||||
|
||||
proc close*[T](s: Selector[T]) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = s.close2()
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc newSelectEvent*(): SelectEvent {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = SelectEvent.new()
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
res.get()
|
||||
|
||||
proc trigger*(event: SelectEvent) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = event.trigger2()
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc close*(event: SelectEvent) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = event.close2()
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc registerHandle*[T](s: Selector[T], fd: cint | SocketHandle,
|
||||
events: set[Event], data: T) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = registerHandle2(s, fd, events, data)
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc updateHandle*[T](s: Selector[T], fd: cint | SocketHandle,
|
||||
events: set[Event]) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = updateHandle2(s, fd, events)
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc unregister*[T](s: Selector[T], fd: cint | SocketHandle) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = unregister2(s, fd)
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc unregister*[T](s: Selector[T], event: SelectEvent) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = unregister2(s, event)
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc registerTimer*[T](s: Selector[T], timeout: int, oneshot: bool,
|
||||
data: T): cint {.
|
||||
discardable, raises: [Defect, IOSelectorsException].} =
|
||||
discardable, raises: [IOSelectorsException].} =
|
||||
let res = registerTimer2(s, timeout, oneshot, data)
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
res.get()
|
||||
|
||||
proc registerEvent*[T](s: Selector[T], event: SelectEvent,
|
||||
data: T) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = registerEvent2(s, event, data)
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc selectInto*[T](s: Selector[T], timeout: int,
|
||||
readyKeys: var openArray[ReadyKey]): int {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = selectInto2(s, timeout, readyKeys)
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
res.get()
|
||||
|
@ -8,7 +8,8 @@
|
||||
#
|
||||
# This module implements BSD kqueue().
|
||||
|
||||
{.push raises: [Defect].}
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[kqueue, deques, tables]
|
||||
import stew/base10
|
||||
|
||||
@ -606,85 +607,85 @@ proc select2*[T](s: Selector[T],
|
||||
ok(res)
|
||||
|
||||
proc newSelector*[T](): owned(Selector[T]) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = Selector.new(T)
|
||||
if res.isErr():
|
||||
raiseIOSelectorsError(res.error())
|
||||
res.get()
|
||||
|
||||
proc newSelectEvent*(): SelectEvent {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = SelectEvent.new()
|
||||
if res.isErr():
|
||||
raiseIOSelectorsError(res.error())
|
||||
res.get()
|
||||
|
||||
proc trigger*(ev: SelectEvent) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = ev.trigger2()
|
||||
if res.isErr():
|
||||
raiseIOSelectorsError(res.error())
|
||||
|
||||
proc close*(ev: SelectEvent) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = ev.close2()
|
||||
if res.isErr():
|
||||
raiseIOSelectorsError(res.error())
|
||||
|
||||
proc registerHandle*[T](s: Selector[T], fd: cint | SocketHandle,
|
||||
events: set[Event], data: T) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = registerHandle2(s, cint(fd), events, data)
|
||||
if res.isErr():
|
||||
raiseIOSelectorsError(res.error())
|
||||
|
||||
proc updateHandle*[T](s: Selector[T], fd: cint | SocketHandle,
|
||||
events: set[Event]) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = updateHandle2(s, cint(fd), events)
|
||||
if res.isErr():
|
||||
raiseIOSelectorsError(res.error())
|
||||
|
||||
proc registerEvent*[T](s: Selector[T], ev: SelectEvent, data: T) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = registerEvent2(s, ev, data)
|
||||
if res.isErr():
|
||||
raiseIOSelectorsError(res.error())
|
||||
|
||||
proc registerVnode*[T](s: Selector[T], fd: cint, events: set[Event], data: T) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = registerVnode2(s, fd, events, data)
|
||||
if res.isErr():
|
||||
raiseIOSelectorsError(res.error())
|
||||
|
||||
proc unregister*[T](s: Selector[T], event: SelectEvent) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = unregister2(s, event)
|
||||
if res.isErr():
|
||||
raiseIOSelectorsError(res.error())
|
||||
|
||||
proc unregister*[T](s: Selector[T], fd: cint|SocketHandle) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = unregister2(s, fd)
|
||||
if res.isErr():
|
||||
raiseIOSelectorsError(res.error())
|
||||
|
||||
proc selectInto*[T](s: Selector[T], timeout: int,
|
||||
results: var openArray[ReadyKey]): int {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = selectInto2(s, timeout, results)
|
||||
if res.isErr():
|
||||
raiseIOSelectorsError(res.error())
|
||||
res.get()
|
||||
|
||||
proc select*[T](s: Selector[T], timeout: int): seq[ReadyKey] {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = select2(s, timeout)
|
||||
if res.isErr():
|
||||
raiseIOSelectorsError(res.error())
|
||||
res.get()
|
||||
|
||||
proc close*[T](s: Selector[T]) {.raises: [Defect, IOSelectorsException].} =
|
||||
proc close*[T](s: Selector[T]) {.raises: [IOSelectorsException].} =
|
||||
let res = s.close2()
|
||||
if res.isErr():
|
||||
raiseIOSelectorsError(res.error())
|
||||
|
@ -11,10 +11,7 @@
|
||||
import std/tables
|
||||
import stew/base10
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
type
|
||||
SelectorImpl[T] = object
|
||||
@ -250,63 +247,63 @@ proc select2*[T](s: Selector[T], timeout: int): SelectResult[seq[ReadyKey]] =
|
||||
ok(res)
|
||||
|
||||
proc newSelector*[T](): Selector[T] {.
|
||||
raises: [Defect, OSError].} =
|
||||
raises: [OSError].} =
|
||||
let res = Selector.new(T)
|
||||
if res.isErr(): raiseOSError(res.error)
|
||||
res.get()
|
||||
|
||||
proc close*[T](s: Selector[T]) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = s.close2()
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc newSelectEvent*(): SelectEvent {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = SelectEvent.new()
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
res.get()
|
||||
|
||||
proc trigger*(event: SelectEvent) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = event.trigger2()
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc close*(event: SelectEvent) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = event.close2()
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc registerHandle*[T](s: Selector[T], fd: cint | SocketHandle,
|
||||
events: set[Event], data: T) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = registerHandle2(s, cint(fd), events, data)
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc updateHandle*[T](s: Selector[T], fd: cint | SocketHandle,
|
||||
events: set[Event]) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = updateHandle2(s, cint(fd), events)
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc unregister*[T](s: Selector[T], fd: cint | SocketHandle) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = unregister2(s, cint(fd))
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc unregister*[T](s: Selector[T], event: SelectEvent) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = unregister2(s, event)
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc registerEvent*[T](s: Selector[T], event: SelectEvent,
|
||||
data: T) {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = registerEvent2(s, event, data)
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
|
||||
proc selectInto*[T](s: Selector[T], timeout: int,
|
||||
readyKeys: var openArray[ReadyKey]): int {.
|
||||
raises: [Defect, IOSelectorsException].} =
|
||||
raises: [IOSelectorsException].} =
|
||||
let res = selectInto2(s, timeout, readyKeys)
|
||||
if res.isErr(): raiseIOSelectorsError(res.error())
|
||||
res.get()
|
||||
|
@ -308,7 +308,7 @@ when defined(windows):
|
||||
stdcall, gcsafe, raises: [].}
|
||||
|
||||
PHANDLER_ROUTINE* = proc (dwCtrlType: DWORD): WINBOOL {.
|
||||
stdcall, gcsafe, raises: [Defect].}
|
||||
stdcall, gcsafe, raises: [].}
|
||||
|
||||
OSVERSIONINFO* {.final, pure.} = object
|
||||
dwOSVersionInfoSize*: DWORD
|
||||
|
@ -11,10 +11,7 @@ import osdefs, oserrno
|
||||
|
||||
export results
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
when defined(windows) or defined(nimdoc):
|
||||
import stew/base10
|
||||
|
@ -6,7 +6,7 @@
|
||||
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
||||
# MIT license (LICENSE-MIT)
|
||||
|
||||
{.push raises: [Defect].}
|
||||
{.push raises: [].}
|
||||
|
||||
import ../chronos
|
||||
import timer
|
||||
|
@ -9,10 +9,7 @@
|
||||
|
||||
## This module provides cross-platform wrapper for ``sendfile()`` syscall.
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
when defined(nimdoc):
|
||||
proc sendfile*(outfd, infd: int, offset: int, count: var int): int =
|
||||
|
@ -6,10 +6,9 @@
|
||||
# Licensed under either of
|
||||
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
||||
# MIT license (LICENSE-MIT)
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
import stew/base10
|
||||
|
||||
type
|
||||
|
@ -7,10 +7,7 @@
|
||||
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
||||
# MIT license (LICENSE-MIT)
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
import ../asyncloop, ../asyncsync
|
||||
import ../transports/common, ../transports/stream
|
||||
@ -67,10 +64,10 @@ type
|
||||
Closed ## Stream was closed
|
||||
|
||||
StreamReaderLoop* = proc (stream: AsyncStreamReader): Future[void] {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
## Main read loop for read streams.
|
||||
StreamWriterLoop* = proc (stream: AsyncStreamWriter): Future[void] {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
## Main write loop for write streams.
|
||||
|
||||
AsyncStreamReader* = ref object of RootRef
|
||||
@ -219,15 +216,15 @@ proc newAsyncStreamUseClosedError*(): ref AsyncStreamUseClosedError {.
|
||||
newException(AsyncStreamUseClosedError, "Stream is already closed")
|
||||
|
||||
proc raiseAsyncStreamUseClosedError*() {.
|
||||
noinline, noreturn, raises: [Defect, AsyncStreamUseClosedError].} =
|
||||
noinline, noreturn, raises: [AsyncStreamUseClosedError].} =
|
||||
raise newAsyncStreamUseClosedError()
|
||||
|
||||
proc raiseAsyncStreamLimitError*() {.
|
||||
noinline, noreturn, raises: [Defect, AsyncStreamLimitError].} =
|
||||
noinline, noreturn, raises: [AsyncStreamLimitError].} =
|
||||
raise newAsyncStreamLimitError()
|
||||
|
||||
proc raiseAsyncStreamIncompleteError*() {.
|
||||
noinline, noreturn, raises: [Defect, AsyncStreamIncompleteError].} =
|
||||
noinline, noreturn, raises: [AsyncStreamIncompleteError].} =
|
||||
raise newAsyncStreamIncompleteError()
|
||||
|
||||
proc raiseEmptyMessageDefect*() {.noinline, noreturn.} =
|
||||
@ -235,7 +232,7 @@ proc raiseEmptyMessageDefect*() {.noinline, noreturn.} =
|
||||
"Could not write empty message")
|
||||
|
||||
proc raiseAsyncStreamWriteEOFError*() {.
|
||||
noinline, noreturn, raises: [Defect, AsyncStreamWriteEOFError].} =
|
||||
noinline, noreturn, raises: [AsyncStreamWriteEOFError].} =
|
||||
raise newException(AsyncStreamWriteEOFError,
|
||||
"Stream finished or remote side dropped connection")
|
||||
|
||||
@ -336,9 +333,9 @@ template checkStreamFinished*(t: untyped) =
|
||||
if t.atEof(): raiseAsyncStreamWriteEOFError()
|
||||
|
||||
proc setupAsyncStreamReaderTracker(): AsyncStreamTracker {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
proc setupAsyncStreamWriterTracker(): AsyncStreamTracker {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
|
||||
proc getAsyncStreamReaderTracker(): AsyncStreamTracker {.inline.} =
|
||||
var res = cast[AsyncStreamTracker](getTracker(AsyncStreamReaderTrackerName))
|
||||
@ -974,7 +971,7 @@ proc close*(rw: AsyncStreamRW) =
|
||||
if not(rw.closed()):
|
||||
rw.state = AsyncStreamState.Closing
|
||||
|
||||
proc continuation(udata: pointer) {.raises: [Defect].} =
|
||||
proc continuation(udata: pointer) {.raises: [].} =
|
||||
if not isNil(rw.udata):
|
||||
GC_unref(cast[ref int](rw.udata))
|
||||
if not(rw.future.finished()):
|
||||
|
@ -27,10 +27,7 @@ import "."/osdefs
|
||||
|
||||
const asyncTimer* {.strdefine.} = "mono"
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
when defined(windows):
|
||||
when asyncTimer == "system":
|
||||
|
@ -7,10 +7,7 @@
|
||||
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
||||
# MIT license (LICENSE-MIT)
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[strutils]
|
||||
import stew/[base10, byteutils]
|
||||
@ -209,7 +206,7 @@ proc toHex*(address: TransportAddress): string =
|
||||
"None"
|
||||
|
||||
proc initTAddress*(address: string): TransportAddress {.
|
||||
raises: [Defect, TransportAddressError].} =
|
||||
raises: [TransportAddressError].} =
|
||||
## Parses string representation of ``address``. ``address`` can be IPv4, IPv6
|
||||
## or Unix domain address.
|
||||
##
|
||||
@ -259,7 +256,7 @@ proc initTAddress*(address: string): TransportAddress {.
|
||||
TransportAddress(family: AddressFamily.Unix)
|
||||
|
||||
proc initTAddress*(address: string, port: Port): TransportAddress {.
|
||||
raises: [Defect, TransportAddressError].} =
|
||||
raises: [TransportAddressError].} =
|
||||
## Initialize ``TransportAddress`` with IP (IPv4 or IPv6) address ``address``
|
||||
## and port number ``port``.
|
||||
let ipaddr =
|
||||
@ -277,7 +274,7 @@ proc initTAddress*(address: string, port: Port): TransportAddress {.
|
||||
address_v6: ipaddr.address_v6, port: port)
|
||||
|
||||
proc initTAddress*(address: string, port: int): TransportAddress {.
|
||||
raises: [Defect, TransportAddressError].} =
|
||||
raises: [TransportAddressError].} =
|
||||
## Initialize ``TransportAddress`` with IP (IPv4 or IPv6) address ``address``
|
||||
## and port number ``port``.
|
||||
if port < 0 or port > 65535:
|
||||
@ -298,7 +295,7 @@ proc initTAddress*(address: IpAddress, port: Port): TransportAddress =
|
||||
proc getAddrInfo(address: string, port: Port, domain: Domain,
|
||||
sockType: SockType = SockType.SOCK_STREAM,
|
||||
protocol: Protocol = Protocol.IPPROTO_TCP): ptr AddrInfo {.
|
||||
raises: [Defect, TransportAddressError].} =
|
||||
raises: [TransportAddressError].} =
|
||||
## We have this one copy of ``getAddrInfo()`` because of AI_V4MAPPED in
|
||||
## ``net.nim:getAddrInfo()``, which is not cross-platform.
|
||||
var hints: AddrInfo
|
||||
@ -380,7 +377,7 @@ proc toSAddr*(address: TransportAddress, sa: var Sockaddr_storage,
|
||||
discard
|
||||
|
||||
proc address*(ta: TransportAddress): IpAddress {.
|
||||
raises: [Defect, ValueError].} =
|
||||
raises: [ValueError].} =
|
||||
## Converts ``TransportAddress`` to ``net.IpAddress`` object.
|
||||
##
|
||||
## Note its impossible to convert ``TransportAddress`` of ``Unix`` family,
|
||||
@ -393,7 +390,7 @@ proc address*(ta: TransportAddress): IpAddress {.
|
||||
else:
|
||||
raise newException(ValueError, "IpAddress supports only IPv4/IPv6!")
|
||||
|
||||
proc host*(ta: TransportAddress): string {.raises: [Defect].} =
|
||||
proc host*(ta: TransportAddress): string {.raises: [].} =
|
||||
## Returns ``host`` of TransportAddress ``ta``.
|
||||
##
|
||||
## For IPv4 and IPv6 addresses it will return IP address as string, or empty
|
||||
@ -410,7 +407,7 @@ proc host*(ta: TransportAddress): string {.raises: [Defect].} =
|
||||
|
||||
proc resolveTAddress*(address: string, port: Port,
|
||||
domain: Domain): seq[TransportAddress] {.
|
||||
raises: [Defect, TransportAddressError].} =
|
||||
raises: [TransportAddressError].} =
|
||||
var res: seq[TransportAddress]
|
||||
let aiList = getAddrInfo(address, port, domain)
|
||||
var it = aiList
|
||||
@ -426,7 +423,7 @@ proc resolveTAddress*(address: string, port: Port,
|
||||
res
|
||||
|
||||
proc resolveTAddress*(address: string, domain: Domain): seq[TransportAddress] {.
|
||||
raises: [Defect, TransportAddressError].} =
|
||||
raises: [TransportAddressError].} =
|
||||
let parts =
|
||||
block:
|
||||
let res = address.rsplit(":", maxsplit = 1)
|
||||
@ -448,7 +445,7 @@ proc resolveTAddress*(address: string, domain: Domain): seq[TransportAddress] {.
|
||||
resolveTAddress(hostname, Port(port), domain)
|
||||
|
||||
proc resolveTAddress*(address: string): seq[TransportAddress] {.
|
||||
raises: [Defect, TransportAddressError].} =
|
||||
raises: [TransportAddressError].} =
|
||||
## Resolve string representation of ``address``.
|
||||
##
|
||||
## Supported formats are:
|
||||
@ -461,7 +458,7 @@ proc resolveTAddress*(address: string): seq[TransportAddress] {.
|
||||
resolveTAddress(address, Domain.AF_UNSPEC)
|
||||
|
||||
proc resolveTAddress*(address: string, port: Port): seq[TransportAddress] {.
|
||||
raises: [Defect, TransportAddressError].} =
|
||||
raises: [TransportAddressError].} =
|
||||
## Resolve string representation of ``address``.
|
||||
##
|
||||
## Supported formats are:
|
||||
@ -475,7 +472,7 @@ proc resolveTAddress*(address: string, port: Port): seq[TransportAddress] {.
|
||||
|
||||
proc resolveTAddress*(address: string,
|
||||
family: AddressFamily): seq[TransportAddress] {.
|
||||
raises: [Defect, TransportAddressError].} =
|
||||
raises: [TransportAddressError].} =
|
||||
## Resolve string representation of ``address``.
|
||||
##
|
||||
## Supported formats are:
|
||||
@ -495,7 +492,7 @@ proc resolveTAddress*(address: string,
|
||||
|
||||
proc resolveTAddress*(address: string, port: Port,
|
||||
family: AddressFamily): seq[TransportAddress] {.
|
||||
raises: [Defect, TransportAddressError].} =
|
||||
raises: [TransportAddressError].} =
|
||||
## Resolve string representation of ``address``.
|
||||
##
|
||||
## ``address`` could be dot IPv4/IPv6 address or hostname.
|
||||
@ -512,7 +509,7 @@ proc resolveTAddress*(address: string, port: Port,
|
||||
|
||||
proc resolveTAddress*(address: string,
|
||||
family: IpAddressFamily): seq[TransportAddress] {.
|
||||
deprecated, raises: [Defect, TransportAddressError].} =
|
||||
deprecated, raises: [TransportAddressError].} =
|
||||
case family
|
||||
of IpAddressFamily.IPv4:
|
||||
resolveTAddress(address, AddressFamily.IPv4)
|
||||
@ -521,7 +518,7 @@ proc resolveTAddress*(address: string,
|
||||
|
||||
proc resolveTAddress*(address: string, port: Port,
|
||||
family: IpAddressFamily): seq[TransportAddress] {.
|
||||
deprecated, raises: [Defect, TransportAddressError].} =
|
||||
deprecated, raises: [TransportAddressError].} =
|
||||
case family
|
||||
of IpAddressFamily.IPv4:
|
||||
resolveTAddress(address, port, AddressFamily.IPv4)
|
||||
@ -586,7 +583,7 @@ template getTransportOsError*(err: cint): ref TransportOsError =
|
||||
getTransportOsError(OSErrorCode(err))
|
||||
|
||||
proc raiseTransportOsError*(err: OSErrorCode) {.
|
||||
raises: [Defect, TransportOsError].} =
|
||||
raises: [TransportOsError].} =
|
||||
## Raises transport specific OS error.
|
||||
raise getTransportOsError(err)
|
||||
|
||||
|
@ -7,10 +7,7 @@
|
||||
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
||||
# MIT license (LICENSE-MIT)
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
import std/deques
|
||||
when not(defined(windows)): import ".."/selectors2
|
||||
@ -30,7 +27,7 @@ type
|
||||
|
||||
DatagramCallback* = proc(transp: DatagramTransport,
|
||||
remote: TransportAddress): Future[void] {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
|
||||
DatagramTransport* = ref object of RootRef
|
||||
fd*: AsyncFD # File descriptor
|
||||
@ -64,7 +61,7 @@ const
|
||||
DgramTransportTrackerName* = "datagram.transport"
|
||||
|
||||
proc remoteAddress*(transp: DatagramTransport): TransportAddress {.
|
||||
raises: [Defect, TransportOsError].} =
|
||||
raises: [TransportOsError].} =
|
||||
## Returns ``transp`` remote socket address.
|
||||
if transp.remote.family == AddressFamily.None:
|
||||
var saddr: Sockaddr_storage
|
||||
@ -76,7 +73,7 @@ proc remoteAddress*(transp: DatagramTransport): TransportAddress {.
|
||||
transp.remote
|
||||
|
||||
proc localAddress*(transp: DatagramTransport): TransportAddress {.
|
||||
raises: [Defect, TransportOsError].} =
|
||||
raises: [TransportOsError].} =
|
||||
## Returns ``transp`` local socket address.
|
||||
if transp.local.family == AddressFamily.None:
|
||||
var saddr: Sockaddr_storage
|
||||
@ -92,7 +89,7 @@ template setReadError(t, e: untyped) =
|
||||
(t).error = getTransportOsError(e)
|
||||
|
||||
proc setupDgramTransportTracker(): DgramTransportTracker {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
|
||||
proc getDgramTransportTracker(): DgramTransportTracker {.inline.} =
|
||||
var res = cast[DgramTransportTracker](getTracker(DgramTransportTrackerName))
|
||||
@ -288,7 +285,7 @@ when defined(windows):
|
||||
child: DatagramTransport,
|
||||
bufferSize: int,
|
||||
ttl: int): DatagramTransport {.
|
||||
raises: [Defect, TransportOsError].} =
|
||||
raises: [TransportOsError].} =
|
||||
var localSock: AsyncFD
|
||||
doAssert(remote.family == local.family)
|
||||
doAssert(not isNil(cbproc))
|
||||
@ -406,7 +403,7 @@ when defined(windows):
|
||||
else:
|
||||
# Linux/BSD/MacOS part
|
||||
|
||||
proc readDatagramLoop(udata: pointer) {.raises: Defect.}=
|
||||
proc readDatagramLoop(udata: pointer) {.raises: [].}=
|
||||
var raddr: TransportAddress
|
||||
doAssert(not isNil(udata))
|
||||
let transp = cast[DatagramTransport](udata)
|
||||
@ -498,7 +495,7 @@ else:
|
||||
child: DatagramTransport,
|
||||
bufferSize: int,
|
||||
ttl: int): DatagramTransport {.
|
||||
raises: [Defect, TransportOsError].} =
|
||||
raises: [TransportOsError].} =
|
||||
var localSock: AsyncFD
|
||||
doAssert(remote.family == local.family)
|
||||
doAssert(not isNil(cbproc))
|
||||
@ -603,7 +600,7 @@ else:
|
||||
|
||||
proc close*(transp: DatagramTransport) =
|
||||
## Closes and frees resources of transport ``transp``.
|
||||
proc continuation(udata: pointer) {.raises: Defect.} =
|
||||
proc continuation(udata: pointer) {.raises: [].} =
|
||||
if not(transp.future.finished()):
|
||||
# Stop tracking transport
|
||||
untrackDgram(transp)
|
||||
@ -636,7 +633,7 @@ proc newDatagramTransport*(cbproc: DatagramCallback,
|
||||
bufSize: int = DefaultDatagramBufferSize,
|
||||
ttl: int = 0
|
||||
): DatagramTransport {.
|
||||
raises: [Defect, TransportOsError].} =
|
||||
raises: [TransportOsError].} =
|
||||
## Create new UDP datagram transport (IPv4).
|
||||
##
|
||||
## ``cbproc`` - callback which will be called, when new datagram received.
|
||||
@ -662,7 +659,7 @@ proc newDatagramTransport*[T](cbproc: DatagramCallback,
|
||||
bufSize: int = DefaultDatagramBufferSize,
|
||||
ttl: int = 0
|
||||
): DatagramTransport {.
|
||||
raises: [Defect, TransportOsError].} =
|
||||
raises: [TransportOsError].} =
|
||||
var fflags = flags + {GCUserData}
|
||||
GC_ref(udata)
|
||||
newDatagramTransportCommon(cbproc, remote, local, sock, fflags,
|
||||
@ -678,7 +675,7 @@ proc newDatagramTransport6*(cbproc: DatagramCallback,
|
||||
bufSize: int = DefaultDatagramBufferSize,
|
||||
ttl: int = 0
|
||||
): DatagramTransport {.
|
||||
raises: [Defect, TransportOsError].} =
|
||||
raises: [TransportOsError].} =
|
||||
## Create new UDP datagram transport (IPv6).
|
||||
##
|
||||
## ``cbproc`` - callback which will be called, when new datagram received.
|
||||
@ -704,7 +701,7 @@ proc newDatagramTransport6*[T](cbproc: DatagramCallback,
|
||||
bufSize: int = DefaultDatagramBufferSize,
|
||||
ttl: int = 0
|
||||
): DatagramTransport {.
|
||||
raises: [Defect, TransportOsError].} =
|
||||
raises: [TransportOsError].} =
|
||||
var fflags = flags + {GCUserData}
|
||||
GC_ref(udata)
|
||||
newDatagramTransportCommon(cbproc, remote, local, sock, fflags,
|
||||
@ -865,7 +862,7 @@ proc sendTo*[T](transp: DatagramTransport, remote: TransportAddress,
|
||||
return retFuture
|
||||
|
||||
proc peekMessage*(transp: DatagramTransport, msg: var seq[byte],
|
||||
msglen: var int) {.raises: [Defect, CatchableError].} =
|
||||
msglen: var int) {.raises: [CatchableError].} =
|
||||
## Get access to internal message buffer and length of incoming datagram.
|
||||
if ReadError in transp.state:
|
||||
transp.state.excl(ReadError)
|
||||
@ -877,7 +874,7 @@ proc peekMessage*(transp: DatagramTransport, msg: var seq[byte],
|
||||
msglen = transp.buflen
|
||||
|
||||
proc getMessage*(transp: DatagramTransport): seq[byte] {.
|
||||
raises: [Defect, CatchableError].} =
|
||||
raises: [CatchableError].} =
|
||||
## Copy data from internal message buffer and return result.
|
||||
var default: seq[byte]
|
||||
if ReadError in transp.state:
|
||||
|
@ -9,10 +9,7 @@
|
||||
|
||||
## This module implements various IP network utility procedures.
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
import std/strutils
|
||||
import stew/endians2
|
||||
@ -352,7 +349,7 @@ proc `$`*(mask: IpMask, include0x = false): string =
|
||||
else:
|
||||
"Unknown mask family: " & $mask.family
|
||||
|
||||
proc ip*(mask: IpMask): string {.raises: [Defect, ValueError].} =
|
||||
proc ip*(mask: IpMask): string {.raises: [ValueError].} =
|
||||
## Returns IP address text representation of IP mask ``mask``.
|
||||
case mask.family
|
||||
of AddressFamily.IPv4:
|
||||
@ -387,7 +384,7 @@ proc init*(t: typedesc[IpNet], host: TransportAddress,
|
||||
IpNet(mask: mask, host: host)
|
||||
|
||||
proc init*(t: typedesc[IpNet], network: string): IpNet {.
|
||||
raises: [Defect, TransportAddressError].} =
|
||||
raises: [TransportAddressError].} =
|
||||
## Initialize IP Network from string representation in format
|
||||
## <address>/<prefix length> or <address>/<netmask address>.
|
||||
var parts = network.rsplit("/", maxsplit = 1)
|
||||
|
@ -10,10 +10,7 @@
|
||||
## This module implements cross-platform network interfaces list.
|
||||
## Currently supported OSes are Windows, Linux, MacOS, BSD(not tested).
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
import std/algorithm
|
||||
import ".."/osdefs
|
||||
@ -753,7 +750,7 @@ when defined(linux):
|
||||
if endflag:
|
||||
break
|
||||
|
||||
proc getInterfaces*(): seq[NetworkInterface] {.raises: [Defect].} =
|
||||
proc getInterfaces*(): seq[NetworkInterface] {.raises: [].} =
|
||||
## Return list of available interfaces.
|
||||
var res: seq[NetworkInterface]
|
||||
var pid = osdefs.getpid()
|
||||
@ -767,7 +764,7 @@ when defined(linux):
|
||||
discard osdefs.close(sock)
|
||||
res
|
||||
|
||||
proc getBestRoute*(address: TransportAddress): Route {.raises: [Defect].} =
|
||||
proc getBestRoute*(address: TransportAddress): Route {.raises: [].} =
|
||||
## Return best applicable OS route, which will be used for connecting to
|
||||
## address ``address``.
|
||||
var pid = osdefs.getpid()
|
||||
@ -795,7 +792,7 @@ elif defined(macosx) or defined(macos) or defined(bsd):
|
||||
else:
|
||||
StatusDown
|
||||
|
||||
proc getInterfaces*(): seq[NetworkInterface] {.raises: [Defect].} =
|
||||
proc getInterfaces*(): seq[NetworkInterface] {.raises: [].} =
|
||||
## Return list of available interfaces.
|
||||
var res: seq[NetworkInterface]
|
||||
var ifap: ptr IfAddrs
|
||||
@ -867,7 +864,7 @@ elif defined(macosx) or defined(macos) or defined(bsd):
|
||||
else:
|
||||
0
|
||||
|
||||
proc getBestRoute*(address: TransportAddress): Route {.raises: [Defect].} =
|
||||
proc getBestRoute*(address: TransportAddress): Route {.raises: [].} =
|
||||
## Return best applicable OS route, which will be used for connecting to
|
||||
## address ``address``.
|
||||
var sock: cint
|
||||
@ -1034,7 +1031,7 @@ elif defined(windows):
|
||||
res.net = IpNet.init(res.host, prefixLength)
|
||||
res
|
||||
|
||||
proc getInterfaces*(): seq[NetworkInterface] {.raises: [Defect].} =
|
||||
proc getInterfaces*(): seq[NetworkInterface] {.raises: [].} =
|
||||
## Return list of network interfaces.
|
||||
var res = newSeq[NetworkInterface]()
|
||||
var size = WorkBufferSize
|
||||
@ -1086,7 +1083,7 @@ elif defined(windows):
|
||||
sort(res, cmp)
|
||||
res
|
||||
|
||||
proc getBestRoute*(address: TransportAddress): Route {.raises: [Defect].} =
|
||||
proc getBestRoute*(address: TransportAddress): Route {.raises: [].} =
|
||||
## Return best applicable OS route, which will be used for connecting to
|
||||
## address ``address``.
|
||||
var res = Route()
|
||||
|
@ -7,10 +7,7 @@
|
||||
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
||||
# MIT license (LICENSE-MIT)
|
||||
|
||||
when (NimMajor, NimMinor) < (1, 4):
|
||||
{.push raises: [Defect].}
|
||||
else:
|
||||
{.push raises: [].}
|
||||
{.push raises: [].}
|
||||
|
||||
import std/deques
|
||||
import ".."/[asyncloop, handles, osdefs, osutils, oserrno]
|
||||
@ -68,7 +65,7 @@ type
|
||||
|
||||
ReadMessagePredicate* = proc (data: openArray[byte]): tuple[consumed: int,
|
||||
done: bool] {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
|
||||
const
|
||||
StreamTransportTrackerName* = "stream.transport"
|
||||
@ -125,14 +122,14 @@ else:
|
||||
type
|
||||
StreamCallback* = proc(server: StreamServer,
|
||||
client: StreamTransport): Future[void] {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
## New remote client connection callback
|
||||
## ``server`` - StreamServer object.
|
||||
## ``client`` - accepted client transport.
|
||||
|
||||
TransportInitCallback* = proc(server: StreamServer,
|
||||
fd: AsyncFD): StreamTransport {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
## Custom transport initialization procedure, which can allocate inherited
|
||||
## StreamTransport object.
|
||||
|
||||
@ -144,7 +141,7 @@ type
|
||||
# transport for new client
|
||||
|
||||
proc remoteAddress*(transp: StreamTransport): TransportAddress {.
|
||||
raises: [Defect, TransportError].} =
|
||||
raises: [TransportError].} =
|
||||
## Returns ``transp`` remote socket address.
|
||||
if transp.kind != TransportKind.Socket:
|
||||
raise newException(TransportError, "Socket required!")
|
||||
@ -158,7 +155,7 @@ proc remoteAddress*(transp: StreamTransport): TransportAddress {.
|
||||
transp.remote
|
||||
|
||||
proc localAddress*(transp: StreamTransport): TransportAddress {.
|
||||
raises: [Defect, TransportError].} =
|
||||
raises: [TransportError].} =
|
||||
## Returns ``transp`` local socket address.
|
||||
if transp.kind != TransportKind.Socket:
|
||||
raise newException(TransportError, "Socket required!")
|
||||
@ -205,9 +202,9 @@ template shiftVectorFile(v: var StreamVector, o: untyped) =
|
||||
(v).offset += uint(o)
|
||||
|
||||
proc setupStreamTransportTracker(): StreamTransportTracker {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
proc setupStreamServerTracker(): StreamServerTracker {.
|
||||
gcsafe, raises: [Defect].}
|
||||
gcsafe, raises: [].}
|
||||
|
||||
proc getStreamTransportTracker(): StreamTransportTracker {.inline.} =
|
||||
var res = cast[StreamTransportTracker](getTracker(StreamTransportTrackerName))
|
||||
@ -824,9 +821,9 @@ when defined(windows):
|
||||
# For some reason Nim compiler does not detect `pipeHandle` usage in
|
||||
# pipeContinuation() procedure, so we marking it as {.used.} here.
|
||||
var pipeHandle {.used.} = INVALID_HANDLE_VALUE
|
||||
var pipeContinuation: proc (udata: pointer) {.gcsafe, raises: [Defect].}
|
||||
var pipeContinuation: proc (udata: pointer) {.gcsafe, raises: [].}
|
||||
|
||||
pipeContinuation = proc (udata: pointer) {.gcsafe, raises: [Defect].} =
|
||||
pipeContinuation = proc (udata: pointer) {.gcsafe, raises: [].} =
|
||||
# Continue only if `retFuture` is not cancelled.
|
||||
if not(retFuture.finished()):
|
||||
let
|
||||
@ -1830,12 +1827,12 @@ proc stop2*(server: StreamServer): Result[void, OSErrorCode] =
|
||||
server.status = ServerStatus.Stopped
|
||||
ok()
|
||||
|
||||
proc start*(server: StreamServer) {.raises: [Defect, TransportOsError].} =
|
||||
proc start*(server: StreamServer) {.raises: [TransportOsError].} =
|
||||
## Starts ``server``.
|
||||
let res = start2(server)
|
||||
if res.isErr(): raiseTransportOsError(res.error())
|
||||
|
||||
proc stop*(server: StreamServer) {.raises: [Defect, TransportOsError].} =
|
||||
proc stop*(server: StreamServer) {.raises: [TransportOsError].} =
|
||||
## Stops ``server``.
|
||||
let res = stop2(server)
|
||||
if res.isErr(): raiseTransportOsError(res.error())
|
||||
@ -1907,7 +1904,7 @@ proc createStreamServer*(host: TransportAddress,
|
||||
child: StreamServer = nil,
|
||||
init: TransportInitCallback = nil,
|
||||
udata: pointer = nil): StreamServer {.
|
||||
raises: [Defect, TransportOsError].} =
|
||||
raises: [TransportOsError].} =
|
||||
## Create new TCP stream server.
|
||||
##
|
||||
## ``host`` - address to which server will be bound.
|
||||
@ -2115,7 +2112,7 @@ proc createStreamServer*(host: TransportAddress,
|
||||
child: StreamServer = nil,
|
||||
init: TransportInitCallback = nil,
|
||||
udata: pointer = nil): StreamServer {.
|
||||
raises: [Defect, CatchableError].} =
|
||||
raises: [CatchableError].} =
|
||||
createStreamServer(host, nil, flags, sock, backlog, bufferSize,
|
||||
child, init, cast[pointer](udata))
|
||||
|
||||
@ -2128,7 +2125,7 @@ proc createStreamServer*[T](host: TransportAddress,
|
||||
bufferSize: int = DefaultStreamBufferSize,
|
||||
child: StreamServer = nil,
|
||||
init: TransportInitCallback = nil): StreamServer {.
|
||||
raises: [Defect, CatchableError].} =
|
||||
raises: [CatchableError].} =
|
||||
var fflags = flags + {GCUserData}
|
||||
GC_ref(udata)
|
||||
createStreamServer(host, cbproc, fflags, sock, backlog, bufferSize,
|
||||
@ -2142,7 +2139,7 @@ proc createStreamServer*[T](host: TransportAddress,
|
||||
bufferSize: int = DefaultStreamBufferSize,
|
||||
child: StreamServer = nil,
|
||||
init: TransportInitCallback = nil): StreamServer {.
|
||||
raises: [Defect, CatchableError].} =
|
||||
raises: [CatchableError].} =
|
||||
var fflags = flags + {GCUserData}
|
||||
GC_ref(udata)
|
||||
createStreamServer(host, nil, fflags, sock, backlog, bufferSize,
|
||||
@ -2681,7 +2678,7 @@ proc fromPipe2*(fd: AsyncFD, child: StreamTransport = nil,
|
||||
|
||||
proc fromPipe*(fd: AsyncFD, child: StreamTransport = nil,
|
||||
bufferSize = DefaultStreamBufferSize): StreamTransport {.
|
||||
raises: [Defect, TransportOsError].} =
|
||||
raises: [TransportOsError].} =
|
||||
## Create new transport object using pipe's file descriptor.
|
||||
##
|
||||
## ``bufferSize`` is size of internal buffer for transport.
|
||||
|
@ -119,7 +119,7 @@ suite "Asynchronous issues test suite":
|
||||
check bytesSent == messageSize
|
||||
var rfut {.used.} = inpTransp.readExactly(addr buffer[0], messageSize)
|
||||
|
||||
proc waiterProc(udata: pointer) {.raises: [Defect], gcsafe.} =
|
||||
proc waiterProc(udata: pointer) {.raises: [], gcsafe.} =
|
||||
try:
|
||||
waitFor(sleepAsync(0.milliseconds))
|
||||
except CatchableError:
|
||||
|
@ -46,8 +46,8 @@ suite "callSoon() tests suite":
|
||||
await sleepAsync(100.milliseconds)
|
||||
timeoutsTest1 += 1
|
||||
|
||||
var callbackproc: proc(udata: pointer) {.gcsafe, raises: [Defect].}
|
||||
callbackproc = proc (udata: pointer) {.gcsafe, raises: [Defect].} =
|
||||
var callbackproc: proc(udata: pointer) {.gcsafe, raises: [].}
|
||||
callbackproc = proc (udata: pointer) {.gcsafe, raises: [].} =
|
||||
timeoutsTest2 += 1
|
||||
{.gcsafe.}:
|
||||
callSoon(callbackproc)
|
||||
|
Loading…
x
Reference in New Issue
Block a user