Skip to content

Commit

Permalink
OSCServer and OSCSocket: Replaced dispatch queue injection with d…
Browse files Browse the repository at this point in the history
…edicated internal queue

Now that the OSC receive handler block is Sendable and async, the internal queue is now only needed for CocoaAsyncSocket to receive
  • Loading branch information
orchetect committed Sep 30, 2024
1 parent 8eb594a commit dfc5b33
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
4 changes: 1 addition & 3 deletions Sources/OSCKit/OSCServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import OSCKitCore
public final class OSCServer: NSObject, _OSCServerProtocol {
let udpSocket = GCDAsyncUdpSocket()
let udpDelegate = OSCServerUDPDelegate()
let receiveQueue: DispatchQueue
let receiveQueue = DispatchQueue(label: "org.orchetect.OSCKit.OSCServer.receiveQueue")
var handler: OSCHandlerBlock?

/// Time tag mode. Determines how OSC bundle time tags are handled.
Expand Down Expand Up @@ -48,14 +48,12 @@ public final class OSCServer: NSObject, _OSCServerProtocol {
/// - Note: Ensure ``start()`` is called once in order to begin receiving messages.
public init(
port: UInt16 = 8000,
receiveQueue: DispatchQueue = .main,
timeTagMode: OSCTimeTagMode = .ignore,
handler: OSCHandlerBlock? = nil
) {
self.localPort = port
self.timeTagMode = timeTagMode

self.receiveQueue = receiveQueue
self.handler = handler

super.init()
Expand Down
9 changes: 3 additions & 6 deletions Sources/OSCKit/OSCSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import CocoaAsyncSocket
public final class OSCSocket: NSObject, _OSCServerProtocol {
let udpSocket = GCDAsyncUdpSocket()
let udpDelegate = OSCServerUDPDelegate()
let receiveQueue: DispatchQueue
let receiveQueue = DispatchQueue(label: "org.orchetect.OSCKit.OSCSocket.receiveQueue")
var handler: OSCHandlerBlock?

/// Time tag mode. Determines how OSC bundle time tags are handled.
Expand All @@ -35,7 +35,6 @@ public final class OSCSocket: NSObject, _OSCServerProtocol {
/// overridden using the `host` parameter in the call to ``send(_:to:port:)``..
public var remoteHost: String?

private var _localPort: UInt16?
/// Local UDP port used to both send OSC packets from and listen for incoming packets.
/// This may only be set at the time of class initialization.
///
Expand All @@ -48,8 +47,8 @@ public final class OSCSocket: NSObject, _OSCServerProtocol {
public var localPort: UInt16 {
udpSocket.localPort()
}
private var _localPort: UInt16?

private var _remotePort: UInt16?
/// UDP port used by to send OSC packets. This may be set at any time.
/// This port will be used in calls to ``send(_:to:port:)``. The port may still be overridden
/// using the `port` parameter in the call to ``send(_:to:port:)``.
Expand All @@ -60,6 +59,7 @@ public final class OSCSocket: NSObject, _OSCServerProtocol {
get { _remotePort ?? localPort }
set { _remotePort = newValue }
}
private var _remotePort: UInt16?

private var _isIPv4BroadcastEnabled: Bool = false
/// Enable sending IPv4 broadcast messages from the socket.
Expand Down Expand Up @@ -112,16 +112,13 @@ public final class OSCSocket: NSObject, _OSCServerProtocol {
localPort: UInt16? = nil,
remoteHost: String? = nil,
remotePort: UInt16? = nil,
receiveQueue: DispatchQueue = .main,
timeTagMode: OSCTimeTagMode = .ignore,
handler: OSCHandlerBlock? = nil
) {
self.remoteHost = remoteHost
self._localPort = localPort
self._remotePort = remotePort
self.timeTagMode = timeTagMode

self.receiveQueue = receiveQueue
self.handler = handler

super.init()
Expand Down

0 comments on commit dfc5b33

Please sign in to comment.