| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ba9ec91 commit adc1601
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,30 +67,6 @@ void StreamResource::PushStreamListener(StreamListener* listener) { | |||
| 67 | 67 | listener_ = listener; | |
| 68 | 68 | } | |
| 69 | 69 | ||
| 70 | - void StreamResource::RemoveStreamListener(StreamListener* listener) { | ||
| 71 | - CHECK_NOT_NULL(listener); | ||
| 72 | - | ||
| 73 | - StreamListener* previous; | ||
| 74 | - StreamListener* current; | ||
| 75 | - | ||
| 76 | - // Remove from the linked list. | ||
| 77 | - for (current = listener_, previous = nullptr; | ||
| 78 | - /* No loop condition because we want a crash if listener is not found */ | ||
| 79 | - ; previous = current, current = current->previous_listener_) { | ||
| 80 | - CHECK_NOT_NULL(current); | ||
| 81 | - if (current == listener) { | ||
| 82 | - if (previous != nullptr) | ||
| 83 | - previous->previous_listener_ = current->previous_listener_; | ||
| 84 | - else | ||
| 85 | - listener_ = listener->previous_listener_; | ||
| 86 | - break; | ||
| 87 | - } | ||
| 88 | - } | ||
| 89 | - | ||
| 90 | - listener->stream_ = nullptr; | ||
| 91 | - listener->previous_listener_ = nullptr; | ||
| 92 | - } | ||
| 93 | - | ||
| 94 | 70 | uv_buf_t StreamResource::EmitAlloc(size_t suggested_size) { | |
| 95 | 71 | DebugSealHandleScope seal_handle_scope; | |
| 96 | 72 | return listener_->OnStreamAlloc(suggested_size); | |
@@ -122,101 +98,6 @@ StreamBase::StreamBase(Environment* env) : env_(env) { | |||
| 122 | 98 | PushStreamListener(&default_listener_); | |
| 123 | 99 | } | |
| 124 | 100 | ||
| 125 | - int StreamBase::Shutdown(v8::Local<v8::Object> req_wrap_obj) { | ||
| 126 | - Environment* env = stream_env(); | ||
| 127 | - | ||
| 128 | - v8::HandleScope handle_scope(env->isolate()); | ||
| 129 | - | ||
| 130 | - if (req_wrap_obj.IsEmpty()) { | ||
| 131 | - if (!env->shutdown_wrap_template() | ||
| 132 | - ->NewInstance(env->context()) | ||
| 133 | - .ToLocal(&req_wrap_obj)) { | ||
| 134 | - return UV_EBUSY; | ||
| 135 | - } | ||
| 136 | - StreamReq::ResetObject(req_wrap_obj); | ||
| 137 | - } | ||
| 138 | - | ||
| 139 | - BaseObjectPtr<AsyncWrap> req_wrap_ptr; | ||
| 140 | - AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(GetAsyncWrap()); | ||
| 141 | - ShutdownWrap* req_wrap = CreateShutdownWrap(req_wrap_obj); | ||
| 142 | - if (req_wrap != nullptr) | ||
| 143 | - req_wrap_ptr.reset(req_wrap->GetAsyncWrap()); | ||
| 144 | - int err = DoShutdown(req_wrap); | ||
| 145 | - | ||
| 146 | - if (err != 0 && req_wrap != nullptr) { | ||
| 147 | - req_wrap->Dispose(); | ||
| 148 | - } | ||
| 149 | - | ||
| 150 | - const char* msg = Error(); | ||
| 151 | - if (msg != nullptr) { | ||
| 152 | - if (req_wrap_obj->Set(env->context(), | ||
| 153 | - env->error_string(), | ||
| 154 | - OneByteString(env->isolate(), msg)).IsNothing()) { | ||
| 155 | - return UV_EBUSY; | ||
| 156 | - } | ||
| 157 | - ClearError(); | ||
| 158 | - } | ||
| 159 | - | ||
| 160 | - return err; | ||
| 161 | - } | ||
| 162 | - | ||
| 163 | - StreamWriteResult StreamBase::Write(uv_buf_t* bufs, | ||
| 164 | - size_t count, | ||
| 165 | - uv_stream_t* send_handle, | ||
| 166 | - v8::Local<v8::Object> req_wrap_obj, | ||
| 167 | - bool skip_try_write) { | ||
| 168 | - Environment* env = stream_env(); | ||
| 169 | - int err; | ||
| 170 | - | ||
| 171 | - size_t total_bytes = 0; | ||
| 172 | - for (size_t i = 0; i < count; ++i) | ||
| 173 | - total_bytes += bufs[i].len; | ||
| 174 | - bytes_written_ += total_bytes; | ||
| 175 | - | ||
| 176 | - if (send_handle == nullptr && !skip_try_write) { | ||
| 177 | - err = DoTryWrite(&bufs, &count); | ||
| 178 | - if (err != 0 || count == 0) { | ||
| 179 | - return StreamWriteResult { false, err, nullptr, total_bytes, {} }; | ||
| 180 | - } | ||
| 181 | - } | ||
| 182 | - | ||
| 183 | - v8::HandleScope handle_scope(env->isolate()); | ||
| 184 | - | ||
| 185 | - if (req_wrap_obj.IsEmpty()) { | ||
| 186 | - if (!env->write_wrap_template() | ||
| 187 | - ->NewInstance(env->context()) | ||
| 188 | - .ToLocal(&req_wrap_obj)) { | ||
| 189 | - return StreamWriteResult { false, UV_EBUSY, nullptr, 0, {} }; | ||
| 190 | - } | ||
| 191 | - StreamReq::ResetObject(req_wrap_obj); | ||
| 192 | - } | ||
| 193 | - | ||
| 194 | - AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(GetAsyncWrap()); | ||
| 195 | - WriteWrap* req_wrap = CreateWriteWrap(req_wrap_obj); | ||
| 196 | - BaseObjectPtr<AsyncWrap> req_wrap_ptr(req_wrap->GetAsyncWrap()); | ||
| 197 | - | ||
| 198 | - err = DoWrite(req_wrap, bufs, count, send_handle); | ||
| 199 | - bool async = err == 0; | ||
| 200 | - | ||
| 201 | - if (!async) { | ||
| 202 | - req_wrap->Dispose(); | ||
| 203 | - req_wrap = nullptr; | ||
| 204 | - } | ||
| 205 | - | ||
| 206 | - const char* msg = Error(); | ||
| 207 | - if (msg != nullptr) { | ||
| 208 | - if (req_wrap_obj->Set(env->context(), | ||
| 209 | - env->error_string(), | ||
| 210 | - OneByteString(env->isolate(), msg)).IsNothing()) { | ||
| 211 | - return StreamWriteResult { false, UV_EBUSY, nullptr, 0, {} }; | ||
| 212 | - } | ||
| 213 | - ClearError(); | ||
| 214 | - } | ||
| 215 | - | ||
| 216 | - return StreamWriteResult { | ||
| 217 | - async, err, req_wrap, total_bytes, std::move(req_wrap_ptr) }; | ||
| 218 | - } | ||
| 219 | - | ||
| 220 | 101 | template <typename OtherBase> | |
| 221 | 102 | SimpleShutdownWrap<OtherBase>::SimpleShutdownWrap( | |
| 222 | 103 | StreamBase* stream, | |
@@ -278,22 +159,6 @@ void WriteWrap::SetBackingStore(std::unique_ptr<v8::BackingStore> bs) { | |||
| 278 | 159 | backing_store_ = std::move(bs); | |
| 279 | 160 | } | |
| 280 | 161 | ||
| 281 | - void StreamReq::Done(int status, const char* error_str) { | ||
| 282 | - AsyncWrap* async_wrap = GetAsyncWrap(); | ||
| 283 | - Environment* env = async_wrap->env(); | ||
| 284 | - if (error_str != nullptr) { | ||
| 285 | - v8::HandleScope handle_scope(env->isolate()); | ||
| 286 | - if (async_wrap->object()->Set( | ||
| 287 | - env->context(), | ||
| 288 | - env->error_string(), | ||
| 289 | - OneByteString(env->isolate(), error_str)).IsNothing()) { | ||
| 290 | - return; | ||
| 291 | - } | ||
| 292 | - } | ||
| 293 | - | ||
| 294 | - OnDone(status); | ||
| 295 | - } | ||
| 296 | - | ||
| 297 | 162 | void StreamReq::ResetObject(v8::Local<v8::Object> obj) { | |
| 298 | 163 | DCHECK_GT(obj->InternalFieldCount(), StreamReq::kStreamReqField); | |
| 299 | 164 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,6 +40,103 @@ using v8::Signature; | |||
| 40 | 40 | using v8::String; | |
| 41 | 41 | using v8::Value; | |
| 42 | 42 | ||
| 43 | + int StreamBase::Shutdown(v8::Local<v8::Object> req_wrap_obj) { | ||
| 44 | + Environment* env = stream_env(); | ||
| 45 | + | ||
| 46 | + v8::HandleScope handle_scope(env->isolate()); | ||
| 47 | + | ||
| 48 | + if (req_wrap_obj.IsEmpty()) { | ||
| 49 | + if (!env->shutdown_wrap_template() | ||
| 50 | + ->NewInstance(env->context()) | ||
| 51 | + .ToLocal(&req_wrap_obj)) { | ||
| 52 | + return UV_EBUSY; | ||
| 53 | + } | ||
| 54 | + StreamReq::ResetObject(req_wrap_obj); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + BaseObjectPtr<AsyncWrap> req_wrap_ptr; | ||
| 58 | + AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(GetAsyncWrap()); | ||
| 59 | + ShutdownWrap* req_wrap = CreateShutdownWrap(req_wrap_obj); | ||
| 60 | + if (req_wrap != nullptr) req_wrap_ptr.reset(req_wrap->GetAsyncWrap()); | ||
| 61 | + int err = DoShutdown(req_wrap); | ||
| 62 | + | ||
| 63 | + if (err != 0 && req_wrap != nullptr) { | ||
| 64 | + req_wrap->Dispose(); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + const char* msg = Error(); | ||
| 68 | + if (msg != nullptr) { | ||
| 69 | + if (req_wrap_obj | ||
| 70 | + ->Set(env->context(), | ||
| 71 | + env->error_string(), | ||
| 72 | + OneByteString(env->isolate(), msg)) | ||
| 73 | + .IsNothing()) { | ||
| 74 | + return UV_EBUSY; | ||
| 75 | + } | ||
| 76 | + ClearError(); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + return err; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + StreamWriteResult StreamBase::Write(uv_buf_t* bufs, | ||
| 83 | + size_t count, | ||
| 84 | + uv_stream_t* send_handle, | ||
| 85 | + v8::Local<v8::Object> req_wrap_obj, | ||
| 86 | + bool skip_try_write) { | ||
| 87 | + Environment* env = stream_env(); | ||
| 88 | + int err; | ||
| 89 | + | ||
| 90 | + size_t total_bytes = 0; | ||
| 91 | + for (size_t i = 0; i < count; ++i) total_bytes += bufs[i].len; | ||
| 92 | + bytes_written_ += total_bytes; | ||
| 93 | + | ||
| 94 | + if (send_handle == nullptr && !skip_try_write) { | ||
| 95 | + err = DoTryWrite(&bufs, &count); | ||
| 96 | + if (err != 0 || count == 0) { | ||
| 97 | + return StreamWriteResult{false, err, nullptr, total_bytes, {}}; | ||
| 98 | + } | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + v8::HandleScope handle_scope(env->isolate()); | ||
| 102 | + | ||
| 103 | + if (req_wrap_obj.IsEmpty()) { | ||
| 104 | + if (!env->write_wrap_template() | ||
| 105 | + ->NewInstance(env->context()) | ||
| 106 | + .ToLocal(&req_wrap_obj)) { | ||
| 107 | + return StreamWriteResult{false, UV_EBUSY, nullptr, 0, {}}; | ||
| 108 | + } | ||
| 109 | + StreamReq::ResetObject(req_wrap_obj); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(GetAsyncWrap()); | ||
| 113 | + WriteWrap* req_wrap = CreateWriteWrap(req_wrap_obj); | ||
| 114 | + BaseObjectPtr<AsyncWrap> req_wrap_ptr(req_wrap->GetAsyncWrap()); | ||
| 115 | + | ||
| 116 | + err = DoWrite(req_wrap, bufs, count, send_handle); | ||
| 117 | + bool async = err == 0; | ||
| 118 | + | ||
| 119 | + if (!async) { | ||
| 120 | + req_wrap->Dispose(); | ||
| 121 | + req_wrap = nullptr; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + const char* msg = Error(); | ||
| 125 | + if (msg != nullptr) { | ||
| 126 | + if (req_wrap_obj | ||
| 127 | + ->Set(env->context(), | ||
| 128 | + env->error_string(), | ||
| 129 | + OneByteString(env->isolate(), msg)) | ||
| 130 | + .IsNothing()) { | ||
| 131 | + return StreamWriteResult{false, UV_EBUSY, nullptr, 0, {}}; | ||
| 132 | + } | ||
| 133 | + ClearError(); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + return StreamWriteResult{ | ||
| 137 | + async, err, req_wrap, total_bytes, std::move(req_wrap_ptr)}; | ||
| 138 | + } | ||
| 139 | + | ||
| 43 | 140 | template int StreamBase::WriteString<ASCII>( | |
| 44 | 141 | const FunctionCallbackInfo<Value>& args); | |
| 45 | 142 | template int StreamBase::WriteString<UTF8>( | |
@@ -680,6 +777,30 @@ StreamResource::~StreamResource() { | |||
| 680 | 777 | } | |
| 681 | 778 | } | |
| 682 | 779 | ||
| 780 | + void StreamResource::RemoveStreamListener(StreamListener* listener) { | ||
| 781 | + CHECK_NOT_NULL(listener); | ||
| 782 | + | ||
| 783 | + StreamListener* previous; | ||
| 784 | + StreamListener* current; | ||
| 785 | + | ||
| 786 | + // Remove from the linked list. | ||
| 787 | + // No loop condition because we want a crash if listener is not found. | ||
| 788 | + for (current = listener_, previous = nullptr;; | ||
| 789 | + previous = current, current = current->previous_listener_) { | ||
| 790 | + CHECK_NOT_NULL(current); | ||
| 791 | + if (current == listener) { | ||
| 792 | + if (previous != nullptr) | ||
| 793 | + previous->previous_listener_ = current->previous_listener_; | ||
| 794 | + else | ||
| 795 | + listener_ = listener->previous_listener_; | ||
| 796 | + break; | ||
| 797 | + } | ||
| 798 | + } | ||
| 799 | + | ||
| 800 | + listener->stream_ = nullptr; | ||
| 801 | + listener->previous_listener_ = nullptr; | ||
| 802 | + } | ||
| 803 | + | ||
| 683 | 804 | ShutdownWrap* StreamBase::CreateShutdownWrap( | |
| 684 | 805 | Local<Object> object) { | |
| 685 | 806 | auto* wrap = new SimpleShutdownWrap<AsyncWrap>(this, object); | |
@@ -694,4 +815,21 @@ WriteWrap* StreamBase::CreateWriteWrap( | |||
| 694 | 815 | return wrap; | |
| 695 | 816 | } | |
| 696 | 817 | ||
| 818 | + void StreamReq::Done(int status, const char* error_str) { | ||
| 819 | + AsyncWrap* async_wrap = GetAsyncWrap(); | ||
| 820 | + Environment* env = async_wrap->env(); | ||
| 821 | + if (error_str != nullptr) { | ||
| 822 | + v8::HandleScope handle_scope(env->isolate()); | ||
| 823 | + if (async_wrap->object() | ||
| 824 | + ->Set(env->context(), | ||
| 825 | + env->error_string(), | ||
| 826 | + OneByteString(env->isolate(), error_str)) | ||
| 827 | + .IsNothing()) { | ||
| 828 | + return; | ||
| 829 | + } | ||
| 830 | + } | ||
| 831 | + | ||
| 832 | + OnDone(status); | ||
| 833 | + } | ||
| 834 | + | ||
| 697 | 835 | } // namespace node | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,7 @@ class StreamReq { | |||
| 51 | 51 | ||
| 52 | 52 | // TODO(RaisinTen): Update the return type to a Maybe, so that we can indicate | |
| 53 | 53 | // if there is a pending exception/termination. | |
| 54 | - inline void Done(int status, const char* error_str = nullptr); | ||
| 54 | + void Done(int status, const char* error_str = nullptr); | ||
| 55 | 55 | inline void Dispose(); | |
| 56 | 56 | ||
| 57 | 57 | StreamBase* stream() const { return stream_; } | |
@@ -276,7 +276,7 @@ class StreamResource { | |||
| 276 | 276 | inline void PushStreamListener(StreamListener* listener); | |
| 277 | 277 | // Remove a listener, and, if this was the currently active one, | |
| 278 | 278 | // transfer ownership back to the previous listener. | |
| 279 | - inline void RemoveStreamListener(StreamListener* listener); | ||
| 279 | + void RemoveStreamListener(StreamListener* listener); | ||
| 280 | 280 | ||
| 281 | 281 | protected: | |
| 282 | 282 | // Call the current listener's OnStreamAlloc() method. | |
@@ -339,8 +339,7 @@ class StreamBase : public StreamResource { | |||
| 339 | 339 | // ShutdownWrap object (that was created in JS), or a new one will be created. | |
| 340 | 340 | // Returns 1 in case of a synchronous completion, 0 in case of asynchronous | |
| 341 | 341 | // completion, and a libuv error case in case of synchronous failure. | |
| 342 | - inline int Shutdown( | ||
| 343 | - v8::Local<v8::Object> req_wrap_obj = v8::Local<v8::Object>()); | ||
| 342 | + int Shutdown(v8::Local<v8::Object> req_wrap_obj = v8::Local<v8::Object>()); | ||
| 344 | 343 | ||
| 345 | 344 | // TODO(RaisinTen): Update the return type to a Maybe, so that we can indicate | |
| 346 | 345 | // if there is a pending exception/termination. | |
@@ -353,7 +352,7 @@ class StreamBase : public StreamResource { | |||
| 353 | 352 | // write is too large to finish synchronously. | |
| 354 | 353 | // If the return value indicates a synchronous completion, no callback will | |
| 355 | 354 | // be invoked. | |
| 356 | - inline StreamWriteResult Write( | ||
| 355 | + StreamWriteResult Write( | ||
| 357 | 356 | uv_buf_t* bufs, | |
| 358 | 357 | size_t count, | |
| 359 | 358 | uv_stream_t* send_handle = nullptr, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments