Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: runtime/vm/json_stream.cc

Issue 1285673003: When no service response is requested, send null back to the service isolate so it can cleanup (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/service/message.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 6
7 #include "vm/dart_entry.h" 7 #include "vm/dart_entry.h"
8 #include "vm/debugger.h" 8 #include "vm/debugger.h"
9 #include "vm/json_stream.h" 9 #include "vm/json_stream.h"
10 #include "vm/message.h" 10 #include "vm/message.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 146 }
147 } 147 }
148 148
149 149
150 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 150 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
151 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 151 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
152 return reinterpret_cast<uint8_t*>(new_ptr); 152 return reinterpret_cast<uint8_t*>(new_ptr);
153 } 153 }
154 154
155 155
156 void JSONStream::PostNullReply(Dart_Port port) {
157 const Object& reply = Object::Handle(Object::null());
158 ASSERT(reply.IsNull());
159
160 uint8_t* data = NULL;
161 MessageWriter writer(&data, &allocator, false);
162 writer.WriteMessage(reply);
163 PortMap::PostMessage(new Message(port,
164 data,
165 writer.BytesWritten(),
166 Message::kNormalPriority));
167 }
168
169
156 void JSONStream::PostReply() { 170 void JSONStream::PostReply() {
157 Dart_Port port = reply_port(); 171 Dart_Port port = reply_port();
158 ASSERT(port != ILLEGAL_PORT); 172 ASSERT(port != ILLEGAL_PORT);
159 set_reply_port(ILLEGAL_PORT); // Prevent double replies. 173 set_reply_port(ILLEGAL_PORT); // Prevent double replies.
160 int64_t process_delta_micros = 0; 174 int64_t process_delta_micros = 0;
161 if (FLAG_trace_service) { 175 if (FLAG_trace_service) {
162 process_delta_micros = OS::GetCurrentTimeMicros() - setup_time_micros_; 176 process_delta_micros = OS::GetCurrentTimeMicros() - setup_time_micros_;
163 } 177 }
164 178
165 if (seq_.IsString()) { 179 if (seq_.IsString()) {
166 const String& str = String::Cast(seq_); 180 const String& str = String::Cast(seq_);
167 PrintProperty("id", str.ToCString()); 181 PrintProperty("id", str.ToCString());
168 } else if (seq_.IsInteger()) { 182 } else if (seq_.IsInteger()) {
169 const Integer& integer = Integer::Cast(seq_); 183 const Integer& integer = Integer::Cast(seq_);
170 PrintProperty64("id", integer.AsInt64Value()); 184 PrintProperty64("id", integer.AsInt64Value());
171 } else if (seq_.IsDouble()) { 185 } else if (seq_.IsDouble()) {
172 const Double& dbl = Double::Cast(seq_); 186 const Double& dbl = Double::Cast(seq_);
173 PrintProperty("id", dbl.value()); 187 PrintProperty("id", dbl.value());
174 } else if (seq_.IsNull()) { 188 } else if (seq_.IsNull()) {
175 // JSON-RPC 2.0 says that a request with a null ID shouldn't get a reply. 189 // JSON-RPC 2.0 says that a request with a null ID shouldn't get a reply.
190 PostNullReply(port);
176 return; 191 return;
177 } 192 }
178 buffer_.AddChar('}'); 193 buffer_.AddChar('}');
179 194
180 const String& reply = String::Handle(String::New(ToCString())); 195 const String& reply = String::Handle(String::New(ToCString()));
181 ASSERT(!reply.IsNull()); 196 ASSERT(!reply.IsNull());
182 197
183 uint8_t* data = NULL; 198 uint8_t* data = NULL;
184 MessageWriter writer(&data, &allocator, false); 199 MessageWriter writer(&data, &allocator, false);
185 writer.WriteMessage(reply); 200 writer.WriteMessage(reply);
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); 723 intptr_t len2 = OS::VSNPrint(p, len+1, format, args);
709 va_end(args); 724 va_end(args);
710 ASSERT(len == len2); 725 ASSERT(len == len2);
711 stream_->buffer_.AddChar('"'); 726 stream_->buffer_.AddChar('"');
712 stream_->AddEscapedUTF8String(p); 727 stream_->AddEscapedUTF8String(p);
713 stream_->buffer_.AddChar('"'); 728 stream_->buffer_.AddChar('"');
714 free(p); 729 free(p);
715 } 730 }
716 731
717 } // namespace dart 732 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/service/message.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698