@@ -893,4 +893,61 @@ extension NIOTSConnectionChannel {
893
893
return SynchronousOptions ( channel: self )
894
894
}
895
895
}
896
+
897
+
898
+ public struct NIOTSConnectionNotInitialized : Error , Hashable {
899
+ public init ( ) { }
900
+ }
901
+
902
+ public struct NIOTSChannelIsNotANIOTSConnectionChannel : Error , Hashable {
903
+ public init ( ) { }
904
+ }
905
+
906
+ @available ( OSX 10 . 14 , iOS 12 . 0 , tvOS 12 . 0 , watchOS 6 . 0 , * )
907
+ extension NIOTSConnectionChannel {
908
+ fileprivate func metadata( definition: NWProtocolDefinition ) throws -> NWProtocolMetadata ? {
909
+ guard let nwConnection = self . nwConnection else {
910
+ throw NIOTSConnectionNotInitialized ( )
911
+ }
912
+ return nwConnection. metadata ( definition: definition)
913
+ }
914
+ }
915
+
916
+ @available ( OSX 10 . 14 , iOS 12 . 0 , tvOS 12 . 0 , watchOS 6 . 0 , * )
917
+ extension Channel {
918
+ /// Retrieves the metadata for a specific protocol from the underlying ``NWConnection``
919
+ /// - Throws: If `self` isn't a `NIOTS` channel with a `NWConnection` this method will throw
920
+ /// ``NIOTSChannelIsNotATransportServicesChannel`` or ``NIOTSConnectionNotInitialized``.
921
+ public func getMetadata( definition: NWProtocolDefinition ) -> EventLoopFuture < NWProtocolMetadata ? > {
922
+ guard let channel = self as? NIOTSConnectionChannel else {
923
+ return self . eventLoop. makeFailedFuture ( NIOTSChannelIsNotANIOTSConnectionChannel ( ) )
924
+ }
925
+ if self . eventLoop. inEventLoop {
926
+ return self . eventLoop. makeCompletedFuture {
927
+ try channel. metadata ( definition: definition)
928
+ }
929
+ } else {
930
+ return self . eventLoop. submit {
931
+ try channel. metadata ( definition: definition)
932
+ }
933
+ }
934
+ }
935
+
936
+ /// Retrieves the metadata for a specific protocol from the underlying ``NWConnection``
937
+ /// - Precondition: Must be called on the `EventLoop` the `Channel` is running on.
938
+ /// - Throws: If `self` isn't a `NIOTS` channel with a `NWConnection` this method will throw
939
+ /// ``NIOTSChannelIsNotATransportServicesChannel`` or ``NIOTSConnectionNotInitialized``.
940
+ public func getMetadataSync(
941
+ definition: NWProtocolDefinition ,
942
+ file: StaticString = #fileID,
943
+ line: UInt = #line
944
+ ) throws -> NWProtocolMetadata ? {
945
+ self . eventLoop. preconditionInEventLoop ( file: file, line: line)
946
+ guard let channel = self as? NIOTSConnectionChannel else {
947
+ throw NIOTSChannelIsNotANIOTSConnectionChannel ( )
948
+ }
949
+ return try channel. metadata ( definition: definition)
950
+ }
951
+ }
952
+
896
953
#endif
0 commit comments