2017-01-03 22:16:48 +01:00
|
|
|
// 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.
|
|
|
|
|
2013-07-31 20:07:29 +02:00
|
|
|
#ifndef SRC_HANDLE_WRAP_H_
|
|
|
|
#define SRC_HANDLE_WRAP_H_
|
2011-07-18 13:22:16 +02:00
|
|
|
|
2016-05-24 09:54:05 +02:00
|
|
|
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
|
|
|
2017-11-14 13:34:52 +01:00
|
|
|
#include "async_wrap.h"
|
2015-01-30 12:54:53 +01:00
|
|
|
#include "util.h"
|
2013-07-31 23:16:08 +02:00
|
|
|
#include "uv.h"
|
|
|
|
#include "v8.h"
|
2012-04-28 18:45:10 +02:00
|
|
|
|
2011-07-18 13:22:16 +02:00
|
|
|
namespace node {
|
|
|
|
|
2015-01-30 12:54:53 +01:00
|
|
|
class Environment;
|
|
|
|
|
2011-07-18 22:45:11 +02:00
|
|
|
// Rules:
|
|
|
|
//
|
|
|
|
// - Do not throw from handle methods. Set errno.
|
|
|
|
//
|
|
|
|
// - MakeCallback may only be made directly off the event loop.
|
2014-02-03 00:39:43 +01:00
|
|
|
// That is there can be no JavaScript stack frames underneath it.
|
|
|
|
// (Is there any way to assert that?)
|
2011-07-18 22:45:11 +02:00
|
|
|
//
|
|
|
|
// - No use of v8::WeakReferenceCallback. The close callback signifies that
|
|
|
|
// we're done with a handle - external resources can be freed.
|
|
|
|
//
|
|
|
|
// - Reusable?
|
|
|
|
//
|
|
|
|
// - The uv_close_cb is used to free the c++ object. The close callback
|
|
|
|
// is not made into javascript land.
|
|
|
|
//
|
|
|
|
// - uv_ref, uv_unref counts are managed at this layer to avoid needless
|
|
|
|
// js/c++ boundary crossing. At the javascript layer that should all be
|
|
|
|
// taken care of.
|
|
|
|
|
2013-09-24 23:12:11 +02:00
|
|
|
class HandleWrap : public AsyncWrap {
|
2013-07-31 20:07:29 +02:00
|
|
|
public:
|
2013-07-03 04:23:44 +02:00
|
|
|
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args);
|
|
|
|
static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2016-05-09 23:02:59 +02:00
|
|
|
static void HasRef(const v8::FunctionCallbackInfo<v8::Value>& args);
|
2013-07-03 04:23:44 +02:00
|
|
|
|
2014-10-24 17:46:25 +02:00
|
|
|
static inline bool IsAlive(const HandleWrap* wrap) {
|
2016-04-26 13:32:44 +02:00
|
|
|
return wrap != nullptr && wrap->state_ != kClosed;
|
2016-04-26 12:01:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool HasRef(const HandleWrap* wrap) {
|
2016-04-26 13:32:44 +02:00
|
|
|
return IsAlive(wrap) && uv_has_ref(wrap->GetHandle());
|
2014-10-24 17:46:25 +02:00
|
|
|
}
|
|
|
|
|
2016-09-22 10:36:13 +02:00
|
|
|
inline uv_handle_t* GetHandle() const { return handle_; }
|
2013-07-03 04:23:44 +02:00
|
|
|
|
2013-07-31 20:07:29 +02:00
|
|
|
protected:
|
2013-08-11 00:26:11 +02:00
|
|
|
HandleWrap(Environment* env,
|
2015-07-18 11:34:16 +02:00
|
|
|
v8::Local<v8::Object> object,
|
2014-01-20 22:33:16 +01:00
|
|
|
uv_handle_t* handle,
|
2017-03-07 20:40:18 +01:00
|
|
|
AsyncWrap::ProviderType provider);
|
2016-06-28 21:21:21 +02:00
|
|
|
~HandleWrap() override;
|
2013-07-03 04:23:44 +02:00
|
|
|
|
2013-07-31 20:07:29 +02:00
|
|
|
private:
|
2015-01-30 12:54:53 +01:00
|
|
|
friend class Environment;
|
2013-07-03 04:23:44 +02:00
|
|
|
friend void GetActiveHandles(const v8::FunctionCallbackInfo<v8::Value>&);
|
|
|
|
static void OnClose(uv_handle_t* handle);
|
2015-01-30 12:54:53 +01:00
|
|
|
ListNode<HandleWrap> handle_wrap_queue_;
|
2016-04-26 12:01:46 +02:00
|
|
|
enum { kInitialized, kClosing, kClosingWithCallback, kClosed } state_;
|
2016-09-22 10:36:13 +02:00
|
|
|
uv_handle_t* const handle_;
|
2011-07-18 13:22:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace node
|
|
|
|
|
2016-05-24 09:54:05 +02:00
|
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
2011-07-18 13:22:16 +02:00
|
|
|
|
2013-07-31 20:07:29 +02:00
|
|
|
#endif // SRC_HANDLE_WRAP_H_
|