forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process: add _getActiveHandles(), _getActiveRequests()
* process._getActiveHandles() returns a list containing all active handles (timers, sockets, etc.) that have not been unref'd. * process._getActiveRequests() returns a list of active requests (in-flight actions like connecting to a remote host, writing data to a socket, etc.).
- Loading branch information
1 parent
636add2
commit 5f04065
Showing
8 changed files
with
252 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
|
||
/* | ||
* Copyright (C) Igor Sysoev | ||
*/ | ||
|
||
|
||
#ifndef NGX_QUEUE_H_INCLUDED_ | ||
#define NGX_QUEUE_H_INCLUDED_ | ||
|
||
|
||
typedef struct ngx_queue_s ngx_queue_t; | ||
|
||
struct ngx_queue_s { | ||
ngx_queue_t *prev; | ||
ngx_queue_t *next; | ||
}; | ||
|
||
|
||
#define ngx_queue_init(q) \ | ||
(q)->prev = q; \ | ||
(q)->next = q | ||
|
||
|
||
#define ngx_queue_empty(h) \ | ||
(h == (h)->prev) | ||
|
||
|
||
#define ngx_queue_insert_head(h, x) \ | ||
(x)->next = (h)->next; \ | ||
(x)->next->prev = x; \ | ||
(x)->prev = h; \ | ||
(h)->next = x | ||
|
||
|
||
#define ngx_queue_insert_after ngx_queue_insert_head | ||
|
||
|
||
#define ngx_queue_insert_tail(h, x) \ | ||
(x)->prev = (h)->prev; \ | ||
(x)->prev->next = x; \ | ||
(x)->next = h; \ | ||
(h)->prev = x | ||
|
||
|
||
#define ngx_queue_head(h) \ | ||
(h)->next | ||
|
||
|
||
#define ngx_queue_last(h) \ | ||
(h)->prev | ||
|
||
|
||
#define ngx_queue_sentinel(h) \ | ||
(h) | ||
|
||
|
||
#define ngx_queue_next(q) \ | ||
(q)->next | ||
|
||
|
||
#define ngx_queue_prev(q) \ | ||
(q)->prev | ||
|
||
|
||
#if (NGX_DEBUG) | ||
|
||
#define ngx_queue_remove(x) \ | ||
(x)->next->prev = (x)->prev; \ | ||
(x)->prev->next = (x)->next; \ | ||
(x)->prev = NULL; \ | ||
(x)->next = NULL | ||
|
||
#else | ||
|
||
#define ngx_queue_remove(x) \ | ||
(x)->next->prev = (x)->prev; \ | ||
(x)->prev->next = (x)->next | ||
|
||
#endif | ||
|
||
|
||
#define ngx_queue_split(h, q, n) \ | ||
(n)->prev = (h)->prev; \ | ||
(n)->prev->next = n; \ | ||
(n)->next = q; \ | ||
(h)->prev = (q)->prev; \ | ||
(h)->prev->next = h; \ | ||
(q)->prev = n; | ||
|
||
|
||
#define ngx_queue_add(h, n) \ | ||
(h)->prev->next = (n)->next; \ | ||
(n)->next->prev = (h)->prev; \ | ||
(h)->prev = (n)->prev; \ | ||
(h)->prev->next = h; | ||
|
||
|
||
#define ngx_queue_data(q, type, link) \ | ||
(type *) ((unsigned char *) q - offsetof(type, link)) | ||
|
||
|
||
#define ngx_queue_foreach(q, h) \ | ||
for ((q) = ngx_queue_head(h); (q) != (h); (q) = ngx_queue_next(q)) | ||
|
||
|
||
#endif /* NGX_QUEUE_H_INCLUDED_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to permit | ||
// persons to whom the Software is furnished to do so, subject to the | ||
// following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var spawn = require('child_process').spawn; | ||
var net = require('net'); | ||
|
||
function expect(activeHandles, activeRequests) { | ||
assert.equal(process._getActiveHandles().length, activeHandles); | ||
assert.equal(process._getActiveRequests().length, activeRequests); | ||
} | ||
|
||
(function() { | ||
expect(0, 0); | ||
var server = net.createServer().listen(common.PORT); | ||
expect(1, 0); | ||
server.close(); | ||
expect(1, 0); // server handle doesn't shut down until next tick | ||
})(); | ||
|
||
(function() { | ||
expect(1, 0); | ||
var conn = net.createConnection(common.PORT); | ||
conn.on('error', function() { /* ignore */ }); | ||
expect(2, 1); | ||
conn.destroy(); | ||
expect(2, 1); // client handle doesn't shut down until next tick | ||
})(); | ||
|
||
process.nextTick(function() { | ||
process.nextTick(function() { | ||
// the handles should be gone but the connect req could still be alive | ||
assert.equal(process._getActiveHandles().length, 0); | ||
}); | ||
}); |