Skip to content

Commit

Permalink
size
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Nov 12, 2024
1 parent 5835cea commit d8bb4d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions FlyingSocks/Sources/Socket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ public struct Socket: Sendable, Hashable {
}
}

Check warning on line 273 in FlyingSocks/Sources/Socket.swift

View check run for this annotation

Codecov / codecov/patch

FlyingSocks/Sources/Socket.swift#L269-L273

Added lines #L269 - L273 were not covered by tests

private func send<A: SocketAddress>(_ pointer: UnsafeRawPointer, length: Int, to address: A) throws -> Int {
private func send(_ pointer: UnsafeRawPointer, length: Int, to address: some SocketAddress) throws -> Int {
var addr = address
let sent = withUnsafePointer(to: &addr) {
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
Socket.sendto(file.rawValue, pointer, length, 0, $0, socklen_t(MemoryLayout<A>.size))
Socket.sendto(file.rawValue, pointer, length, 0, $0, address.size)
}
}
guard sent >= 0 || errno == EISCONN else {
Expand Down
15 changes: 15 additions & 0 deletions FlyingSocks/Sources/SocketAddress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ public protocol SocketAddress: Sendable {
static var family: sa_family_t { get }
}

extension SocketAddress {
var family: sa_family_t {
var this = self
return withUnsafePointer(to: &this) {
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
$0.pointee.sa_family
}
}
}

Check warning on line 55 in FlyingSocks/Sources/SocketAddress.swift

View check run for this annotation

Codecov / codecov/patch

FlyingSocks/Sources/SocketAddress.swift#L48-L55

Added lines #L48 - L55 were not covered by tests

var size: socklen_t {
socklen_t(MemoryLayout<Self>.size)
}

Check warning on line 59 in FlyingSocks/Sources/SocketAddress.swift

View check run for this annotation

Codecov / codecov/patch

FlyingSocks/Sources/SocketAddress.swift#L57-L59

Added lines #L57 - L59 were not covered by tests
}

public extension SocketAddress where Self == sockaddr_in {

static func inet(port: UInt16) -> Self {
Expand Down

0 comments on commit d8bb4d2

Please sign in to comment.