You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I haven't found a template for feature request, improvement or question, thus adding it as blank one.
Recently, there is NIOAsyncChannel was added to swift-nio. It is very convenient to use it with swift concurrency.
However, sometimes it is hard to dial with ByteBuffer without async interface, such as ByteBuffer.withUnsafeReadableBytes that accepts async closure.
I have the following use case:
letchannel=tryawaitClientBootstrap(group:Self.eventLoopGroup).connect(host: ipAddress, port: port){ channel in
channel.eventLoop.makeCompletedFuture{try channel.pipeline.syncOperations.addHandler(ByteToMessageHandler(StreamDecoder(self.logger)))returntryNIOAsyncChannel(
wrappingChannelSynchronously: channel,
configuration:.init(
backPressureStrategy:.init(lowWatermark:5, highWatermark:10),
inboundType:ByteBuffer.self))}}tryawait channel.executeThenClose{ inbound in
for tryawaitbuffer in inbound {tryawait buffer.withUnsafeReadableBytes{ ptr in// cannot use it here because withUnsafeReadableBytes does not support swift concurrency
header =ProtocolHeader(ptr)// some protocol that accepts UnsafeRawBufferPointertryawait hander.handleMessage(header)}}}
Thus I have to copy memory from ByteBuffer which I believe is not efficient:
tryawait channel.executeThenClose{ inbound in
for tryawaitbuffer in inbound {letbuf= buffer.withUnsafeReadableBytes{ buf in// Workaround, no async method in ByteBuffer...letnewBuf=UnsafeMutableRawBufferPointer.allocate(byteCount: buf.count, alignment:8)
newBuf.copyBytes(from: buf)return newBuf
}defer{
buf.deallocate()}
header =ProtocolHeader(UnsafeRawBufferPointer(buf))tryawait hander.handleMessage(header)}}
I am looking for a good solution here. The easiest way from my point of view seems to allow async withUnsafeReadableBytes.
However, it might be not inline with its design, therefore I am looking for a good way to solve the issue.
Could you advise on above, please?
The text was updated successfully, but these errors were encountered:
I haven't found a template for feature request, improvement or question, thus adding it as blank one.
Recently, there is
NIOAsyncChannel
was added to swift-nio. It is very convenient to use it with swift concurrency.However, sometimes it is hard to dial with ByteBuffer without async interface, such as
ByteBuffer.withUnsafeReadableBytes
that accepts async closure.I have the following use case:
Thus I have to copy memory from ByteBuffer which I believe is not efficient:
I am looking for a good solution here. The easiest way from my point of view seems to allow async
withUnsafeReadableBytes
.However, it might be not inline with its design, therefore I am looking for a good way to solve the issue.
Could you advise on above, please?
The text was updated successfully, but these errors were encountered: