Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions XCode/Sources/Socket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ public enum SocketError: Error {
// swiftlint: disable identifier_name
open class Socket: Hashable, Equatable {

let socketFileDescriptor: Int32
private var shutdown = false
public let socketFileDescriptor: Int32
private var shutdown = false {
didSet {
if shutdown { didClose?() }
}
}
public var didClose: (() -> ())?

public init(socketFileDescriptor: Int32) {
self.socketFileDescriptor = socketFileDescriptor
Expand Down
7 changes: 5 additions & 2 deletions XCode/Sources/WebSockets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public class WebSocketSession: Hashable, Equatable {
public enum WsError: Error { case unknownOpCode(String), unMaskedFrame(String), protocolError(String), invalidUTF8(String) }
public enum OpCode: UInt8 { case `continue` = 0x00, close = 0x08, ping = 0x09, pong = 0x0A, text = 0x01, binary = 0x02 }
public enum Control: Error { case close }
public var shouldCloseSocket = true

public class Frame {
public var opcode = OpCode.close
Expand All @@ -167,8 +168,10 @@ public class WebSocketSession: Hashable, Equatable {
}

deinit {
writeCloseFrame()
socket.close()
if shouldCloseSocket {
writeCloseFrame()
socket.close()
}
}

public func writeText(_ text: String) {
Expand Down