Imported connection & inet code from http-conn branch