Fix unreachable code places. (#459)

* Fix unreachable code.

* Use implicit returns instead.
This commit is contained in:
Eugene Kabanov 2023-10-30 15:27:25 +02:00 committed by GitHub
parent 12dc36cfee
commit 8375770fe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 24 deletions

View File

@ -1617,6 +1617,8 @@ elif defined(linux):
# RTA_PRIORITY* = 6'u16
RTA_PREFSRC* = 7'u16
# RTA_METRICS* = 8'u16
RTM_NEWLINK* = 16'u16
RTM_NEWROUTE* = 24'u16
RTM_F_LOOKUP_TABLE* = 0x1000

View File

@ -157,17 +157,15 @@ proc tlsWriteRec(engine: ptr SslEngineContext,
doAssert(length != 0 and not isNil(buf))
await writer.wsource.write(buf, int(length))
sslEngineSendrecAck(engine[], length)
return TLSResult.Success
TLSResult.Success
except AsyncStreamError as exc:
writer.state = AsyncStreamState.Error
writer.error = exc
return TLSResult.Error
TLSResult.Error
except CancelledError:
if writer.state == AsyncStreamState.Running:
writer.state = AsyncStreamState.Stopped
return TLSResult.Stopped
return TLSResult.Error
TLSResult.Stopped
proc tlsWriteApp(engine: ptr SslEngineContext,
writer: TLSStreamWriter): Future[TLSResult] {.async.} =
@ -182,7 +180,6 @@ proc tlsWriteApp(engine: ptr SslEngineContext,
# (and discarded).
writer.state = AsyncStreamState.Finished
return TLSResult.WriteEof
let toWrite = min(int(length), item.size)
copyOut(buf, item, toWrite)
if int(length) >= item.size:
@ -190,7 +187,6 @@ proc tlsWriteApp(engine: ptr SslEngineContext,
sslEngineSendappAck(engine[], uint(item.size))
sslEngineFlush(engine[], 0)
item.future.complete()
return TLSResult.Success
else:
# BearSSL is not ready to accept whole item, so we will send
# only part of item and adjust offset.
@ -198,17 +194,15 @@ proc tlsWriteApp(engine: ptr SslEngineContext,
item.size = item.size - int(length)
writer.queue.addFirstNoWait(item)
sslEngineSendappAck(engine[], length)
return TLSResult.Success
TLSResult.Success
else:
sslEngineClose(engine[])
item.future.complete()
return TLSResult.Success
TLSResult.Success
except CancelledError:
if writer.state == AsyncStreamState.Running:
writer.state = AsyncStreamState.Stopped
return TLSResult.Stopped
return TLSResult.Error
TLSResult.Stopped
proc tlsReadRec(engine: ptr SslEngineContext,
reader: TLSStreamReader): Future[TLSResult] {.async.} =
@ -219,19 +213,17 @@ proc tlsReadRec(engine: ptr SslEngineContext,
sslEngineRecvrecAck(engine[], uint(res))
if res == 0:
sslEngineClose(engine[])
return TLSResult.ReadEof
TLSResult.ReadEof
else:
return TLSResult.Success
TLSResult.Success
except AsyncStreamError as exc:
reader.state = AsyncStreamState.Error
reader.error = exc
return TLSResult.Error
TLSResult.Error
except CancelledError:
if reader.state == AsyncStreamState.Running:
reader.state = AsyncStreamState.Stopped
return TLSResult.Stopped
return TLSResult.Error
TLSResult.Stopped
proc tlsReadApp(engine: ptr SslEngineContext,
reader: TLSStreamReader): Future[TLSResult] {.async.} =
@ -240,13 +232,11 @@ proc tlsReadApp(engine: ptr SslEngineContext,
var buf = sslEngineRecvappBuf(engine[], length)
await upload(addr reader.buffer, buf, int(length))
sslEngineRecvappAck(engine[], length)
return TLSResult.Success
TLSResult.Success
except CancelledError:
if reader.state == AsyncStreamState.Running:
reader.state = AsyncStreamState.Stopped
return TLSResult.Stopped
return TLSResult.Error
TLSResult.Stopped
template readAndReset(fut: untyped) =
if fut.finished():

View File

@ -677,10 +677,10 @@ when defined(linux):
var msg = cast[ptr NlMsgHeader](addr data[0])
var endflag = false
while NLMSG_OK(msg, length):
if msg.nlmsg_type == NLMSG_ERROR:
if msg.nlmsg_type in [uint16(NLMSG_DONE), uint16(NLMSG_ERROR)]:
endflag = true
break
else:
elif msg.nlmsg_type == RTM_NEWROUTE:
res = processRoute(msg)
endflag = true
break