host
on port port
# Creates a socket connection to host `host` on port `port`
init connect(host: String, port: Int)
do
native = new NativeSocket.socket(new NativeSocketAddressFamilies.af_inet,
new NativeSocketTypes.sock_stream, new NativeSocketProtocolFamilies.pf_unspec)
if native.address_is_null then
closed = true
return
end
if not native.setsockopt(new NativeSocketOptLevels.socket, new NativeSocketOptNames.reuseaddr, 1) then
closed = true
return
end
var hostent = sys.gethostbyname(host.to_cstring)
if hostent.address_is_null then
# Error in name lookup
last_error = new IOError.from_h_errno
closed = true
return
end
addrin = new NativeSocketAddrIn
addrin.fill_from_hostent hostent
addrin.port = port
address = addrin.address.to_s
init(addrin.port, hostent.h_name.to_s)
closed = not internal_connect
if closed then
# Connection failed
last_error = new IOError.from_errno
end
end
lib/socket/socket.nit:70,2--106,4