@@ -208,7 +208,7 @@ class AgentImpl {
208
208
State state_;
209
209
node::Environment* parent_env_;
210
210
211
- uv_async_t data_written_;
211
+ uv_async_t * data_written_;
212
212
uv_async_t io_thread_req_;
213
213
inspector_socket_t * client_socket_;
214
214
blink::V8Inspector* inspector_;
@@ -316,31 +316,34 @@ AgentImpl::AgentImpl(Environment* env) : port_(0),
316
316
shutting_down_(false ),
317
317
state_(State::kNew ),
318
318
parent_env_(env),
319
+ data_written_(new uv_async_t ()),
319
320
client_socket_(nullptr ),
320
321
inspector_(nullptr ),
321
322
platform_(nullptr ),
322
323
dispatching_messages_(false ),
323
324
frontend_session_id_(0 ),
324
325
backend_session_id_(0 ) {
325
326
CHECK_EQ (0 , uv_sem_init (&start_sem_, 0 ));
326
- memset (&data_written_, 0 , sizeof (data_written_));
327
327
memset (&io_thread_req_, 0 , sizeof (io_thread_req_));
328
+ CHECK_EQ (0 , uv_async_init (env->event_loop (), data_written_, nullptr ));
329
+ uv_unref (reinterpret_cast <uv_handle_t *>(data_written_));
328
330
}
329
331
330
332
AgentImpl::~AgentImpl () {
331
- if (!inspector_)
332
- return ;
333
- uv_close (reinterpret_cast <uv_handle_t *>(&data_written_), nullptr );
333
+ auto close_cb = [](uv_handle_t * handle) {
334
+ delete reinterpret_cast <uv_async_t *>(handle);
335
+ };
336
+ uv_close (reinterpret_cast <uv_handle_t *>(data_written_), close_cb);
337
+ data_written_ = nullptr ;
334
338
}
335
339
336
340
bool AgentImpl::Start (v8::Platform* platform, int port, bool wait) {
337
341
auto env = parent_env_;
338
342
inspector_ = new V8NodeInspector (this , env, platform);
339
343
platform_ = platform;
340
- int err = uv_async_init (env->event_loop (), &data_written_, nullptr );
341
- CHECK_EQ (err, 0 );
342
344
343
- uv_unref (reinterpret_cast <uv_handle_t *>(&data_written_));
345
+ int err = uv_loop_init (&child_loop_);
346
+ CHECK_EQ (err, 0 );
344
347
345
348
port_ = port;
346
349
wait_ = wait;
@@ -516,7 +519,7 @@ void AgentImpl::PostIncomingMessage(const String16& message) {
516
519
platform_->CallOnForegroundThread (isolate,
517
520
new DispatchOnInspectorBackendTask (this ));
518
521
isolate->RequestInterrupt (InterruptCallback, this );
519
- uv_async_send (& data_written_);
522
+ uv_async_send (data_written_);
520
523
}
521
524
522
525
void AgentImpl::OnInspectorConnectionIO (inspector_socket_t * socket) {
@@ -558,7 +561,7 @@ void AgentImpl::DispatchMessages() {
558
561
inspector_->dispatchMessageFromFrontend (message);
559
562
}
560
563
}
561
- uv_async_send (& data_written_);
564
+ uv_async_send (data_written_);
562
565
dispatching_messages_ = false ;
563
566
}
564
567
0 commit comments