Advertisement
prova12

Untitled

Feb 22nd, 2018
3,416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 2.02 KB | None | 0 0
  1. module vibe.http.internal.http1;
  2.  
  3. import vibe.core.stream;
  4.  
  5.  
  6. /* TODO:
  7.  * decide how to manage InterfaceProxy
  8.  * allocators policy needs to be discussed
  9.  *
  10.  * NOTE:
  11.  * we cannot use scope (exit) connection.close() anymore,
  12.  * connection teardown is performed inside the callback
  13.  */
  14. private void handleHTTP1Connection(ConnectionStream)(ConnectionStream connection)
  15.     if (isConnectionStream!ConnectionStream)
  16. @safe {
  17.     InterfaceProxy!Stream http_stream = connection;
  18.     HTTPServerSettings settings;
  19.     bool keep_alive;
  20.     // get context
  21.     auto context = getDefaultHTTPContext(local_address);
  22.  
  23.     connection.tcpNoDelay = true;
  24.  
  25.     () @trusted {
  26.         import vibe.internal.utilallocator: RegionListAllocator;
  27.  
  28.         version (VibeManualMemoryManagement)
  29.             scope request_allocator = new RegionListAllocator!(shared(Mallocator), false)(1024, Mallocator.instance);
  30.         else
  31.             scope request_allocator = new RegionListAllocator!(shared(GCAllocator), true)(1024, GCAllocator.instance);
  32.  
  33.         // first request
  34.         connection.waitForDataAsync(
  35.             (status) {
  36.                 if (status) {
  37.                     handleRequest (http_stream, connection, context, settings,
  38.                         keep_alive, request_allocator);
  39.                 } else {
  40.                     logDebug("Client didn't send the initial request in a timely manner. Closing connection.");
  41.                     connection.close();
  42.                 }  
  43.             }, 10.seconds);
  44.  
  45.         // process further requests
  46.         connection.waitForDataAsync(
  47.             (status) {
  48.                 if (status) {
  49.                     handleRequest (http_stream, connection, context, settings,
  50.                         keep_alive, request_allocator);
  51.                 } else if (!keep_alive) {
  52.                     // teardown
  53.                     logTrace("No keep-alive - disconnecting client.")
  54.                     connection.close()
  55.                 }  
  56.             }, settings.keepAliveTimeout);
  57.     }  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement