create a connection based on erlang22

This commit is contained in:
niamtokik
2020-06-18 20:03:58 +00:00
parent 51d5648cc3
commit 7b69df5190
3 changed files with 28 additions and 5 deletions

View File

@@ -2,16 +2,16 @@
# Makefile - OpenBSD pmake implementation
######################################################################
ERLANG_VERSION ?= 21
ERL_INTERFACE_VERSION ?= 3.10.4
ERLANG_VERSION ?= 22
ERL_INTERFACE_VERSION ?= 3.13.2
ERLANG_PATH = /usr/local/lib/erlang$(ERLANG_VERSION)
INCLUDES += -I$(ERLANG_PATH)/lib/erl_interface-$(ERL_INTERFACE_VERSION)/include
INCLUDES += -I$(ERLANG_PATH)/usr/include
INCLUDES += -I/usr/local/include
INCLUDES += -I/usr/include
INCLUDE_LIBS += -L$(ERLANG_PATH)/lib/erl_interface-$(ERL_INTERFACE_VERSION)/lib
INCLUDE_LIBS += -L$(ERLANG_PATH)/usr/lib
INCLUDE_LIBS += -L/usr/local/lib/
INCLUDE_LIBS += -L/usr/lib
@@ -23,7 +23,7 @@ LDFLAGS += $(INCLUDES) $(INCLUDE_LIBS) $(LIBS)
all: erluv erluv_test
liberluv.o:
$(CC) $(CFLAGS) -c liberluv.c -o $@
$(CC) $(INCLUDES) -c liberluv.c -o $@
erluv: liberluv.o
$(CC) $(CFLAGS) liberluv.o $@.c -o $@

View File

@@ -18,6 +18,7 @@ extern short creation;
extern int id;
extern char cookie[];
extern char node_name[];
extern char node_target[];
/* main function */
int
@@ -25,5 +26,9 @@ main(int argc, char *argv[]) {
(void)init();
ei_cnode ec;
ei_connect_init(&ec, node_name, cookie, creation);
int sockfd;
if ((sockfd = ei_connect(&ec, node_target)) < 0)
fprintf(stderr, "ERROR: ei_connect failed\n");
for(;;);
}

View File

@@ -19,6 +19,7 @@ short creation = 0;
int id = 1;
char cookie[COOKIE_SIZE];
char node_name[NODE_NAME_SIZE];
char node_target[NODE_NAME_SIZE];
/* set the node cookie from environment */
int
@@ -48,6 +49,20 @@ init_node_name() {
return 0;
}
int
init_node_target() {
if (getenv("NODE_TARGET") == NULL) {
return 1;
}
fprintf(stdout, "set node_target");
/* the last char must be set to 0. */
strncpy(node_target, getenv("NODE_TARGET"), NODE_NAME_SIZE-1);
fprintf(stdout, "%s\n", node_target);
return 0;
}
/* set the node id from environment
*/
int
@@ -90,6 +105,9 @@ init() {
init_cookie();
init_node_name();
init_node_target();
init_id();
init_creation();
ei_init();
}