dgram: add dgram send queue info · nodejs/node@33707dc · GitHub
Skip to content

Commit 33707dc

Browse files
theanarkhrichardlau
authored andcommitted
dgram: add dgram send queue info
PR-URL: #44149 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent c708d9b commit 33707dc

5 files changed

Lines changed: 74 additions & 0 deletions

File tree

doc/api/dgram.md

Lines changed: 17 additions & 0 deletions

lib/dgram.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,13 @@ Socket.prototype.getSendBufferSize = function() {
976976
return bufferSize(this, 0, SEND_BUFFER);
977977
};
978978

979+
Socket.prototype.getSendQueueSize = function() {
980+
return this[kStateSymbol].handle.getSendQueueSize();
981+
};
982+
983+
Socket.prototype.getSendQueueCount = function() {
984+
return this[kStateSymbol].handle.getSendQueueCount();
985+
};
979986

980987
// Deprecated private APIs.
981988
ObjectDefineProperty(Socket.prototype, '_handle', {

src/udp_wrap.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ void UDPWrap::Initialize(Local<Object> target,
182182
SetProtoMethod(isolate, t, "setBroadcast", SetBroadcast);
183183
SetProtoMethod(isolate, t, "setTTL", SetTTL);
184184
SetProtoMethod(isolate, t, "bufferSize", BufferSize);
185+
SetProtoMethodNoSideEffect(isolate, t, "getSendQueueSize", GetSendQueueSize);
186+
SetProtoMethodNoSideEffect(
187+
isolate, t, "getSendQueueCount", GetSendQueueCount);
185188

186189
t->Inherit(HandleWrap::GetConstructorTemplate(env));
187190

@@ -783,6 +786,23 @@ MaybeLocal<Object> UDPWrap::Instantiate(Environment* env,
783786
return env->udp_constructor_function()->NewInstance(env->context());
784787
}
785788

789+
void UDPWrap::GetSendQueueSize(const FunctionCallbackInfo<Value>& args) {
790+
UDPWrap* wrap;
791+
ASSIGN_OR_RETURN_UNWRAP(
792+
&wrap, args.Holder(), args.GetReturnValue().Set(UV_EBADF));
793+
794+
size_t size = uv_udp_get_send_queue_size(&wrap->handle_);
795+
args.GetReturnValue().Set(static_cast<double>(size));
796+
}
797+
798+
void UDPWrap::GetSendQueueCount(const FunctionCallbackInfo<Value>& args) {
799+
UDPWrap* wrap;
800+
ASSIGN_OR_RETURN_UNWRAP(
801+
&wrap, args.Holder(), args.GetReturnValue().Set(UV_EBADF));
802+
803+
size_t count = uv_udp_get_send_queue_count(&wrap->handle_);
804+
args.GetReturnValue().Set(static_cast<double>(count));
805+
}
786806

787807
} // namespace node
788808

src/udp_wrap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ class UDPWrap final : public HandleWrap,
150150
static void SetBroadcast(const v8::FunctionCallbackInfo<v8::Value>& args);
151151
static void SetTTL(const v8::FunctionCallbackInfo<v8::Value>& args);
152152
static void BufferSize(const v8::FunctionCallbackInfo<v8::Value>& args);
153+
static void GetSendQueueSize(const v8::FunctionCallbackInfo<v8::Value>& args);
154+
static void GetSendQueueCount(
155+
const v8::FunctionCallbackInfo<v8::Value>& args);
153156

154157
// UDPListener implementation
155158
uv_buf_t OnAlloc(size_t suggested_size) override;
Lines changed: 27 additions & 0 deletions

0 commit comments

Comments
 (0)