-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathUtil.swift
More file actions
67 lines (58 loc) · 1.56 KB
/
Copy pathUtil.swift
File metadata and controls
67 lines (58 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
This source file is part of the Swift System open source project
Copyright (c) 2021 - 2025 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
*/
import SystemPackage
import SystemSockets
#if SYSTEM_PACKAGE_DARWIN
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(Android)
import Android
#else
#error("Unsupported Platform")
#endif
/// Turn off libc's input/output buffering.
internal func disableBuffering() {
setbuf(stdin, nil)
setbuf(stdout, nil)
setbuf(stderr, nil)
}
internal func complain(_ message: String) {
var message = message + "\n"
message.withUTF8 { buffer in
_ = try? FileDescriptor.standardError.writeAll(buffer)
}
}
@available(System 99, *)
extension SocketAddress.ResolvedAddress {
var niceDescription: String {
var proto = ""
switch self.protocol {
case .udp: proto = "udp"
case .tcp: proto = "tcp"
default: proto = "\(self.protocol)"
}
return "\(address.niceDescription) (\(proto))"
}
}
@available(System 99, *)
extension SocketAddress {
var niceDescription: String {
if let ipv4 = self.ipv4 { return ipv4.description }
if let ipv6 = self.ipv6 { return ipv6.description }
if let unix = self.unix { return unix.description }
return self.description
}
}
@available(System 99, *)
extension SocketDescriptor.ConnectionType {
var isConnectionless: Bool {
self == .datagram || self == .reliablyDeliveredMessage
}
}