@@ -318,6 +318,7 @@ open class WebSocket : NSObject, StreamDelegate {
318318 inStream. delegate = self
319319 outStream. delegate = self
320320 if supportedSSLSchemes. contains ( url. scheme!) {
321+ certValidated = false
321322 inStream. setProperty ( StreamSocketSecurityLevel . negotiatedSSL as AnyObject , forKey: Stream . PropertyKey. socketSecurityLevelKey)
322323 outStream. setProperty ( StreamSocketSecurityLevel . negotiatedSSL as AnyObject , forKey: Stream . PropertyKey. socketSecurityLevelKey)
323324 if disableSSLCertValidation {
@@ -631,7 +632,8 @@ open class WebSocket : NSObject, StreamDelegate {
631632 return buffer. fromOffset ( bufferLen - extra)
632633 } else {
633634 let isFin = ( FinMask & baseAddress [ 0 ] )
634- let receivedOpcode = OpCode ( rawValue: ( OpCodeMask & baseAddress [ 0 ] ) )
635+ let receivedOpcodeRawValue = ( OpCodeMask & baseAddress [ 0 ] )
636+ let receivedOpcode = OpCode ( rawValue: receivedOpcodeRawValue)
635637 let isMasked = ( MaskMask & baseAddress [ 1 ] )
636638 let payloadLen = ( PayloadLenMask & baseAddress [ 1 ] )
637639 var offset = 2
@@ -645,7 +647,7 @@ open class WebSocket : NSObject, StreamDelegate {
645647 if !isControlFrame && ( receivedOpcode != . binaryFrame && receivedOpcode != . continueFrame &&
646648 receivedOpcode != . textFrame && receivedOpcode != . pong) {
647649 let errCode = CloseCode . protocolError. rawValue
648- doDisconnect ( errorWithDetail ( " unknown opcode: \( String ( describing : receivedOpcode ) ) " , code: errCode) )
650+ doDisconnect ( errorWithDetail ( " unknown opcode: \( receivedOpcodeRawValue ) " , code: errCode) )
649651 writeError ( errCode)
650652 return emptyBuffer
651653 }
@@ -690,18 +692,13 @@ open class WebSocket : NSObject, StreamDelegate {
690692 if dataLength > UInt64 ( bufferLen) {
691693 len = UInt64 ( bufferLen- offset)
692694 }
693- let data : Data
694- if len < 0 {
695- len = 0
696- data = Data ( )
697- } else {
698- if receivedOpcode == . connectionClose && len > 0 {
699- let size = MemoryLayout< UInt16> . size
700- offset += size
701- len -= UInt64 ( size)
702- }
703- data = Data ( bytes: baseAddress+ offset, count: Int ( len) )
695+ if receivedOpcode == . connectionClose && len > 0 {
696+ let size = MemoryLayout< UInt16> . size
697+ offset += size
698+ len -= UInt64 ( size)
704699 }
700+ let data = Data ( bytes: baseAddress+ offset, count: Int ( len) )
701+
705702 if receivedOpcode == . connectionClose {
706703 var closeReason = " connection closed by server "
707704 if let customCloseReason = String ( data: data, encoding: . utf8) {
0 commit comments