#line 666 "/home/travis/build/felix-lang/felix/src/packages/web.fdoc"
  include "web/__init__";
  
  publish """
  Container for server config and socket_t
  """
  class HTTPConnection {
    open ServerConfig;
    open Socket;
    open Logger;
    open Stream;
    open Socket;
    open TerminalIOByteStream[socket_t];
  
    struct http_connection {
      config:server_config;
      sock:socket_t;
      dirty:&bool;
    };
    fun _ctor_http_connection(config:server_config,sock:socket_t) = {
      var b:bool = false;
      return http_connection(config,sock,&b);
    }
    proc set_dirty(conn:http_connection,state:bool) {
      *conn.dirty = state;
    }
  
    noinline proc write(var conn:http_connection,var content:string) {
  
      var eof_flag = false;
      val content_len = content.len;
      conn.config.log(DEBUG,"Content Size:"+str(content_len));
      val chunk_size = size(1024);
      var chunks:size = content.len / chunk_size;
      var remainder = content.len % chunk_size;
      var base = size(0);
      for var i in size(1) upto chunks do
        conn.config.log(DEBUG,"Writing[sock="+str conn.sock+"]:"+str(base)+" to "+str(base+chunk_size));
        write_string(conn.sock,content.[base to (base+chunk_size)],&eof_flag);
        base = base + chunk_size;
  
      done
      if remainder > size(0) do
         conn.config.log(DEBUG,"Writing[sock="+str conn.sock+"] Remainder:"+str(base)+" to "+str(content_len));
         write_string(conn.sock,content.[base to ],&eof_flag);
      done
      set_dirty(conn,true);
    }
  
  }