var socket = use('socket')
var time   = use('time')
var blob   = use('blob')

var data       = new blob
var start_time = time.number()

var host = arg[0]
var path = arg[1] || '/'

$_.start(e => {
  send(e.actor, { op: 'get', domain: host, port: 80}, addrs => {
    log.console(json.encode(addrs[0]))
  })
}, 'dig')
/*
var addrs = socket.getaddrinfo(host, '80')
var addr  = addrs[0]
log.console(json.encode(addrs))
var sock = socket.socket()
socket.connect(sock, addr)

var req = `GET ${path} HTTP/1.1\r\nHost: ${host}\r\nConnection: close\r\n\r\n`
socket.send(sock, req)

var chunk_size = 4096

function get_chunk()
{
  var chunk = socket.recv(sock, chunk_size)

  if (chunk.length > 0) {
    log.console('got chunk size ' + chunk.length/8 + ' bytes')  
    data.write_blob(chunk)
    get_chunk()
  } else {
    log.console(`http GET took ${time.number() - start_time}`)
    log.console(`total length is ${data.length}`)
    stone(data)
    log.console(text(data))
    log.console(`time taken: ${time.number()-start_time}`)
    $_.stop()
  }
}

get_chunk()
*/