Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/nodejs/src/stream_wrap.h
1 // Copyright Joyent, Inc. and other Node contributors. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a 4 // copy of this software and associated documentation files (the 5 // "Software"), to deal in the Software without restriction, including 6 // without limitation the rights to use, copy, modify, merge, publish, 7 // distribute, sublicense, and/or sell copies of the Software, and to permit 8 // persons to whom the Software is furnished to do so, subject to the 9 // following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included 12 // in all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22 #ifndef SRC_STREAM_WRAP_H_ 23 #define SRC_STREAM_WRAP_H_ 24 25 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 26 27 #include "stream_base.h" 28 #include "handle_wrap.h" 29 #include "v8.h" 30 31 namespace node { 32 33 class Environment; 34 class ExternalReferenceRegistry; 35 36 class LibuvStreamWrap : public HandleWrap, public StreamBase { 37 public: 38 static void Initialize(v8::Local<v8::Object> target, 39 v8::Local<v8::Value> unused, 40 v8::Local<v8::Context> context, 41 void* priv); 42 static void RegisterExternalReferences(ExternalReferenceRegistry* registry); 43 int GetFD() override; 44 bool IsAlive() override; 45 bool IsClosing() override; 46 bool IsIPCPipe() override; 47 48 // JavaScript functions 49 int ReadStart() override; 50 int ReadStop() override; 51 52 // Resource implementation 53 int DoShutdown(ShutdownWrap* req_wrap) override; 54 int DoTryWrite(uv_buf_t** bufs, size_t* count) override; 55 inline bool HasDoTryWrite() const override { return true; } 56 int DoWrite(WriteWrap* w, 57 uv_buf_t* bufs, 58 size_t count, 59 uv_stream_t* send_handle) override; 60 61 inline uv_stream_t* stream() const { 62 return stream_; 63 } 64 65 inline bool is_named_pipe() const { 66 return stream()->type == UV_NAMED_PIPE; 67 } 68 69 inline bool is_named_pipe_ipc() const { 70 return is_named_pipe() && 71 reinterpret_cast<const uv_pipe_t*>(stream())->ipc != 0; 72 } 73 74 inline bool is_tcp() const { 75 return stream()->type == UV_TCP; 76 } 77 78 ShutdownWrap* CreateShutdownWrap(v8::Local<v8::Object> object) override; 79 WriteWrap* CreateWriteWrap(v8::Local<v8::Object> object) override; 80 81 static LibuvStreamWrap* From(Environment* env, v8::Local<v8::Object> object); 82 83 protected: 84 LibuvStreamWrap(Environment* env, 85 v8::Local<v8::Object> object, 86 uv_stream_t* stream, 87 AsyncWrap::ProviderType provider); 88 89 AsyncWrap* GetAsyncWrap() override; 90 91 static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( 92 Environment* env); 93 94 protected: 95 inline void set_fd(int fd) { 96 #ifdef _WIN32 97 fd_ = fd; 98 #endif 99 } 100 101 102 private: 103 static void GetWriteQueueSize( 104 const v8::FunctionCallbackInfo<v8::Value>& info); 105 static void SetBlocking(const v8::FunctionCallbackInfo<v8::Value>& args); 106 107 // Callbacks for libuv 108 void OnUvAlloc(size_t suggested_size, uv_buf_t* buf); 109 v8::Maybe<void> OnUvRead(ssize_t nread, const uv_buf_t* buf); 110 111 static void AfterUvWrite(uv_write_t* req, int status); 112 static void AfterUvShutdown(uv_shutdown_t* req, int status); 113 114 uv_stream_t* const stream_; 115 116 #ifdef _WIN32 117 // We don't always have an FD that we could look up on the stream_ 118 // object itself on Windows. However, for some cases, we open handles 119 // using FDs; In that case, we can store and provide the value. 120 // This became necessary because it allows to detect situations 121 // where multiple handles refer to the same stdio FDs (in particular, 122 // a possible IPC channel and a regular process.std??? stream). 123 int fd_ = -1; 124 #endif 125 }; 126 127 128 } // namespace node 129 130 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 131 132 #endif // SRC_STREAM_WRAP_H_