Mercurial > spidermonkey-playground
comparison tcb.js @ 50:853f80bd3b4b
Added tentative profileMemory() server, which suspends the current JS runtime, creates a new one and runs a web server in it.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Wed, 24 Jun 2009 16:40:51 -0700 |
parents | aabc1dd92639 |
children | 8750e9ecf3af |
comparison
equal
deleted
inserted
replaced
49:45fd970860f2 | 50:853f80bd3b4b |
---|---|
231 | 231 |
232 if (getWrapper(wrapped) !== wrapper || | 232 if (getWrapper(wrapped) !== wrapper || |
233 getWrapper(getWrapper(wrapped)) !== null) | 233 getWrapper(getWrapper(wrapped)) !== null) |
234 throw new Error("Getting the wrapper doesn't work!"); | 234 throw new Error("Getting the wrapper doesn't work!"); |
235 | 235 |
236 dumpHeap(new Object()); | |
237 | |
238 var socket = new ServerSocket(); | 236 var socket = new ServerSocket(); |
239 try { | 237 try { |
240 var boop = {bind: socket.bind}; | 238 var boop = {bind: socket.bind}; |
241 boop.bind("127.0.0.1", 8080); | 239 boop.bind("127.0.0.1", 8080); |
242 } catch (e) {} | 240 } catch (e) {} |
243 socket.bind("127.0.0.1", 8080); | 241 |
244 socket.listen(); | 242 profileMemory(); |
245 | |
246 var NEWLINE = "\r\n"; | |
247 var DOUBLE_NEWLINE = NEWLINE + NEWLINE; | |
248 | |
249 function getHeaders(conn) { | |
250 var headers = ""; | |
251 while (1) { | |
252 var character = conn.recv(1); | |
253 if (character == null) | |
254 return null; | |
255 headers += character; | |
256 if (headers.indexOf(DOUBLE_NEWLINE) != -1) | |
257 return headers; | |
258 } | |
259 } | |
260 | |
261 while (1) { | |
262 var conn = socket.accept(); | |
263 | |
264 if (conn) { | |
265 var requestHeaders = getHeaders(conn); | |
266 if (requestHeaders == null) | |
267 continue; | |
268 //print("headers: " + uneval(requestHeaders)); | |
269 var toSend = "hello there."; | |
270 var headerLines = ["HTTP/1.0 200 OK", | |
271 "Content-Type: text/plain", | |
272 "Connection: close", | |
273 "Content-Length: " + toSend.length]; | |
274 var headers = headerLines.join("\r\n"); | |
275 var response = headers + DOUBLE_NEWLINE + toSend; | |
276 //print("response: " + uneval(response)); | |
277 conn.send(response); | |
278 conn.close(); | |
279 //print("response sent."); | |
280 } else | |
281 throw new Error("Unexpected: conn is " + conn); | |
282 } |