remote_node.c
changeset 9 fb6632e6c1bb
child 23 31307efd7e78
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/remote_node.c	Fri Jun 06 03:24:55 2008 +0300
@@ -0,0 +1,51 @@
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <assert.h>
+
+#include "common.h"
+#include "render_remote.h"
+#include "remote_node.h"
+
+int remote_node_init (struct remote_node *node_info, const char *hostname, const char *portname) {
+    // zero out the struct
+    memset(node_info, 0, sizeof(*node_info));
+
+    // XXX: currently, this is hardcoded to one, but should be automagically discovered
+    node_info->parallel_renders = 1;
+
+    // lookup the host:port
+    portname = portname ? portname : RENDER_PORT_NAME;
+    
+    // XXX: stat it and look for a PF_UNIX socket!
+    
+    // PF_INET
+    
+    struct addrinfo hints, *results, *result;
+
+    memset(&hints, 0, sizeof(hints));
+    hints.ai_socktype = SOCK_STREAM;
+    hints.ai_flags = AI_ADDRCONFIG;     // attempt to get a working address as the first result
+
+    int err = getaddrinfo(hostname, portname, &hints, &results);
+    
+    if (err != 0) {
+        error("getaddrinfo: [%s].%s: %s", hostname, portname, gai_strerror(err));
+
+        return -1;
+    }
+    
+    assert(results != NULL); // we expect at least one result
+
+    // XXX: only use the first result, discard the rest.
+    result = results;
+    memcpy(&node_info->addr, result->ai_addr, result->ai_addrlen);
+
+    freeaddrinfo(results);
+    
+    // success!
+    node_info->valid = 1;
+    return 0;
+}
+