7.3 KiB
7.3 KiB
Changes in the Public API from NIO 1 to NIO 2
- renamed all instances of
ctx
tocontext
. YourChannelHandler
methods now need to take acontext
parameter and no longerctx
. Example:func channelRead(context: ChannelHandlerContext, data: NIOAny)
HTTPResponseCompressor
moved toswift-nio-extras
.- removed all previously deprecated functions, types and modules.
- renamed
SniResult
toSNIResult
- renamed
SniHandler
toSNIHandler
- made
EventLoopGroup.makeIterator()
a required method Channel._unsafe
is nowChannel._channelCore
TimeAmount.Value
is nowInt64
(fromInt
on 64 bit platforms, no change for 32 bit platforms)ByteToMessageDecoder
s now need to be wrapped inByteToMessageHandler
before they can be added to the pipeline. before:pipeline.add(MyDecoder())
, after:pipeline.add(ByteToMessageHandler(MyDecoder()))
MessageToByteEncoder
s now need to be wrapped inMessageToByteHandler
before they can be added to the pipeline. before:pipeline.add(MyEncoder())
, after:pipeline.add(MessageToByteHandler(MyEncoder()))
BlockingIOThreadPool
has been renamed toNIOThreadPool
ByteToMessageDecoder
now requires the implementation ofdecodeLast
MessageToByteEncoder
now requires the implementation ofencode
MessageToByteEncoder.allocateOutBuffer
was removed without replacementMessageToByteEncoder.encode
no longer gets access to theChannelHandlerContext
ByteToMessageDecoder.decodeLast
has a new parameterseenEOF: Bool
EventLoop.makePromise
/makeSucceededFuture
/makeFailedFuture
instead ofnew*
, alsoresult:
/error:
labels droppedSocketAddress.makeAddressResolvingHost(:port:)
instead ofSocketAddress.newAddressResolving(host:port:)
- changed all ports to
Int
(fromUInt16
) - changed
HTTPVersion
'smajor
andminor
properties toInt
(fromUInt16
) NIOWebSocketUpgradeError
is now astruct
rather than anenum
- renamed the generic parameter name to
Bytes
where we're talking about a generic collection of bytes - Moved error
ChannelLifecycleError.inappropriateOperationForState
toChannelError.inappropriateOperationForState
. - Moved all errors in
MulticastError
enum intoChannelError
. - Removed
ChannelError.connectFailed
. All errors that triggered this now throwNIOConnectError
directly. - Made
WebSocketOpcode
a struct. RemovedWebSocketOpcode.unknownControl
andWebSocketOpcode.unknownNonControl
values: these should be replaced by simply instantiatingWebSocketOpcode
with the value. ThreadSpecificVariable
is now aclass
instead of astruct
Channel.setOption(option:value:)
has been renamedChannel.setOption(_:value:)
Channel.getOption(option:value:)
has been renamedChannel.getOption(_:value:)
ChannelOption.AssociatedValueType
has been removedChannelOption.OptionType
has been renamedChannelOption.Value
- the default
ChannelOption
s have been switched changed fromcase FooOption { case const }
to astruct FooOption { public init() {} }
markedElementIndex()
,markedElement()
andhasMark()
are now computed variables instead of functions.ByteBuffer.setString(_:at:)
(used to beset(string:at:)
) no longer returns anInt?
, instead it returnsInt
and has had its return value made discardable.ByteBuffer.write(string:)
(now namedByteBuffer.writeString(_:)
) no longer returns anInt?
, instead it returnsInt
and has had its return value made discardable.- removed ContiguousCollection
- CircularBuffer(initialRingCapacity:) is now CircularBuffer(initialCapacity:)
- MarkedCircularBuffer(initialRingCapacity:) is now MarkedCircularBuffer(initialCapacity:)
- EventLoopFuture.whenComplete now provides Result<T, Error>
- renamed
EventLoopFuture.then
toEventLoopFuture.flatMap
- renamed
EventLoopFuture.thenIfError
toEventLoopFuture.flatMapError
- renamed
EventLoopFuture.mapIfError
toEventLoopFuture.recover
- renamed
EventLoopFuture.thenThrowing
toEventLoopFuture.flatMapThrowing
- renamed
EventLoopFuture
's generic parameter fromT
toValue
- renamed
EventLoopFuture.and(result:)
toEventLoopFuture.and(value:)
- the asynchronous task version of
EventLoop.scheduleRepeatedTask
has been renamed toscheduleRepeatedAsyncTask
EventLoopPromise.succeed(result: Value)
lost its label so is nowEventLoopPromise.succeed(Value)
EventLoopPromise.fail(error: Error)
lost its label so is nowEventLoopPromise.fail(Error)
- renamed
HTTPProtocolUpgrader
toHTTPServerProtocolUpgrader
ByteToMessageDecoder
s no longer automatically close the connection on error.EventLoopFuture.cascade(promise: EventLoopPromise)
had its label changed toEventLoopFuture.cascade(to: EventLoopPromise)
EventLoopFuture.cascadeFailure(promise: EventLoopPromise)
had its label changed toEventLoopFuture.cascade(to: EventLoopPromise)
- renamed
EventLoopFuture.andAll(_:eventLoop:)
toEventLoopFuture.andAllSucceed(_:on:)
- all
ChannelPipeline.remove(...)
now returnEventLoopFuture<Void>
instead ofEventLoopFuture<Bool>
ByteBuffer.set(<type>, ...)
is nowByteBuffer.set<Type>
ByteBuffer.write(<type>, ...)
is nowByteBuffer.write<Type>
- renamed
EventLoopFuture.hopTo(eventLoop:)
toEventLoopFuture.hop(to:)
EventLoopFuture.reduce(into:_:eventLoop:_:)
had its label signature changed toEventLoopFuture.reduce(into:_:on:_:)
EventLoopFuture.reduce(_:_:eventLoop:_:
had its label signature changed toEventLoopFuture.reduce(_:_:on:_:)
CircularBuffer
andMarkedCircularBuffer
's indices are now opaque and no longerStrideable
, useCircularBuffer.index(...)
for index calculations- all
ChannelOption
s are now required to beEquatable
HTTPHeaderIndex
has been removed, without replacementHTTPHeader
has been removed, without replacementHTTPHeaders[canonicalForm:]
now returns[Substring]
instead of[String]
HTTPListHeaderIterator
has been removed, without replacementWebSocketFrameDecoder
'sautomaticErrorHandling:
parameter has been deprecated. Remove iffalse
, addWebSocketProtocolErrorHandler
to your pipeline instead iftrue
- rename
FileHandle
toNIOFileHandle
- rename all
ChannelPipeline.add(name:handler:...)
s toChannelPipeline.addHandler(_:name:...)
- rename all
ChannelPipeline.remove(...)
s toChannelPipeline.removeHandler(...)
- change
ChannelPipeline.addHandler[s](_:first:)
toChannelPipeline.addHandler(_:postion:)
whereposition
can be.first
,.last
,.before(ChannelHandler)
, and.after(ChannelHandler)
- change
ChannelPipeline.addHandler(_:before:)
toChannelPipeline.addHandler(_:postion:)
whereposition
can be.first
,.last
,.before(ChannelHandler)
, and.after(ChannelHandler)
- change
ChannelPipeline.addHandler(_:after:)
toChannelPipeline.addHandler(_:postion:)
whereposition
can be.first
,.last
,.before(ChannelHandler)
, and.after(ChannelHandler)
- Change
HTTPServerProtocolUpgrader
protocol
to requirebuildUpgradeResponse
to take achannel
and return anEventLoopFuture<HTTPHeaders>
. EmbeddedChannel.writeInbound/Outbound
are nowthrowing
EmbeddedChannel.finish/writeInbound/writeOutbound
now return anenum
representation of their effects rather than mystery bools.HTTPMethod.hasRequestBody
and theHTTPMethod.HasBody
type have been removed from the public API