Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow public access to socket and keep it open when requested #471

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from
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