+ /* Create a new `cnode' for each connection. Otherwise we cannot determine
+ * which RPC call a message belongs to. */
+ status = erl_connect_init (connection_number, conf_cookie,
+ /* creation = */ 0);
+ if (!status) /* Yes, it's this way around in this case ... {{{ */
+ {
+ char errbuf[1024];
+ pthread_mutex_unlock (&connection_lock);
+ ERROR ("erlang plugin: erl_connect_init failed: %s",
+ sstrerror (erl_errno, errbuf, sizeof (errbuf)));
+ sfree (ci);
+ erl_free_term (eterm_cb);
+ status = send_error (cinfo->fd, req->from, "erl_connect failed.");
+ return (status);
+ } /* }}} */
+
+ ci->fd = erl_connect (cinfo->conn.nodename);
+ if (ci->fd < 0) /* {{{ */
+ {
+ char errbuf[1024];
+ pthread_mutex_unlock (&connection_lock);
+ ERROR ("erlang plugin: erl_connect(%s) failed: %s",
+ cinfo->conn.nodename,
+ sstrerror (erl_errno, errbuf, sizeof (errbuf)));
+ sfree (ci);
+ erl_free_term (eterm_cb);
+ status = send_error (cinfo->fd, req->from, "erl_connect failed.");
+ return (status);
+ } /* }}} */
+
+ pthread_mutex_unlock (&connection_lock);
+
+ ci->fun = eterm_cb;
+
+ memset (&ud, 0, sizeof (ud));
+ ud.data = ci;
+ ud.free_func = (void (*) (void *)) ce_free_callback_info;
+
+ ssnprintf (callback_name, sizeof (callback_name), "erlang:%i",
+ connection_number);
+
+ status = plugin_register_complex_read (callback_name,
+ ce_read, /* interval = */ NULL, &ud);
+ if (status == 0)
+ status = send_atom (cinfo->fd, req->from, "success");
+ else
+ status = send_error (cinfo->fd, req->from,
+ "plugin_register_complex_read failed.");
+
+ return (status);