Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new ChannelOption to get the amount of buffered outbound data in the Channel #2849

Merged
merged 27 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
69d8fcb
add buffered writable writes option to channel
johnnzhou Aug 10, 2024
5a06f57
add tests for pending datagram writes manager
johnnzhou Aug 15, 2024
576e04b
add tests for pending stream writes manager
johnnzhou Aug 16, 2024
5598706
add channel tests and datagram channel tests for bufferedBytes option
johnnzhou Aug 19, 2024
18b9562
Merge remote-tracking branch 'upstream/main'
johnnzhou Aug 19, 2024
f025e05
align with upstream
johnnzhou Aug 19, 2024
8e3935a
fix type inconsistency issue
johnnzhou Aug 19, 2024
5f0029d
Merge branch 'apple:main' into main
johnnzhou Aug 19, 2024
7ad22c7
skip checking snd_buf size as different platforms have different beha…
johnnzhou Aug 20, 2024
69ab6d0
rename test and add back missing asserts
johnnzhou Aug 20, 2024
756f11d
Merge branch 'main' into main
johnnzhou Aug 20, 2024
b9a3442
[WIP] align interface type to Int; support new channel option for emb…
johnnzhou Aug 21, 2024
7d8dcdc
add unit tests for embedded and async channels
johnnzhou Aug 24, 2024
2023396
Merge branch 'main' into main
johnnzhou Sep 3, 2024
f6337d9
Merge branch 'main' into main
johnnzhou Sep 3, 2024
2d7428a
Merge branch 'main' into main
johnnzhou Sep 4, 2024
10c004c
Merge branch 'main' into main
johnnzhou Sep 8, 2024
760b4e7
Merge branch 'main' into main
johnnzhou Sep 11, 2024
e963207
Merge branch 'main' into main
johnnzhou Sep 13, 2024
1460bfe
Merge branch 'main' into main
johnnzhou Sep 14, 2024
686afb8
Merge branch 'main' into main
Lukasa Sep 16, 2024
331e0ed
Merge branch 'main' into main
johnnzhou Sep 16, 2024
a248e2c
change foreach loop back to for-in loop
johnnzhou Sep 17, 2024
225e02e
Merge branch 'main' into main
johnnzhou Sep 18, 2024
eeda805
Merge branch 'main' into main
johnnzhou Sep 20, 2024
ac06d72
fix lint problem
johnnzhou Sep 23, 2024
f3ee542
Merge branch 'main' of github.com:johnnzhou/swift-nio
johnnzhou Sep 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/NIOCore/BSDSocketAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ extension NIOBSDSocket.Option {

/// Specifies the total per-socket buffer space reserved for receives.
public static let so_rcvbuf = Self(rawValue: SO_RCVBUF)

/// Specifies the total per-socket buffer space reserved for sends.
public static let so_sndbuf = Self(rawValue: SO_SNDBUF)

/// Specifies the receive timeout.
public static let so_rcvtimeo = Self(rawValue: SO_RCVTIMEO)
Expand Down
10 changes: 10 additions & 0 deletions Sources/NIOCore/ChannelOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ extension ChannelOptions {
public typealias Value = Bool
public init() {}
}

/// `BufferedWritableBytesOption` allows users to know the number of writable bytes currently buffered in the `Channel`.
public struct BufferedWritableBytesOption: ChannelOption, Sendable {
public typealias Value = Int64
johnnzhou marked this conversation as resolved.
Show resolved Hide resolved

public init() {}
}
}
}

Expand Down Expand Up @@ -358,6 +365,9 @@ public struct ChannelOptions: Sendable {

/// - seealso: `ReceivePacketInfo`
public static let receivePacketInfo = Types.ReceivePacketInfo()

/// - seealso: `BufferedWritableBytesOption`
public static let bufferedWritableBytes = Types.BufferedWritableBytesOption()
}

/// - seealso: `SocketOption`.
Expand Down
2 changes: 2 additions & 0 deletions Sources/NIOPosix/BaseStreamSocketChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class BaseStreamSocketChannel<Socket: SocketProtocol>: BaseSocketChannel<Socket>
return self.pendingWrites.writeSpinCount as! Option.Value
case _ as ChannelOptions.Types.WriteBufferWaterMarkOption:
return self.pendingWrites.waterMark as! Option.Value
case _ as ChannelOptions.Types.BufferedWritableBytesOption:
return self.pendingWrites.bufferedBytes as! Option.Value
default:
return try super.getOption0(option)
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/NIOPosix/PendingDatagramWritesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ final class PendingDatagramWritesManager: PendingWritesManager {
var isEmpty: Bool {
self.state.isEmpty
}

var bufferedBytes: Int64 {
return self.state.bytes
}

private func add(_ pendingWrite: PendingDatagramWrite) -> Bool {
assert(self.isOpen)
Expand Down
4 changes: 4 additions & 0 deletions Sources/NIOPosix/PendingWritesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ final class PendingStreamWritesManager: PendingWritesManager {
var isEmpty: Bool {
self.state.isEmpty
}

var bufferedBytes: Int64 {
return self.state.bytes
}

/// Add a pending write alongside its promise.
///
Expand Down
2 changes: 2 additions & 0 deletions Sources/NIOPosix/SocketChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,8 @@ final class DatagramChannel: BaseSocketChannel<Socket> {
throw ChannelError._operationUnsupported
}
return try self.socket.getUDPReceiveOffload() as! Option.Value
case _ as ChannelOptions.Types.BufferedWritableBytesOption:
return self.pendingWrites.bufferedBytes as! Option.Value
default:
return try super.getOption0(option)
}
Expand Down
Loading