mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Workers cannot shut down while requests are open, so keep a counter that is increased whenever libuv requests are made and decreased whenever their callback is called. This also applies to other embedders, who may want to shut down an `Environment` instance early. Many thanks for Stephen Belanger for reviewing the original version of this commit in the Ayo.js project. Fixes: https://github.com/nodejs/node/issues/20517 Refs: https://github.com/ayojs/ayo/pull/85 PR-URL: https://github.com/nodejs/node/pull/19377 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
62 lines
1.9 KiB
C++
62 lines
1.9 KiB
C++
#ifndef SRC_REQ_WRAP_H_
|
|
#define SRC_REQ_WRAP_H_
|
|
|
|
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
|
|
#include "async_wrap.h"
|
|
#include "env.h"
|
|
#include "util.h"
|
|
#include "v8.h"
|
|
|
|
namespace node {
|
|
|
|
template <typename T>
|
|
class ReqWrap : public AsyncWrap {
|
|
public:
|
|
inline ReqWrap(Environment* env,
|
|
v8::Local<v8::Object> object,
|
|
AsyncWrap::ProviderType provider);
|
|
inline ~ReqWrap() override;
|
|
// Call this after the req has been dispatched, if that did not already
|
|
// happen by using Dispatch().
|
|
inline void Dispatched();
|
|
// Call this after a request has finished, if re-using this object is planned.
|
|
inline void Reset();
|
|
T* req() { return &req_; }
|
|
inline void Cancel();
|
|
|
|
static ReqWrap* from_req(T* req);
|
|
|
|
template <typename LibuvFunction, typename... Args>
|
|
inline int Dispatch(LibuvFunction fn, Args... args);
|
|
|
|
private:
|
|
friend class Environment;
|
|
friend int GenDebugSymbols();
|
|
template <typename ReqT, typename U>
|
|
friend struct MakeLibuvRequestCallback;
|
|
|
|
ListNode<ReqWrap> req_wrap_queue_;
|
|
|
|
typedef void (*callback_t)();
|
|
callback_t original_callback_ = nullptr;
|
|
|
|
protected:
|
|
// req_wrap_queue_ needs to be at a fixed offset from the start of the class
|
|
// because it is used by ContainerOf to calculate the address of the embedding
|
|
// ReqWrap. ContainerOf compiles down to simple, fixed pointer arithmetic. It
|
|
// is also used by src/node_postmortem_metadata.cc to calculate offsets and
|
|
// generate debug symbols for ReqWrap, which assumes that the position of
|
|
// members in memory are predictable. sizeof(req_) depends on the type of T,
|
|
// so req_wrap_queue_ would no longer be at a fixed offset if it came after
|
|
// req_. For more information please refer to
|
|
// `doc/guides/node-postmortem-support.md`
|
|
T req_;
|
|
};
|
|
|
|
} // namespace node
|
|
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
|
|
#endif // SRC_REQ_WRAP_H_
|