GeezerVison is showing github.com — dgram: add dgram send queue info · nodejs/node@33707dc
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/dgram.md +17Lines changed: 17 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -454,6 +454,23 @@ added: v8.7.0 | 454 | 454 |
| 455 | 455 | This method throws [`ERR_SOCKET_BUFFER_SIZE`][] if called on an unbound socket. | 456 | 456 |
| | 457 | +### `socket.getSendQueueSize()` | | 458 | + | | 459 | +<!-- YAML | | 460 | +added: REPLACEME | | 461 | +--> | | 462 | + | | 463 | +* Returns: {number} Number of bytes queued for sending. | | 464 | + | | 465 | +### `socket.getSendQueueCount()` | | 466 | + | | 467 | +<!-- YAML | | 468 | +added: REPLACEME | | 469 | +--> | | 470 | + | | 471 | +* Returns: {number} Number of send requests currently in the queue awaiting | | 472 | + to be processed. | | 473 | + | 457 | 474 | ### `socket.ref()` | 458 | 475 |
| 459 | 476 | <!-- YAML | |
Collapse file Copy file name to clipboardExpand all lines: lib/dgram.js +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -976,6 +976,13 @@ Socket.prototype.getSendBufferSize = function() { | 976 | 976 | return bufferSize(this, 0, SEND_BUFFER); | 977 | 977 | }; | 978 | 978 |
| | 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 | +}; | 979 | 986 |
| 980 | 987 | // Deprecated private APIs. | 981 | 988 | ObjectDefineProperty(Socket.prototype, '_handle', { | |
Collapse file Copy file name to clipboardExpand all lines: src/udp_wrap.cc +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -182,6 +182,9 @@ void UDPWrap::Initialize(Local<Object> target, | 182 | 182 | SetProtoMethod(isolate, t, "setBroadcast", SetBroadcast); | 183 | 183 | SetProtoMethod(isolate, t, "setTTL", SetTTL); | 184 | 184 | SetProtoMethod(isolate, t, "bufferSize", BufferSize); | | 185 | + SetProtoMethodNoSideEffect(isolate, t, "getSendQueueSize", GetSendQueueSize); | | 186 | + SetProtoMethodNoSideEffect( | | 187 | + isolate, t, "getSendQueueCount", GetSendQueueCount); | 185 | 188 |
| 186 | 189 | t->Inherit(HandleWrap::GetConstructorTemplate(env)); | 187 | 190 |
| @@ -783,6 +786,23 @@ MaybeLocal<Object> UDPWrap::Instantiate(Environment* env, | 783 | 786 | return env->udp_constructor_function()->NewInstance(env->context()); | 784 | 787 | } | 785 | 788 |
| | 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 | +} | 786 | 806 |
| 787 | 807 | } // namespace node | 788 | 808 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/udp_wrap.h +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -150,6 +150,9 @@ class UDPWrap final : public HandleWrap, | 150 | 150 | static void SetBroadcast(const v8::FunctionCallbackInfo<v8::Value>& args); | 151 | 151 | static void SetTTL(const v8::FunctionCallbackInfo<v8::Value>& args); | 152 | 152 | 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); | 153 | 156 |
| 154 | 157 | // UDPListener implementation | 155 | 158 | uv_buf_t OnAlloc(size_t suggested_size) override; | |
Collapse file Copy file name to clipboard +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Flags: --test-udp-no-try-send | | 2 | +'use strict'; | | 3 | +const common = require('../common'); | | 4 | +const assert = require('assert'); | | 5 | +const dgram = require('dgram'); | | 6 | + | | 7 | +const socket = dgram.createSocket('udp4'); | | 8 | +assert.strictEqual(socket.getSendQueueSize(), 0); | | 9 | +assert.strictEqual(socket.getSendQueueCount(), 0); | | 10 | +socket.close(); | | 11 | + | | 12 | +const server = dgram.createSocket('udp4'); | | 13 | +const client = dgram.createSocket('udp4'); | | 14 | + | | 15 | +server.bind(0, common.mustCall(() => { | | 16 | + client.connect(server.address().port, common.mustCall(() => { | | 17 | + const data = 'hello'; | | 18 | + client.send(data); | | 19 | + client.send(data); | | 20 | + // See uv__send in win/udp.c | | 21 | + assert.strictEqual(client.getSendQueueSize(), | | 22 | + common.isWindows ? 0 : data.length * 2); | | 23 | + assert.strictEqual(client.getSendQueueCount(), 2); | | 24 | + client.close(); | | 25 | + server.close(); | | 26 | + })); | | 27 | +})); |
|