Skip to content

Commit 2b0b28c

Browse files
committed
Rebase and update to top-of-main
1 parent e7f6310 commit 2b0b28c

File tree

4 files changed

+39
-36
lines changed

4 files changed

+39
-36
lines changed

Sources/System/Sockets/SocketOperations.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ extension SocketDescriptor {
8282

8383
@usableFromInline
8484
internal func _bind(to address: SocketAddress) -> Result<(), Errno> {
85-
let success = address.withUnsafeCInterop { addr, len in
86-
system_bind(self.rawValue, addr, len)
85+
nothingOrErrno(retryOnInterrupt: false) {
86+
address.withUnsafeCInterop { addr, len in
87+
system_bind(self.rawValue, addr, len)
88+
}
8789
}
88-
return nothingOrErrno(success)
8990
}
9091

9192
/// Listen for connections on a socket.
@@ -103,7 +104,9 @@ extension SocketDescriptor {
103104

104105
@usableFromInline
105106
internal func _listen(backlog: Int) -> Result<(), Errno> {
106-
nothingOrErrno(system_listen(self.rawValue, CInt(backlog)))
107+
nothingOrErrno(retryOnInterrupt: false) {
108+
system_listen(self.rawValue, CInt(backlog))
109+
}
107110
}
108111

109112
/// Accept a connection on a socket.
@@ -189,10 +192,11 @@ extension SocketDescriptor {
189192

190193
@usableFromInline
191194
internal func _connect(to address: SocketAddress) -> Result<(), Errno> {
192-
let success = address.withUnsafeCInterop { addr, len in
193-
system_connect(self.rawValue, addr, len)
195+
nothingOrErrno(retryOnInterrupt: false) {
196+
address.withUnsafeCInterop { addr, len in
197+
system_connect(self.rawValue, addr, len)
198+
}
194199
}
195-
return nothingOrErrno(success)
196200
}
197201

198202
/// Shutdown part of a full-duplex connection
@@ -205,7 +209,9 @@ extension SocketDescriptor {
205209

206210
@usableFromInline
207211
internal func _shutdown(_ how: ShutdownKind) -> Result<(), Errno> {
208-
nothingOrErrno(system_shutdown(self.rawValue, how.rawValue))
212+
nothingOrErrno(retryOnInterrupt: false) {
213+
system_shutdown(self.rawValue, how.rawValue)
214+
}
209215
}
210216

211217
// MARK: - Send and receive

Sources/System/Sockets/SocketOptions.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,13 @@ extension SocketDescriptor {
518518
into buffer: UnsafeMutableRawBufferPointer
519519
) -> Result<Int, Errno> {
520520
var length = CInterop.SockLen(buffer.count)
521-
let success = system_getsockopt(
522-
self.rawValue,
523-
level.rawValue,
524-
option.rawValue,
525-
buffer.baseAddress, &length)
526-
return nothingOrErrno(success).map { _ in Int(length) }
521+
return nothingOrErrno(retryOnInterrupt: false) {
522+
system_getsockopt(
523+
self.rawValue,
524+
level.rawValue,
525+
option.rawValue,
526+
buffer.baseAddress, &length)
527+
}.map { _ in Int(length) }
527528
}
528529
}
529530

@@ -595,11 +596,12 @@ extension SocketDescriptor {
595596
_ option: Option,
596597
from buffer: UnsafeRawBufferPointer
597598
) -> Result<Void, Errno> {
598-
let success = system_setsockopt(
599-
self.rawValue,
600-
level.rawValue,
601-
option.rawValue,
602-
buffer.baseAddress, CInterop.SockLen(buffer.count))
603-
return nothingOrErrno(success)
599+
nothingOrErrno(retryOnInterrupt: false) {
600+
system_setsockopt(
601+
self.rawValue,
602+
level.rawValue,
603+
option.rawValue,
604+
buffer.baseAddress, CInterop.SockLen(buffer.count))
605+
}
604606
}
605607
}

Tests/SystemTests/SocketTest.swift

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,34 @@ final class SocketTest: XCTestCase {
3030
let writeBufAddr = writeBuf.baseAddress
3131

3232
let syscallTestCases: Array<MockTestCase> = [
33-
MockTestCase(name: "socket", PF_INET6, SOCK_STREAM, 0, interruptable: true) {
33+
MockTestCase(name: "socket", .interruptable, PF_INET6, SOCK_STREAM, 0) {
3434
retryOnInterrupt in
3535
_ = try SocketDescriptor.open(.ipv6, .stream, retryOnInterrupt: retryOnInterrupt)
3636
},
37-
MockTestCase(name: "shutdown", rawSocket, SHUT_RD, interruptable: false) {
37+
MockTestCase(name: "shutdown", .noInterrupt, rawSocket, SHUT_RD) {
3838
retryOnInterrupt in
3939
_ = try socket.shutdown(.read)
4040
},
41-
MockTestCase(name: "listen", rawSocket, 999, interruptable: false) {
41+
MockTestCase(name: "listen", .noInterrupt, rawSocket, 999) {
4242
retryOnInterrupt in
4343
_ = try socket.listen(backlog: 999)
4444
},
4545
MockTestCase(
46-
name: "recv", rawSocket, bufAddr, bufCount, MSG_PEEK, interruptable: true
46+
name: "recv", .interruptable, rawSocket, bufAddr, bufCount, MSG_PEEK
4747
) {
4848
retryOnInterrupt in
4949
_ = try socket.receive(
5050
into: rawBuf, flags: .peek, retryOnInterrupt: retryOnInterrupt)
5151
},
5252
MockTestCase(
53-
name: "send", rawSocket, writeBufAddr, bufCount, MSG_DONTROUTE,
54-
interruptable: true
53+
name: "send", .interruptable, rawSocket, writeBufAddr, bufCount, MSG_DONTROUTE
5554
) {
5655
retryOnInterrupt in
5756
_ = try socket.send(
5857
writeBuf, flags: .doNotRoute, retryOnInterrupt: retryOnInterrupt)
5958
},
6059
MockTestCase(
61-
name: "recvfrom", rawSocket, Wildcard(), Wildcard(), 42, Wildcard(), Wildcard(),
62-
interruptable: true
60+
name: "recvfrom", .interruptable, rawSocket, Wildcard(), Wildcard(), 42, Wildcard(), Wildcard()
6361
) { retryOnInterrupt in
6462
var sender = SocketAddress()
6563
_ = try socket.receive(into: rawBuf,
@@ -68,8 +66,7 @@ final class SocketTest: XCTestCase {
6866
retryOnInterrupt: retryOnInterrupt)
6967
},
7068
MockTestCase(
71-
name: "sendto", rawSocket, Wildcard(), Wildcard(), 42, Wildcard(), Wildcard(),
72-
interruptable: true
69+
name: "sendto", .interruptable, rawSocket, Wildcard(), Wildcard(), 42, Wildcard(), Wildcard()
7370
) { retryOnInterrupt in
7471
let recipient = SocketAddress(ipv4: .loopback, port: 123)
7572
_ = try socket.send(UnsafeRawBufferPointer(rawBuf),
@@ -78,8 +75,7 @@ final class SocketTest: XCTestCase {
7875
retryOnInterrupt: retryOnInterrupt)
7976
},
8077
MockTestCase(
81-
name: "recvmsg", rawSocket, Wildcard(), 42,
82-
interruptable: true
78+
name: "recvmsg", .interruptable, rawSocket, Wildcard(), 42
8379
) { retryOnInterrupt in
8480
var sender = SocketAddress()
8581
var ancillary = SocketDescriptor.AncillaryMessageBuffer()
@@ -90,8 +86,7 @@ final class SocketTest: XCTestCase {
9086
retryOnInterrupt: retryOnInterrupt)
9187
},
9288
MockTestCase(
93-
name: "sendmsg", rawSocket, Wildcard(), 42,
94-
interruptable: true
89+
name: "sendmsg", .interruptable, rawSocket, Wildcard(), 42
9590
) { retryOnInterrupt in
9691
let recipient = SocketAddress(ipv4: .loopback, port: 123)
9792
let ancillary = SocketDescriptor.AncillaryMessageBuffer()

Tests/SystemTests/TestingInfrastructure.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ internal struct MockTestCase: TestCase {
198198
guard interruptBehavior != .noError else {
199199
do {
200200
try body(interruptable)
201-
self.expectEqual(self.expected, mocking.trace.dequeue())
201+
self.expectMatch(self.expected, mocking.trace.dequeue())
202202
try body(!interruptable)
203-
self.expectEqual(self.expected, mocking.trace.dequeue())
203+
self.expectMatch(self.expected, mocking.trace.dequeue())
204204
} catch {
205205
self.fail()
206206
}

0 commit comments

Comments
 (0)