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