30 fprintf(stderr,
"Runtime type error: tcp_connect expects (string host, int port)\n");
37 int port = (int)
portv.i;
40 snprintf(portstr,
sizeof(portstr),
"%d", port);
41 struct addrinfo hints, *
res = NULL, *rp;
42 memset(&hints, 0,
sizeof(hints));
43 hints.ai_family = AF_UNSPEC;
44 hints.ai_socktype = SOCK_STREAM;
45 if (getaddrinfo(host, portstr, &hints, &
res) == 0) {
46 for (rp =
res; rp != NULL; rp = rp->ai_next) {
47 int s = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
49 if (connect(
s, rp->ai_addr, rp->ai_addrlen) == 0) {
55 if (
res) freeaddrinfo(
res);
push_value(vm, make_int(fd > 0 ? fd :0))
Tagged union representing a Fun value.
char * value_to_string_alloc(const Value *v)
Allocate a printable C string for a Value.
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.