11cb0ef41Sopenharmony_ci// Copyright Joyent, Inc. and other Node contributors. 21cb0ef41Sopenharmony_ci// 31cb0ef41Sopenharmony_ci// Permission is hereby granted, free of charge, to any person obtaining a 41cb0ef41Sopenharmony_ci// copy of this software and associated documentation files (the 51cb0ef41Sopenharmony_ci// "Software"), to deal in the Software without restriction, including 61cb0ef41Sopenharmony_ci// without limitation the rights to use, copy, modify, merge, publish, 71cb0ef41Sopenharmony_ci// distribute, sublicense, and/or sell copies of the Software, and to permit 81cb0ef41Sopenharmony_ci// persons to whom the Software is furnished to do so, subject to the 91cb0ef41Sopenharmony_ci// following conditions: 101cb0ef41Sopenharmony_ci// 111cb0ef41Sopenharmony_ci// The above copyright notice and this permission notice shall be included 121cb0ef41Sopenharmony_ci// in all copies or substantial portions of the Software. 131cb0ef41Sopenharmony_ci// 141cb0ef41Sopenharmony_ci// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 151cb0ef41Sopenharmony_ci// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 161cb0ef41Sopenharmony_ci// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 171cb0ef41Sopenharmony_ci// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 181cb0ef41Sopenharmony_ci// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 191cb0ef41Sopenharmony_ci// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 201cb0ef41Sopenharmony_ci// USE OR OTHER DEALINGS IN THE SOFTWARE. 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci#ifndef SRC_TCP_WRAP_H_ 231cb0ef41Sopenharmony_ci#define SRC_TCP_WRAP_H_ 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci#include "async_wrap.h" 281cb0ef41Sopenharmony_ci#include "connection_wrap.h" 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_cinamespace node { 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ciclass ExternalReferenceRegistry; 331cb0ef41Sopenharmony_ciclass Environment; 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciclass TCPWrap : public ConnectionWrap<TCPWrap, uv_tcp_t> { 361cb0ef41Sopenharmony_ci public: 371cb0ef41Sopenharmony_ci enum SocketType { 381cb0ef41Sopenharmony_ci SOCKET, 391cb0ef41Sopenharmony_ci SERVER 401cb0ef41Sopenharmony_ci }; 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci static v8::MaybeLocal<v8::Object> Instantiate(Environment* env, 431cb0ef41Sopenharmony_ci AsyncWrap* parent, 441cb0ef41Sopenharmony_ci SocketType type); 451cb0ef41Sopenharmony_ci static void Initialize(v8::Local<v8::Object> target, 461cb0ef41Sopenharmony_ci v8::Local<v8::Value> unused, 471cb0ef41Sopenharmony_ci v8::Local<v8::Context> context, 481cb0ef41Sopenharmony_ci void* priv); 491cb0ef41Sopenharmony_ci static void RegisterExternalReferences(ExternalReferenceRegistry* registry); 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci SET_NO_MEMORY_INFO() 521cb0ef41Sopenharmony_ci SET_SELF_SIZE(TCPWrap) 531cb0ef41Sopenharmony_ci const char* MemoryInfoName() const override { 541cb0ef41Sopenharmony_ci switch (provider_type()) { 551cb0ef41Sopenharmony_ci case ProviderType::PROVIDER_TCPWRAP: 561cb0ef41Sopenharmony_ci return "TCPSocketWrap"; 571cb0ef41Sopenharmony_ci case ProviderType::PROVIDER_TCPSERVERWRAP: 581cb0ef41Sopenharmony_ci return "TCPServerWrap"; 591cb0ef41Sopenharmony_ci default: 601cb0ef41Sopenharmony_ci UNREACHABLE(); 611cb0ef41Sopenharmony_ci } 621cb0ef41Sopenharmony_ci } 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci private: 651cb0ef41Sopenharmony_ci typedef uv_tcp_t HandleType; 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci template <typename T, 681cb0ef41Sopenharmony_ci int (*F)(const typename T::HandleType*, sockaddr*, int*)> 691cb0ef41Sopenharmony_ci friend void GetSockOrPeerName(const v8::FunctionCallbackInfo<v8::Value>&); 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ci TCPWrap(Environment* env, v8::Local<v8::Object> object, 721cb0ef41Sopenharmony_ci ProviderType provider); 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci static void New(const v8::FunctionCallbackInfo<v8::Value>& args); 751cb0ef41Sopenharmony_ci static void SetNoDelay(const v8::FunctionCallbackInfo<v8::Value>& args); 761cb0ef41Sopenharmony_ci static void SetKeepAlive(const v8::FunctionCallbackInfo<v8::Value>& args); 771cb0ef41Sopenharmony_ci static void Bind(const v8::FunctionCallbackInfo<v8::Value>& args); 781cb0ef41Sopenharmony_ci static void Bind6(const v8::FunctionCallbackInfo<v8::Value>& args); 791cb0ef41Sopenharmony_ci static void Listen(const v8::FunctionCallbackInfo<v8::Value>& args); 801cb0ef41Sopenharmony_ci static void Connect(const v8::FunctionCallbackInfo<v8::Value>& args); 811cb0ef41Sopenharmony_ci static void Connect6(const v8::FunctionCallbackInfo<v8::Value>& args); 821cb0ef41Sopenharmony_ci template <typename T> 831cb0ef41Sopenharmony_ci static void Connect(const v8::FunctionCallbackInfo<v8::Value>& args, 841cb0ef41Sopenharmony_ci std::function<int(const char* ip_address, T* addr)> uv_ip_addr); 851cb0ef41Sopenharmony_ci static void Open(const v8::FunctionCallbackInfo<v8::Value>& args); 861cb0ef41Sopenharmony_ci template <typename T> 871cb0ef41Sopenharmony_ci static void Bind( 881cb0ef41Sopenharmony_ci const v8::FunctionCallbackInfo<v8::Value>& args, 891cb0ef41Sopenharmony_ci int family, 901cb0ef41Sopenharmony_ci std::function<int(const char* ip_address, int port, T* addr)> uv_ip_addr); 911cb0ef41Sopenharmony_ci static void Reset(const v8::FunctionCallbackInfo<v8::Value>& args); 921cb0ef41Sopenharmony_ci int Reset(v8::Local<v8::Value> close_callback = v8::Local<v8::Value>()); 931cb0ef41Sopenharmony_ci 941cb0ef41Sopenharmony_ci#ifdef _WIN32 951cb0ef41Sopenharmony_ci static void SetSimultaneousAccepts( 961cb0ef41Sopenharmony_ci const v8::FunctionCallbackInfo<v8::Value>& args); 971cb0ef41Sopenharmony_ci#endif 981cb0ef41Sopenharmony_ci}; 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci 1011cb0ef41Sopenharmony_ci} // namespace node 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ci#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 1041cb0ef41Sopenharmony_ci 1051cb0ef41Sopenharmony_ci#endif // SRC_TCP_WRAP_H_ 106