Skip to content

Commit 2824048

Browse files
committed
OSCUDPSocket: Input sanitizing for port number and inline docs updated for clarity
1 parent ad8ed78 commit 2824048

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Sources/OSCKit/UDP/Socket/OSCUDPSocket.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public final class OSCUDPSocket {
5959
/// manufacturer.
6060
public var remotePort: UInt16 {
6161
get { _remotePort ?? localPort }
62-
set { _remotePort = newValue }
62+
set { _remotePort = (newValue == 0) ? nil : newValue }
6363
}
6464
private var _remotePort: UInt16?
6565

@@ -99,10 +99,10 @@ public final class OSCUDPSocket {
9999
///
100100
/// - Parameters:
101101
/// - localPort: Local port to listen on for inbound OSC packets.
102-
/// If `nil`, a random available port in the system will be chosen.
102+
/// If `nil` or `0`, a random available port in the system will be chosen.
103103
/// - remoteHost: Remote hostname or IP address.
104104
/// - remotePort: Remote port on the remote host machine to send outbound OSC packets to.
105-
/// If `nil`, the `localPort` value will be used.
105+
/// If `nil` or `0`, the `localPort` value will be used.
106106
/// - interface: Optionally specify a network interface for which to constrain communication.
107107
/// - timeTagMode: OSC time-tag mode. The default is recommended.
108108
/// - isIPv4BroadcastEnabled: Enable sending IPv4 broadcast messages from the socket.
@@ -121,8 +121,8 @@ public final class OSCUDPSocket {
121121
receiveHandler: OSCHandlerBlock? = nil
122122
) {
123123
self.remoteHost = remoteHost
124-
_localPort = localPort
125-
_remotePort = remotePort
124+
_localPort = (localPort == nil || localPort == 0) ? nil : localPort
125+
_remotePort = (remotePort == nil || remotePort == 0) ? nil : remotePort
126126
self.interface = interface
127127
self.timeTagMode = timeTagMode
128128
self.isIPv4BroadcastEnabled = isIPv4BroadcastEnabled

0 commit comments

Comments
 (0)