@@ -59,17 +59,19 @@ class MockSOCKSServer {
5959 bootstrap = ServerBootstrap ( group: elg)
6060 . serverChannelOption ( ChannelOptions . socket ( SocketOptionLevel ( SOL_SOCKET) , SO_REUSEADDR) , value: 1 )
6161 . childChannelInitializer { channel in
62- let handshakeHandler = SOCKSServerHandshakeHandler ( )
63- return channel. pipeline. addHandlers ( [
64- handshakeHandler,
65- SOCKSTestHandler ( handshakeHandler: handshakeHandler) ,
66- TestHTTPServer (
67- expectedURL: expectedURL,
68- expectedResponse: expectedResponse,
69- file: file,
70- line: line
71- ) ,
72- ] )
62+ channel. eventLoop. makeCompletedFuture {
63+ let handshakeHandler = SOCKSServerHandshakeHandler ( )
64+ try channel. pipeline. syncOperations. addHandlers ( [
65+ handshakeHandler,
66+ SOCKSTestHandler ( handshakeHandler: handshakeHandler) ,
67+ TestHTTPServer (
68+ expectedURL: expectedURL,
69+ expectedResponse: expectedResponse,
70+ file: file,
71+ line: line
72+ ) ,
73+ ] )
74+ }
7375 }
7476 }
7577 self . channel = try bootstrap. bind ( host: " localhost " , port: 0 ) . wait ( )
@@ -112,15 +114,19 @@ class SOCKSTestHandler: ChannelInboundHandler, RemovableChannelHandler {
112114 ) ,
113115 promise: nil
114116 )
115- context. channel. pipeline. addHandlers (
116- [
117- ByteToMessageHandler ( HTTPRequestDecoder ( ) ) ,
118- HTTPResponseEncoder ( ) ,
119- ] ,
120- position: . after( self )
121- ) . whenSuccess {
122- context. channel. pipeline. removeHandler ( self , promise: nil )
123- context. channel. pipeline. removeHandler ( self . handshakeHandler, promise: nil )
117+
118+ do {
119+ try context. channel. pipeline. syncOperations. addHandlers (
120+ [
121+ ByteToMessageHandler ( HTTPRequestDecoder ( ) ) ,
122+ HTTPResponseEncoder ( ) ,
123+ ] ,
124+ position: . after( self )
125+ )
126+ context. channel. pipeline. syncOperations. removeHandler ( self , promise: nil )
127+ context. channel. pipeline. syncOperations. removeHandler ( self . handshakeHandler, promise: nil )
128+ } catch {
129+ context. fireErrorCaught ( error)
124130 }
125131 }
126132 }
0 commit comments