Fix a few more warnings
This commit is contained in:
parent
5668ab3a49
commit
e686ca2523
16 changed files with 131 additions and 129 deletions
|
|
@ -200,7 +200,7 @@ template schedule =
|
|||
if minIdx >= 0:
|
||||
p.actors[minIdx].i.send(t)
|
||||
else:
|
||||
raise newException(EDeadThread, "cannot send message; thread died")
|
||||
raise newException(DeadThreadError, "cannot send message; thread died")
|
||||
|
||||
proc spawn*[TIn, TOut](p: var TActorPool[TIn, TOut], input: TIn,
|
||||
action: proc (input: TIn): TOut {.thread.}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ type
|
|||
offset: int64
|
||||
|
||||
when defined(windows):
|
||||
proc getDesiredAccess(mode: TFileMode): int32 =
|
||||
proc getDesiredAccess(mode: FileMode): int32 =
|
||||
case mode
|
||||
of fmRead:
|
||||
result = GENERIC_READ
|
||||
|
|
@ -44,7 +44,7 @@ when defined(windows):
|
|||
of fmReadWrite, fmReadWriteExisting:
|
||||
result = GENERIC_READ or GENERIC_WRITE
|
||||
|
||||
proc getCreationDisposition(mode: TFileMode, filename: string): int32 =
|
||||
proc getCreationDisposition(mode: FileMode, filename: string): int32 =
|
||||
case mode
|
||||
of fmRead, fmReadWriteExisting:
|
||||
OPEN_EXISTING
|
||||
|
|
@ -54,7 +54,7 @@ when defined(windows):
|
|||
else:
|
||||
CREATE_NEW
|
||||
else:
|
||||
proc getPosixFlags(mode: TFileMode): cint =
|
||||
proc getPosixFlags(mode: FileMode): cint =
|
||||
case mode
|
||||
of fmRead:
|
||||
result = O_RDONLY
|
||||
|
|
@ -74,7 +74,7 @@ proc getFileSize(f: AsyncFile): int64 =
|
|||
var high: DWord
|
||||
let low = getFileSize(f.fd.THandle, addr high)
|
||||
if low == INVALID_FILE_SIZE:
|
||||
raiseOSError()
|
||||
raiseOSError(osLastError())
|
||||
return (high shl 32) or low
|
||||
|
||||
proc openAsync*(filename: string, mode = fmRead): AsyncFile =
|
||||
|
|
@ -95,7 +95,7 @@ proc openAsync*(filename: string, mode = fmRead): AsyncFile =
|
|||
nil, creationDisposition, flags, 0).TAsyncFd
|
||||
|
||||
if result.fd.THandle == INVALID_HANDLE_VALUE:
|
||||
raiseOSError()
|
||||
raiseOSError(osLastError())
|
||||
|
||||
register(result.fd)
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ proc openAsync*(filename: string, mode = fmRead): AsyncFile =
|
|||
let perm = S_IRUSR or S_IWUSR or S_IRGRP or S_IWGRP or S_IROTH
|
||||
result.fd = open(filename, flags, perm).TAsyncFD
|
||||
if result.fd.cint == -1:
|
||||
raiseOSError()
|
||||
raiseOSError(osLastError())
|
||||
|
||||
register(result.fd)
|
||||
|
||||
|
|
@ -185,7 +185,7 @@ proc read*(f: AsyncFile, size: int): Future[string] =
|
|||
if res < 0:
|
||||
let lastError = osLastError()
|
||||
if lastError.int32 != EAGAIN:
|
||||
retFuture.fail(newException(EOS, osErrorMsg(lastError)))
|
||||
retFuture.fail(newException(OSError, osErrorMsg(lastError)))
|
||||
else:
|
||||
result = false # We still want this callback to be called.
|
||||
elif res == 0:
|
||||
|
|
@ -227,7 +227,7 @@ proc setFilePos*(f: AsyncFile, pos: int64) =
|
|||
when not defined(windows):
|
||||
let ret = lseek(f.fd.cint, pos, SEEK_SET)
|
||||
if ret == -1:
|
||||
raiseOSError()
|
||||
raiseOSError(osLastError())
|
||||
|
||||
proc readAll*(f: AsyncFile): Future[string] {.async.} =
|
||||
## Reads all data from the specified file.
|
||||
|
|
@ -299,7 +299,7 @@ proc write*(f: AsyncFile, data: string): Future[void] =
|
|||
if res < 0:
|
||||
let lastError = osLastError()
|
||||
if lastError.int32 != EAGAIN:
|
||||
retFuture.fail(newException(EOS, osErrorMsg(lastError)))
|
||||
retFuture.fail(newException(OSError, osErrorMsg(lastError)))
|
||||
else:
|
||||
result = false # We still want this callback to be called.
|
||||
else:
|
||||
|
|
@ -318,8 +318,8 @@ proc close*(f: AsyncFile) =
|
|||
## Closes the file specified.
|
||||
when defined(windows):
|
||||
if not closeHandle(f.fd.THandle).bool:
|
||||
raiseOSError()
|
||||
raiseOSError(osLastError())
|
||||
else:
|
||||
if close(f.fd.cint) == -1:
|
||||
raiseOSError()
|
||||
raiseOSError(osLastError())
|
||||
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ proc createDir*(ftp: AsyncFtpClient, dir: string, recursive = false){.async.} =
|
|||
assertReply reply, "257"
|
||||
|
||||
proc chmod*(ftp: AsyncFtpClient, path: string,
|
||||
permissions: set[TFilePermission]) {.async.} =
|
||||
permissions: set[FilePermission]) {.async.} =
|
||||
## Changes permission of ``path`` to ``permissions``.
|
||||
var userOctal = 0
|
||||
var groupOctal = 0
|
||||
|
|
@ -188,7 +188,7 @@ proc retrText*(ftp: AsyncFtpClient, file: string): Future[string] {.async.} =
|
|||
|
||||
result = await ftp.getLines()
|
||||
|
||||
proc getFile(ftp: AsyncFtpClient, file: TFile, total: BiggestInt,
|
||||
proc getFile(ftp: AsyncFtpClient, file: File, total: BiggestInt,
|
||||
onProgressChanged: ProgressChangedProc) {.async.} =
|
||||
assert ftp.dsockConnected
|
||||
var progress = 0
|
||||
|
|
@ -240,7 +240,7 @@ proc retrFile*(ftp: AsyncFtpClient, file, dest: string,
|
|||
|
||||
await getFile(ftp, destFile, fileSize, onProgressChanged)
|
||||
|
||||
proc doUpload(ftp: AsyncFtpClient, file: TFile,
|
||||
proc doUpload(ftp: AsyncFtpClient, file: File,
|
||||
onProgressChanged: ProgressChangedProc) {.async.} =
|
||||
assert ftp.dsockConnected
|
||||
|
||||
|
|
|
|||
|
|
@ -675,7 +675,7 @@ when isMainModule:
|
|||
echo(data)
|
||||
echo("Finished reading! " & $no)
|
||||
|
||||
proc testAccept(s: AsyncSocket, disp: PDispatcher, no: int) =
|
||||
proc testAccept(s: AsyncSocket, disp: Dispatcher, no: int) =
|
||||
echo("Accepting client! " & $no)
|
||||
var client: AsyncSocket
|
||||
new(client)
|
||||
|
|
@ -691,7 +691,7 @@ when isMainModule:
|
|||
var d = newDispatcher()
|
||||
|
||||
var s = asyncSocket()
|
||||
s.connect("amber.tenthbit.net", TPort(6667))
|
||||
s.connect("amber.tenthbit.net", Port(6667))
|
||||
s.handleConnect =
|
||||
proc (s: AsyncSocket) =
|
||||
testConnect(s, 1)
|
||||
|
|
@ -704,7 +704,7 @@ when isMainModule:
|
|||
server.handleAccept =
|
||||
proc (s: AsyncSocket) =
|
||||
testAccept(s, d, 78)
|
||||
server.bindAddr(TPort(5555))
|
||||
server.bindAddr(Port(5555))
|
||||
server.listen()
|
||||
d.register(server)
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ proc openDefaultBrowser*(url: string) =
|
|||
for b in getEnv("BROWSER").string.split(PathSep):
|
||||
try:
|
||||
# we use ``startProcess`` here because we don't want to block!
|
||||
discard startProcess(command=b, args=[url], options={poUseShell})
|
||||
discard startProcess(command=b, args=[url], options={poUsePath})
|
||||
return
|
||||
except OSError:
|
||||
discard
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ type
|
|||
FSMonitorObj = object of RootObj
|
||||
fd: cint
|
||||
handleEvent: proc (m: FSMonitor, ev: MonitorEvent) {.closure.}
|
||||
targets: TTable[cint, string]
|
||||
targets: Table[cint, string]
|
||||
|
||||
MonitorEventType* = enum ## Monitor event type
|
||||
MonitorAccess, ## File was accessed.
|
||||
|
|
@ -64,7 +64,7 @@ type
|
|||
const
|
||||
MaxEvents = 100
|
||||
|
||||
proc newMonitor*(): PFSMonitor =
|
||||
proc newMonitor*(): FSMonitor =
|
||||
## Creates a new file system monitor.
|
||||
new(result)
|
||||
result.targets = initTable[cint, string]()
|
||||
|
|
@ -72,7 +72,7 @@ proc newMonitor*(): PFSMonitor =
|
|||
if result.fd < 0:
|
||||
raiseOSError(osLastError())
|
||||
|
||||
proc add*(monitor: PFSMonitor, target: string,
|
||||
proc add*(monitor: FSMonitor, target: string,
|
||||
filters = {MonitorAll}): cint {.discardable.} =
|
||||
## Adds ``target`` which may be a directory or a file to the list of
|
||||
## watched paths of ``monitor``.
|
||||
|
|
@ -99,14 +99,14 @@ proc add*(monitor: PFSMonitor, target: string,
|
|||
raiseOSError(osLastError())
|
||||
monitor.targets.add(result, target)
|
||||
|
||||
proc del*(monitor: PFSMonitor, wd: cint) =
|
||||
proc del*(monitor: FSMonitor, wd: cint) =
|
||||
## Removes watched directory or file as specified by ``wd`` from ``monitor``.
|
||||
##
|
||||
## If ``wd`` is not a part of ``monitor`` an EOS error is raised.
|
||||
if inotifyRmWatch(monitor.fd, wd) < 0:
|
||||
raiseOSError(osLastError())
|
||||
|
||||
proc getEvent(m: PFSMonitor, fd: cint): seq[TMonitorEvent] =
|
||||
proc getEvent(m: FSMonitor, fd: cint): seq[MonitorEvent] =
|
||||
result = @[]
|
||||
let size = (sizeof(TINotifyEvent)+2000)*MaxEvents
|
||||
var buffer = newString(size)
|
||||
|
|
@ -118,7 +118,7 @@ proc getEvent(m: PFSMonitor, fd: cint): seq[TMonitorEvent] =
|
|||
var i = 0
|
||||
while i < le:
|
||||
var event = cast[ptr TINotifyEvent](addr(buffer[i]))
|
||||
var mev: TMonitorEvent
|
||||
var mev: MonitorEvent
|
||||
mev.wd = event.wd
|
||||
if event.len.int != 0:
|
||||
let cstr = event.name.addr.cstring
|
||||
|
|
@ -137,7 +137,7 @@ proc getEvent(m: PFSMonitor, fd: cint): seq[TMonitorEvent] =
|
|||
# Find the MovedFrom event.
|
||||
mev.oldPath = movedFrom[event.cookie.cint].old
|
||||
mev.newPath = "" # Set later
|
||||
# Delete it from the TTable
|
||||
# Delete it from the Table
|
||||
movedFrom.del(event.cookie.cint)
|
||||
elif (event.mask.int and IN_ACCESS) != 0: mev.kind = MonitorAccess
|
||||
elif (event.mask.int and IN_ATTRIB) != 0: mev.kind = MonitorAttrib
|
||||
|
|
@ -164,26 +164,26 @@ proc getEvent(m: PFSMonitor, fd: cint): seq[TMonitorEvent] =
|
|||
# If movedFrom events have not been matched with a moveTo. File has
|
||||
# been moved to an unwatched location, emit a MonitorDelete.
|
||||
for cookie, t in pairs(movedFrom):
|
||||
var mev: TMonitorEvent
|
||||
var mev: MonitorEvent
|
||||
mev.kind = MonitorDelete
|
||||
mev.wd = t.wd
|
||||
mev.name = t.old
|
||||
result.add(mev)
|
||||
|
||||
proc FSMonitorRead(h: PObject) =
|
||||
var events = PFSMonitor(h).getEvent(PFSMonitor(h).fd)
|
||||
#var newEv: TMonitorEvent
|
||||
proc FSMonitorRead(h: RootRef) =
|
||||
var events = FSMonitor(h).getEvent(FSMonitor(h).fd)
|
||||
#var newEv: MonitorEvent
|
||||
for ev in events:
|
||||
var target = PFSMonitor(h).targets[ev.wd]
|
||||
var target = FSMonitor(h).targets[ev.wd]
|
||||
var newEv = ev
|
||||
if newEv.kind == MonitorMoved:
|
||||
newEv.oldPath = target / newEv.oldPath
|
||||
newEv.newPath = target / newEv.name
|
||||
else:
|
||||
newEv.fullName = target / newEv.name
|
||||
PFSMonitor(h).handleEvent(PFSMonitor(h), newEv)
|
||||
FSMonitor(h).handleEvent(FSMonitor(h), newEv)
|
||||
|
||||
proc toDelegate(m: PFSMonitor): PDelegate =
|
||||
proc toDelegate(m: FSMonitor): Delegate =
|
||||
result = newDelegate()
|
||||
result.deleVal = m
|
||||
result.fd = (type(result.fd))(m.fd)
|
||||
|
|
@ -191,8 +191,8 @@ proc toDelegate(m: PFSMonitor): PDelegate =
|
|||
result.handleRead = FSMonitorRead
|
||||
result.open = true
|
||||
|
||||
proc register*(d: PDispatcher, monitor: PFSMonitor,
|
||||
handleEvent: proc (m: PFSMonitor, ev: TMonitorEvent) {.closure.}) =
|
||||
proc register*(d: Dispatcher, monitor: FSMonitor,
|
||||
handleEvent: proc (m: FSMonitor, ev: MonitorEvent) {.closure.}) =
|
||||
## Registers ``monitor`` with dispatcher ``d``.
|
||||
monitor.handleEvent = handleEvent
|
||||
var deleg = toDelegate(monitor)
|
||||
|
|
@ -204,7 +204,7 @@ when isMainModule:
|
|||
var monitor = newMonitor()
|
||||
echo monitor.add("/home/dom/inotifytests/")
|
||||
disp.register(monitor,
|
||||
proc (m: PFSMonitor, ev: TMonitorEvent) =
|
||||
proc (m: FSMonitor, ev: MonitorEvent) =
|
||||
echo("Got event: ", ev.kind)
|
||||
if ev.kind == MonitorMoved:
|
||||
echo("From ", ev.oldPath, " to ", ev.newPath)
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ type
|
|||
EInvalidReply: ReplyError, EFTP: FTPError
|
||||
].}
|
||||
|
||||
proc ftpClient*(address: string, port = TPort(21),
|
||||
proc ftpClient*(address: string, port = Port(21),
|
||||
user, pass = ""): FtpClient =
|
||||
## Create a ``FtpClient`` object.
|
||||
new(result)
|
||||
|
|
@ -120,10 +120,10 @@ proc ftpClient*(address: string, port = TPort(21),
|
|||
result.csock = socket()
|
||||
if result.csock == invalidSocket: raiseOSError(osLastError())
|
||||
|
||||
template blockingOperation(sock: TSocket, body: stmt) {.immediate.} =
|
||||
template blockingOperation(sock: Socket, body: stmt) {.immediate.} =
|
||||
body
|
||||
|
||||
template blockingOperation(sock: asyncio.PAsyncSocket, body: stmt) {.immediate.} =
|
||||
template blockingOperation(sock: asyncio.AsyncSocket, body: stmt) {.immediate.} =
|
||||
sock.setBlocking(true)
|
||||
body
|
||||
sock.setBlocking(false)
|
||||
|
|
@ -145,14 +145,14 @@ proc send*[T](ftp: FtpBase[T], m: string): TaintedString =
|
|||
|
||||
proc assertReply(received: TaintedString, expected: string) =
|
||||
if not received.string.startsWith(expected):
|
||||
raise newException(EInvalidReply,
|
||||
raise newException(ReplyError,
|
||||
"Expected reply '$1' got: $2" % [
|
||||
expected, received.string])
|
||||
|
||||
proc assertReply(received: TaintedString, expected: varargs[string]) =
|
||||
for i in items(expected):
|
||||
if received.string.startsWith(i): return
|
||||
raise newException(EInvalidReply,
|
||||
raise newException(ReplyError,
|
||||
"Expected reply '$1' got: $2" %
|
||||
[expected.join("' or '"), received.string])
|
||||
|
||||
|
|
@ -161,7 +161,7 @@ proc createJob[T](ftp: FtpBase[T],
|
|||
nimcall,gcsafe.},
|
||||
cmd: FTPJobType) =
|
||||
if ftp.jobInProgress:
|
||||
raise newException(EFTP, "Unable to do two jobs at once.")
|
||||
raise newException(FTPError, "Unable to do two jobs at once.")
|
||||
ftp.jobInProgress = true
|
||||
new(ftp.job)
|
||||
ftp.job.prc = prc
|
||||
|
|
@ -182,11 +182,11 @@ proc deleteJob[T](ftp: FtpBase[T]) =
|
|||
ftp.job.file.close()
|
||||
ftp.dsock.close()
|
||||
|
||||
proc handleTask(s: PAsyncSocket, ftp: PAsyncFTPClient) =
|
||||
proc handleTask(s: AsyncSocket, ftp: AsyncFTPClient) =
|
||||
if ftp.jobInProgress:
|
||||
if ftp.job.typ in {JRetr, JStore}:
|
||||
if epochTime() - ftp.job.lastProgressReport >= 1.0:
|
||||
var r: TFTPEvent
|
||||
var r: FTPEvent
|
||||
ftp.job.lastProgressReport = epochTime()
|
||||
r.typ = EvTransferProgress
|
||||
r.bytesTotal = ftp.job.total
|
||||
|
|
@ -195,22 +195,22 @@ proc handleTask(s: PAsyncSocket, ftp: PAsyncFTPClient) =
|
|||
r.filename = ftp.job.filename
|
||||
r.currentJob = ftp.job.typ
|
||||
ftp.job.oneSecond = 0
|
||||
ftp.handleEvent(PAsyncFTPClient(ftp), r)
|
||||
ftp.handleEvent(ftp, r)
|
||||
|
||||
proc handleWrite(s: PAsyncSocket, ftp: PAsyncFTPClient) =
|
||||
proc handleWrite(s: AsyncSocket, ftp: AsyncFTPClient) =
|
||||
if ftp.jobInProgress:
|
||||
if ftp.job.typ == JStore:
|
||||
assert (not ftp.job.prc(ftp, true))
|
||||
|
||||
proc handleConnect(s: PAsyncSocket, ftp: PAsyncFTPClient) =
|
||||
proc handleConnect(s: AsyncSocket, ftp: AsyncFTPClient) =
|
||||
ftp.dsockConnected = true
|
||||
assert(ftp.jobInProgress)
|
||||
if ftp.job.typ == JStore:
|
||||
s.setHandleWrite(proc (s: PAsyncSocket) = handleWrite(s, ftp))
|
||||
s.setHandleWrite(proc (s: AsyncSocket) = handleWrite(s, ftp))
|
||||
else:
|
||||
s.delHandleWrite()
|
||||
|
||||
proc handleRead(s: PAsyncSocket, ftp: PAsyncFTPClient) =
|
||||
proc handleRead(s: AsyncSocket, ftp: AsyncFTPClient) =
|
||||
assert ftp.jobInProgress
|
||||
assert ftp.job.typ != JStore
|
||||
# This can never return true, because it shouldn't check for code
|
||||
|
|
@ -219,19 +219,19 @@ proc handleRead(s: PAsyncSocket, ftp: PAsyncFTPClient) =
|
|||
|
||||
proc pasv[T](ftp: FtpBase[T]) =
|
||||
## Negotiate a data connection.
|
||||
when T is TSocket:
|
||||
when T is Socket:
|
||||
ftp.dsock = socket()
|
||||
if ftp.dsock == invalidSocket: raiseOSError(osLastError())
|
||||
elif T is PAsyncSocket:
|
||||
elif T is AsyncSocket:
|
||||
ftp.dsock = asyncSocket()
|
||||
ftp.dsock.handleRead =
|
||||
proc (s: PAsyncSocket) =
|
||||
proc (s: AsyncSocket) =
|
||||
handleRead(s, ftp)
|
||||
ftp.dsock.handleConnect =
|
||||
proc (s: PAsyncSocket) =
|
||||
proc (s: AsyncSocket) =
|
||||
handleConnect(s, ftp)
|
||||
ftp.dsock.handleTask =
|
||||
proc (s: PAsyncSocket) =
|
||||
proc (s: AsyncSocket) =
|
||||
handleTask(s, ftp)
|
||||
ftp.disp.register(ftp.dsock)
|
||||
else:
|
||||
|
|
@ -244,8 +244,8 @@ proc pasv[T](ftp: FtpBase[T]) =
|
|||
var ip = nums[0.. -3]
|
||||
var port = nums[-2.. -1]
|
||||
var properPort = port[0].parseInt()*256+port[1].parseInt()
|
||||
ftp.dsock.connect(ip.join("."), TPort(properPort.toU16))
|
||||
when T is PAsyncSocket:
|
||||
ftp.dsock.connect(ip.join("."), Port(properPort.toU16))
|
||||
when T is AsyncSocket:
|
||||
ftp.dsockConnected = false
|
||||
else:
|
||||
ftp.dsockConnected = true
|
||||
|
|
@ -255,10 +255,10 @@ proc normalizePathSep(path: string): string =
|
|||
|
||||
proc connect*[T](ftp: FtpBase[T]) =
|
||||
## Connect to the FTP server specified by ``ftp``.
|
||||
when T is PAsyncSocket:
|
||||
when T is AsyncSocket:
|
||||
blockingOperation(ftp.csock):
|
||||
ftp.csock.connect(ftp.address, ftp.port)
|
||||
elif T is TSocket:
|
||||
elif T is Socket:
|
||||
ftp.csock.connect(ftp.address, ftp.port)
|
||||
else:
|
||||
{.fatal: "Incorrect socket instantiation".}
|
||||
|
|
@ -292,13 +292,13 @@ proc getLines[T](ftp: FtpBase[T], async: bool = false): bool =
|
|||
## It doesn't if `async` is true, because it doesn't check for 226 then.
|
||||
if ftp.dsockConnected:
|
||||
var r = TaintedString""
|
||||
when T is PAsyncSocket:
|
||||
when T is AsyncSocket:
|
||||
if ftp.asyncDSock.readLine(r):
|
||||
if r.string == "":
|
||||
ftp.dsockConnected = false
|
||||
else:
|
||||
ftp.job.lines.add(r.string & "\n")
|
||||
elif T is TSocket:
|
||||
elif T is Socket:
|
||||
assert(not async)
|
||||
ftp.dsock.readLine(r)
|
||||
if r.string == "":
|
||||
|
|
@ -309,7 +309,7 @@ proc getLines[T](ftp: FtpBase[T], async: bool = false): bool =
|
|||
{.fatal: "Incorrect socket instantiation".}
|
||||
|
||||
if not async:
|
||||
var readSocks: seq[TSocket] = @[ftp.csock]
|
||||
var readSocks: seq[Socket] = @[ftp.csock]
|
||||
# This is only needed here. Asyncio gets this socket...
|
||||
blockingOperation(ftp.csock):
|
||||
if readSocks.select(1) != 0 and ftp.csock in readSocks:
|
||||
|
|
@ -372,7 +372,7 @@ proc createDir*[T](ftp: FtpBase[T], dir: string, recursive: bool = false) =
|
|||
assertReply reply, "257"
|
||||
|
||||
proc chmod*[T](ftp: FtpBase[T], path: string,
|
||||
permissions: set[TFilePermission]) =
|
||||
permissions: set[FilePermission]) =
|
||||
## Changes permission of ``path`` to ``permissions``.
|
||||
var userOctal = 0
|
||||
var groupOctal = 0
|
||||
|
|
@ -431,8 +431,8 @@ proc getFile[T](ftp: FtpBase[T], async = false): bool =
|
|||
var bytesRead = 0
|
||||
var returned = false
|
||||
if async:
|
||||
when T is TSocket:
|
||||
raise newException(EFTP, "FTPClient must be async.")
|
||||
when T is Socket:
|
||||
raise newException(FTPError, "FTPClient must be async.")
|
||||
else:
|
||||
bytesRead = ftp.dsock.recvAsync(r, BufferSize)
|
||||
returned = bytesRead != -1
|
||||
|
|
@ -447,9 +447,9 @@ proc getFile[T](ftp: FtpBase[T], async = false): bool =
|
|||
elif returned and r2 == "":
|
||||
ftp.dsockConnected = false
|
||||
|
||||
when T is TSocket:
|
||||
when T is Socket:
|
||||
if not async:
|
||||
var readSocks: seq[TSocket] = @[ftp.csock]
|
||||
var readSocks: seq[Socket] = @[ftp.csock]
|
||||
blockingOperation(ftp.csock):
|
||||
if readSocks.select(1) != 0 and ftp.csock in readSocks:
|
||||
assertReply ftp.expectReply(), "226"
|
||||
|
|
@ -467,10 +467,10 @@ proc retrFile*[T](ftp: FtpBase[T], file, dest: string, async = false) =
|
|||
var reply = ftp.send("RETR " & file.normalizePathSep)
|
||||
assertReply reply, ["125", "150"]
|
||||
if {'(', ')'} notin reply.string:
|
||||
raise newException(EInvalidReply, "Reply has no file size.")
|
||||
raise newException(ReplyError, "Reply has no file size.")
|
||||
var fileSize: BiggestInt
|
||||
if reply.string.captureBetween('(', ')').parseBiggestInt(fileSize) == 0:
|
||||
raise newException(EInvalidReply, "Reply has no file size.")
|
||||
raise newException(ReplyError, "Reply has no file size.")
|
||||
|
||||
ftp.job.total = fileSize
|
||||
ftp.job.lastProgressReport = epochTime()
|
||||
|
|
@ -545,10 +545,10 @@ proc close*[T](ftp: FtpBase[T]) =
|
|||
ftp.csock.close()
|
||||
ftp.dsock.close()
|
||||
|
||||
proc csockHandleRead(s: PAsyncSocket, ftp: PAsyncFTPClient) =
|
||||
proc csockHandleRead(s: AsyncSocket, ftp: AsyncFTPClient) =
|
||||
if ftp.jobInProgress:
|
||||
assertReply ftp.expectReply(), "226" # Make sure the transfer completed.
|
||||
var r: TFTPEvent
|
||||
var r: FTPEvent
|
||||
case ftp.job.typ
|
||||
of JRetrText:
|
||||
r.typ = EvLines
|
||||
|
|
@ -557,21 +557,21 @@ proc csockHandleRead(s: PAsyncSocket, ftp: PAsyncFTPClient) =
|
|||
r.typ = EvRetr
|
||||
r.filename = ftp.job.filename
|
||||
if ftp.job.progress != ftp.job.total:
|
||||
raise newException(EFTP, "Didn't download full file.")
|
||||
raise newException(FTPError, "Didn't download full file.")
|
||||
of JStore:
|
||||
r.typ = EvStore
|
||||
r.filename = ftp.job.filename
|
||||
if ftp.job.progress != ftp.job.total:
|
||||
raise newException(EFTP, "Didn't upload full file.")
|
||||
raise newException(FTPError, "Didn't upload full file.")
|
||||
ftp.deleteJob()
|
||||
|
||||
ftp.handleEvent(ftp, r)
|
||||
|
||||
proc asyncFTPClient*(address: string, port = TPort(21),
|
||||
proc asyncFTPClient*(address: string, port = Port(21),
|
||||
user, pass = "",
|
||||
handleEvent: proc (ftp: PAsyncFTPClient, ev: TFTPEvent) {.closure,gcsafe.} =
|
||||
(proc (ftp: PAsyncFTPClient, ev: TFTPEvent) = discard)): PAsyncFTPClient =
|
||||
## Create a ``PAsyncFTPClient`` object.
|
||||
handleEvent: proc (ftp: AsyncFTPClient, ev: FTPEvent) {.closure,gcsafe.} =
|
||||
(proc (ftp: AsyncFTPClient, ev: FTPEvent) = discard)): AsyncFTPClient =
|
||||
## Create a ``AsyncFTPClient`` object.
|
||||
##
|
||||
## Use this if you want to use asyncio's dispatcher.
|
||||
var dres: AsyncFtpClient
|
||||
|
|
@ -588,7 +588,7 @@ proc asyncFTPClient*(address: string, port = TPort(21),
|
|||
csockHandleRead(s, dres)
|
||||
result = dres
|
||||
|
||||
proc register*(d: PDispatcher, ftp: PAsyncFTPClient): PDelegate {.discardable.} =
|
||||
proc register*(d: Dispatcher, ftp: AsyncFTPClient): Delegate {.discardable.} =
|
||||
## Registers ``ftp`` with dispatcher ``d``.
|
||||
ftp.disp = d
|
||||
return ftp.disp.register(ftp.csock)
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ proc execProcesses*(cmds: openArray[string],
|
|||
for i in 0..m-1:
|
||||
if beforeRunEvent != nil:
|
||||
beforeRunEvent(i)
|
||||
q[i] = startCmd(cmds[i], options=options)
|
||||
q[i] = startProcess(cmds[i], options=options + {poEvalCommand})
|
||||
when defined(noBusyWaiting):
|
||||
var r = 0
|
||||
for i in m..high(cmds):
|
||||
|
|
@ -275,7 +275,7 @@ proc execProcesses*(cmds: openArray[string],
|
|||
if q[r] != nil: close(q[r])
|
||||
if beforeRunEvent != nil:
|
||||
beforeRunEvent(i)
|
||||
q[r] = startCmd(cmds[i], options=options)
|
||||
q[r] = startProcess(cmds[i], options=options + {poEvalCommand})
|
||||
r = (r + 1) mod n
|
||||
else:
|
||||
var i = m
|
||||
|
|
@ -288,7 +288,7 @@ proc execProcesses*(cmds: openArray[string],
|
|||
if q[r] != nil: close(q[r])
|
||||
if beforeRunEvent != nil:
|
||||
beforeRunEvent(i)
|
||||
q[r] = startCmd(cmds[i], options=options)
|
||||
q[r] = startProcess(cmds[i], options=options + {poEvalCommand})
|
||||
inc(i)
|
||||
if i > high(cmds): break
|
||||
for j in 0..m-1:
|
||||
|
|
@ -298,7 +298,7 @@ proc execProcesses*(cmds: openArray[string],
|
|||
for i in 0..high(cmds):
|
||||
if beforeRunEvent != nil:
|
||||
beforeRunEvent(i)
|
||||
var p = startCmd(cmds[i], options=options)
|
||||
var p = startProcess(cmds[i], options=options + {poEvalCommand})
|
||||
result = max(waitForExit(p), result)
|
||||
close(p)
|
||||
|
||||
|
|
@ -644,14 +644,14 @@ elif not defined(useNimRtl):
|
|||
var pid: TPid
|
||||
|
||||
var sysArgs = allocCStringArray(sysArgsRaw)
|
||||
finally: deallocCStringArray(sysArgs)
|
||||
defer: deallocCStringArray(sysArgs)
|
||||
|
||||
var sysEnv = if env == nil:
|
||||
envToCStringArray()
|
||||
else:
|
||||
envToCStringArray(env)
|
||||
|
||||
finally: deallocCStringArray(sysEnv)
|
||||
defer: deallocCStringArray(sysEnv)
|
||||
|
||||
var data: TStartProcessData
|
||||
data.sysCommand = sysCommand
|
||||
|
|
@ -748,7 +748,7 @@ elif not defined(useNimRtl):
|
|||
if pipe(data.pErrorPipe) != 0:
|
||||
raiseOSError(osLastError())
|
||||
|
||||
finally:
|
||||
defer:
|
||||
discard close(data.pErrorPipe[readIdx])
|
||||
|
||||
var pid: TPid
|
||||
|
|
@ -956,7 +956,7 @@ proc execCmdEx*(command: string, options: set[ProcessOption] = {
|
|||
exitCode: int] {.tags: [ExecIOEffect, ReadIOEffect], gcsafe.} =
|
||||
## a convenience proc that runs the `command`, grabs all its output and
|
||||
## exit code and returns both.
|
||||
var p = startCmd(command, options)
|
||||
var p = startProcess(command, options=options + {poEvalCommand})
|
||||
var outp = outputStream(p)
|
||||
result = (TaintedString"", -1)
|
||||
var line = newStringOfCap(120).TaintedString
|
||||
|
|
|
|||
|
|
@ -353,11 +353,11 @@ when isMainModule:
|
|||
|
||||
proc `%`(formatstr: string, a: openarray[string]): string =
|
||||
result = newStringOfCap(formatstr.len + a.len shl 4)
|
||||
addf(result, formatstr.TSubex, a)
|
||||
addf(result, formatstr.Subex, a)
|
||||
|
||||
proc `%`(formatstr: string, a: string): string =
|
||||
result = newStringOfCap(formatstr.len + a.len)
|
||||
addf(result, formatstr.TSubex, [a])
|
||||
addf(result, formatstr.Subex, [a])
|
||||
|
||||
|
||||
doAssert "$# $3 $# $#" % ["a", "b", "c"] == "a c b c"
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ type
|
|||
|
||||
{.deprecated: [TUrl: Url, TUri: Uri].}
|
||||
|
||||
{.push warning[deprecated]: off.}
|
||||
proc `$`*(url: Url): string {.deprecated.} =
|
||||
## **Deprecated since 0.9.6**: Use ``Uri`` instead.
|
||||
return string(url)
|
||||
|
|
@ -44,6 +45,7 @@ proc add*(url: var Url, a: Url) {.deprecated.} =
|
|||
##
|
||||
## **Deprecated since 0.9.6**: Use ``Uri`` instead.
|
||||
url = url / a
|
||||
{.pop.}
|
||||
|
||||
proc parseAuthority(authority: string, result: var Uri) =
|
||||
var i = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue