diff options
Diffstat (limited to 'src/io')
-rw-r--r-- | src/io/bufreader.nim | 2 | ||||
-rw-r--r-- | src/io/bufstream.nim | 12 | ||||
-rw-r--r-- | src/io/posixstream.nim | 8 | ||||
-rw-r--r-- | src/io/promise.nim | 32 | ||||
-rw-r--r-- | src/io/readablestream.nim | 2 | ||||
-rw-r--r-- | src/io/socketstream.nim | 12 | ||||
-rw-r--r-- | src/io/tempfile.nim | 2 | ||||
-rw-r--r-- | src/io/urlfilter.nim | 6 |
8 files changed, 39 insertions, 37 deletions
diff --git a/src/io/bufreader.nim b/src/io/bufreader.nim index eca6b585..6de269ac 100644 --- a/src/io/bufreader.nim +++ b/src/io/bufreader.nim @@ -118,7 +118,7 @@ proc sread*(reader: var BufferedReader; s: var seq) = for x in s.mitems: reader.sread(x) -proc sread*[U; V](reader: var BufferedReader, t: var Table[U, V]) = +proc sread*[U; V](reader: var BufferedReader; t: var Table[U, V]) = var len: int reader.sread(len) for i in 0..<len: diff --git a/src/io/bufstream.nim b/src/io/bufstream.nim index 118b81e5..62a0df3e 100644 --- a/src/io/bufstream.nim +++ b/src/io/bufstream.nim @@ -8,10 +8,10 @@ type registered: bool writeBuffer: string -method recvData*(s: BufStream, buffer: pointer, len: int): int = +method recvData*(s: BufStream; buffer: pointer; len: int): int = s.source.recvData(buffer, len) -method sendData*(s: BufStream, buffer: pointer, len: int): int = +method sendData*(s: BufStream; buffer: pointer; len: int): int = s.source.setBlocking(false) block nobuf: var n: int @@ -45,9 +45,5 @@ proc flushWrite*(s: BufStream): bool = s.writeBuffer = s.writeBuffer.substr(n) return false -proc newBufStream*(ps: PosixStream, registerFun: proc(fd: int)): BufStream = - return BufStream( - source: ps, - blocking: ps.blocking, - registerFun: registerFun - ) +proc newBufStream*(ps: PosixStream; registerFun: proc(fd: int)): BufStream = + return BufStream(source: ps, blocking: ps.blocking, registerFun: registerFun) diff --git a/src/io/posixstream.nim b/src/io/posixstream.nim index bfd925f2..dd2101fa 100644 --- a/src/io/posixstream.nim +++ b/src/io/posixstream.nim @@ -32,7 +32,7 @@ proc raisePosixIOError*() = else: raise newException(IOError, $strerror(errno)) -method recvData*(s: PosixStream, buffer: pointer, len: int): int = +method recvData*(s: PosixStream; buffer: pointer; len: int): int = let n = read(s.fd, buffer, len) if n < 0: raisePosixIOError() @@ -46,13 +46,13 @@ proc sreadChar*(s: PosixStream): char = let n = read(s.fd, addr result, 1) assert n == 1 -method sendData*(s: PosixStream, buffer: pointer, len: int): int = +method sendData*(s: PosixStream; buffer: pointer; len: int): int = let n = write(s.fd, buffer, len) if n < 0: raisePosixIOError() return n -method setBlocking*(s: PosixStream, blocking: bool) {.base.} = +method setBlocking*(s: PosixStream; blocking: bool) {.base.} = s.blocking = blocking let ofl = fcntl(s.fd, F_GETFL, 0) if blocking: @@ -70,7 +70,7 @@ method sclose*(s: PosixStream) = proc newPosixStream*(fd: FileHandle): PosixStream = return PosixStream(fd: fd, blocking: true) -proc newPosixStream*(path: string, flags, mode: cint): PosixStream = +proc newPosixStream*(path: string; flags, mode: cint): PosixStream = let fd = open(cstring(path), flags, mode) if fd == -1: return nil diff --git a/src/io/promise.nim b/src/io/promise.nim index c7942190..63ae256f 100644 --- a/src/io/promise.nim +++ b/src/io/promise.nim @@ -16,7 +16,7 @@ type res: T get: GetValueProc[T] - GetValueProc[T] = (proc(opaque: pointer, res: var T)) + GetValueProc[T] = (proc(opaque: pointer; res: var T)) PromiseMap* = object tab: Table[int, EmptyPromise] @@ -30,12 +30,13 @@ proc newPromiseMap*(opaque: pointer): PromiseMap = opaque: opaque ) -proc addPromise*[T](map: var PromiseMap, id: int, get: GetValueProc[T]): Promise[T] = +proc addPromise*[T](map: var PromiseMap; id: int; get: GetValueProc[T]): + Promise[T] = let promise = Promise[T](get: get, opaque: map.opaque) map.tab[id] = promise return promise -proc addEmptyPromise*(map: var PromiseMap, id: int): EmptyPromise = +proc addEmptyPromise*(map: var PromiseMap; id: int): EmptyPromise = let promise = EmptyPromise(opaque: map.opaque) map.tab[id] = promise return promise @@ -52,7 +53,7 @@ proc resolve*(promise: EmptyPromise) = break promise.next = nil -proc resolve*[T](promise: Promise[T], res: T) = +proc resolve*[T](promise: Promise[T]; res: T) = if promise.cb != nil: if promise.get != nil: promise.get(promise.opaque, promise.res) @@ -60,7 +61,7 @@ proc resolve*[T](promise: Promise[T], res: T) = promise.res = res promise.resolve() -proc resolve*(map: var PromiseMap, promiseid: int) = +proc resolve*(map: var PromiseMap; promiseid: int) = var promise: EmptyPromise if map.tab.pop(promiseid, promise): promise.resolve() @@ -73,14 +74,14 @@ proc newResolvedPromise*(): EmptyPromise = func empty*(map: PromiseMap): bool = map.tab.len == 0 -proc then*(promise: EmptyPromise, cb: (proc())): EmptyPromise {.discardable.} = +proc then*(promise: EmptyPromise; cb: (proc())): EmptyPromise {.discardable.} = promise.cb = cb promise.next = EmptyPromise() if promise.state == PROMISE_FULFILLED: promise.resolve() return promise.next -proc then*(promise: EmptyPromise, cb: (proc(): EmptyPromise)): EmptyPromise +proc then*(promise: EmptyPromise; cb: (proc(): EmptyPromise)): EmptyPromise {.discardable.} = let next = EmptyPromise() promise.then(proc() = @@ -92,14 +93,16 @@ proc then*(promise: EmptyPromise, cb: (proc(): EmptyPromise)): EmptyPromise next.resolve()) return next -proc then*[T](promise: Promise[T], cb: (proc(x: T))): EmptyPromise {.discardable.} = +proc then*[T](promise: Promise[T]; cb: (proc(x: T))): EmptyPromise + {.discardable.} = return promise.then(proc() = if promise.get != nil: promise.get(promise.opaque, promise.res) promise.get = nil cb(promise.res)) -proc then*[T](promise: EmptyPromise, cb: (proc(): Promise[T])): Promise[T] {.discardable.} = +proc then*[T](promise: EmptyPromise; cb: (proc(): Promise[T])): Promise[T] + {.discardable.} = let next = Promise[T]() promise.then(proc() = var p2 = cb() @@ -111,7 +114,8 @@ proc then*[T](promise: EmptyPromise, cb: (proc(): Promise[T])): Promise[T] {.dis next.resolve()) return next -proc then*[T](promise: Promise[T], cb: (proc(x: T): EmptyPromise)): EmptyPromise {.discardable.} = +proc then*[T](promise: Promise[T]; cb: (proc(x: T): EmptyPromise)): EmptyPromise + {.discardable.} = let next = EmptyPromise() promise.then(proc(x: T) = let p2 = cb(x) @@ -122,14 +126,16 @@ proc then*[T](promise: Promise[T], cb: (proc(x: T): EmptyPromise)): EmptyPromise next.resolve()) return next -proc then*[T, U](promise: Promise[T], cb: (proc(x: T): U)): Promise[U] {.discardable.} = +proc then*[T, U](promise: Promise[T]; cb: (proc(x: T): U)): Promise[U] + {.discardable.} = let next = Promise[U]() promise.then(proc(x: T) = next.res = cb(x) next.resolve()) return next -proc then*[T, U](promise: Promise[T], cb: (proc(x: T): Promise[U])): Promise[U] {.discardable.} = +proc then*[T, U](promise: Promise[T]; cb: (proc(x: T): Promise[U])): Promise[U] + {.discardable.} = let next = Promise[U]() promise.then(proc(x: T) = let p2 = cb(x) @@ -141,7 +147,7 @@ proc then*[T, U](promise: Promise[T], cb: (proc(x: T): Promise[U])): Promise[U] next.resolve()) return next -proc then*[T, U](promise: Promise[T], cb: (proc(x: T): Opt[Promise[U]])): +proc then*[T, U](promise: Promise[T]; cb: (proc(x: T): Opt[Promise[U]])): Promise[Opt[U]] {.discardable.} = let next = Promise[Opt[U]]() promise.then(proc(x: T) = diff --git a/src/io/readablestream.nim b/src/io/readablestream.nim index 16a650e2..8269f1dc 100644 --- a/src/io/readablestream.nim +++ b/src/io/readablestream.nim @@ -26,7 +26,7 @@ type ReadableStream* = object underlyingSource: UnderlyingSource -proc newReadableStream(underlyingSource = none(UnderlyingSource), +proc newReadableStream(underlyingSource = none(UnderlyingSource); strategy = none(QueuingStrategySize)): ReadableStream = let this = ReadableStream() discard diff --git a/src/io/socketstream.nim b/src/io/socketstream.nim index 32aff96d..13fcd664 100644 --- a/src/io/socketstream.nim +++ b/src/io/socketstream.nim @@ -9,7 +9,7 @@ import io/serversocket type SocketStream* = ref object of PosixStream source*: Socket -method recvData*(s: SocketStream, buffer: pointer, len: int): int = +method recvData*(s: SocketStream; buffer: pointer; len: int): int = let n = s.source.recv(buffer, len) if n < 0: raisePosixIOError() @@ -19,7 +19,7 @@ method recvData*(s: SocketStream, buffer: pointer, len: int): int = s.isend = true return n -method sendData*(s: SocketStream, buffer: pointer, len: int): int = +method sendData*(s: SocketStream; buffer: pointer; len: int): int = let n = s.source.send(buffer, len) if n < 0: raisePosixIOError() @@ -28,7 +28,7 @@ method sendData*(s: SocketStream, buffer: pointer, len: int): int = {.compile: "sendfd.c".} proc sendfd(sock, fd: cint): int {.importc.} -proc sendFileHandle*(s: SocketStream, fd: FileHandle) = +proc sendFileHandle*(s: SocketStream; fd: FileHandle) = assert not s.source.hasDataBuffered let n = sendfd(s.fd, cint(fd)) if n < 0: @@ -36,7 +36,7 @@ proc sendFileHandle*(s: SocketStream, fd: FileHandle) = assert n == 1 # we send a single nul byte as buf {.compile: "recvfd.c".} -proc recvfd(sock: cint, fdout: ptr cint): int {.importc.} +proc recvfd(sock: cint; fdout: ptr cint): int {.importc.} proc recvFileHandle*(s: SocketStream): FileHandle = assert not s.source.hasDataBuffered @@ -46,7 +46,7 @@ proc recvFileHandle*(s: SocketStream): FileHandle = raisePosixIOError() return FileHandle(fd) -method setBlocking*(s: SocketStream, blocking: bool) = +method setBlocking*(s: SocketStream; blocking: bool) = s.blocking = blocking s.source.getFd().setBlocking(blocking) @@ -96,7 +96,7 @@ proc connectSocketStream*(socketDir: string; baseFd, pid: int; except OSError: return nil -proc acceptSocketStream*(ssock: ServerSocket, blocking = true): SocketStream = +proc acceptSocketStream*(ssock: ServerSocket; blocking = true): SocketStream = var sock: Socket ssock.sock.accept(sock, inheritable = true) if not blocking: diff --git a/src/io/tempfile.nim b/src/io/tempfile.nim index 5968270b..44c63297 100644 --- a/src/io/tempfile.nim +++ b/src/io/tempfile.nim @@ -1,7 +1,7 @@ import std/os var tmpf_seq: int -proc getTempFile*(tmpdir: string, ext = ""): string = +proc getTempFile*(tmpdir: string; ext = ""): string = if not dirExists(tmpdir): createDir(tmpdir) var tmpf = tmpdir / "chatmp" & $getCurrentProcessId() & "-" & $tmpf_seq diff --git a/src/io/urlfilter.nim b/src/io/urlfilter.nim index 457d79f8..6bbb247c 100644 --- a/src/io/urlfilter.nim +++ b/src/io/urlfilter.nim @@ -11,8 +11,8 @@ type URLFilter* = object allowhosts: seq[Regex] default: bool -proc newURLFilter*(scheme = none(string), allowschemes: seq[string] = @[], - allowhost = none(string), allowhosts: seq[Regex] = @[], +proc newURLFilter*(scheme = none(string); allowschemes: seq[string] = @[]; + allowhost = none(string); allowhosts: seq[Regex] = @[]; default = false): URLFilter = doAssert scheme.isSome or allowschemes.len == 0, "allowschemes without scheme is not supported" @@ -28,7 +28,7 @@ proc newURLFilter*(scheme = none(string), allowschemes: seq[string] = @[], # If scheme/s are given, only URLs with the same scheme are matched. # Then, allowhost and allowhosts are checked; if none of these match the host, # the function returns the value of `default'. -proc match*(filter: URLFilter, url: URL): bool = +proc match*(filter: URLFilter; url: URL): bool = block check_scheme: if filter.scheme.isSome and filter.scheme.get != url.scheme: for scheme in filter.allowschemes: |