set to erlang23, and can send a message. libuv is not thread safe, and it will be a bit... complicated to do what I want to do
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
# Makefile - OpenBSD pmake implementation
|
||||
######################################################################
|
||||
|
||||
ERLANG_VERSION ?= 22
|
||||
ERL_INTERFACE_VERSION ?= 3.13.2
|
||||
ERLANG_VERSION ?= 23
|
||||
ERL_INTERFACE_VERSION ?= 4.0
|
||||
|
||||
ERLANG_PATH = /usr/local/lib/erlang$(ERLANG_VERSION)
|
||||
|
||||
@@ -15,7 +15,7 @@ INCLUDE_LIBS += -L$(ERLANG_PATH)/usr/lib
|
||||
INCLUDE_LIBS += -L/usr/local/lib/
|
||||
INCLUDE_LIBS += -L/usr/lib
|
||||
|
||||
LIBS += -luv -lei -lerl_interface
|
||||
LIBS += -luv -lei
|
||||
|
||||
CFLAGS += -g $(INCLUDES) $(INCLUDE_LIBS) $(LIBS)
|
||||
LDFLAGS += $(INCLUDES) $(INCLUDE_LIBS) $(LIBS)
|
||||
|
||||
112
c_src/erluv.c
112
c_src/erluv.c
@@ -1,11 +1,12 @@
|
||||
/* copyright (c) 2020 Mathieu Kerjouan <contact@steepath.eu>
|
||||
*
|
||||
*
|
||||
* erluv -n NODE_NAME -t TARGET_NODE -c COOKIE -i ID
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <ei.h>
|
||||
#include <erl_interface.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
@@ -20,15 +21,102 @@ extern char cookie[];
|
||||
extern char node_name[];
|
||||
extern char node_target[];
|
||||
|
||||
/* main function */
|
||||
int
|
||||
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(;;);
|
||||
void
|
||||
usage() {
|
||||
printf("usage: erluv ...\n");
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
create_loop(uv_loop_t *loop) {
|
||||
/* create the loop */
|
||||
loop = malloc(sizeof(uv_loop_t));
|
||||
uv_loop_init(loop);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
close_loop(uv_loop_t *loop) {
|
||||
uv_loop_close(uv_default_loop());
|
||||
free(loop);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
process_on_exit(uv_process_t* p, int64_t exit_status, int term_signal) {
|
||||
fprintf(stderr, "process %d exited\n", p->pid);
|
||||
}
|
||||
|
||||
int
|
||||
process_new(uv_loop_t *loop) {
|
||||
uv_process_t child_req = {0};
|
||||
uv_process_options_t options = {0};
|
||||
|
||||
char *name = "ls";
|
||||
char *args[3] = { "ls", "/", NULL };
|
||||
char *env[] = { NULL };
|
||||
|
||||
options.exit_cb = process_on_exit;
|
||||
options.file = name;
|
||||
options.args = args;
|
||||
options.env = env;
|
||||
|
||||
int r = uv_spawn(loop, &child_req, &options);
|
||||
if (r) {
|
||||
fprintf(stderr, "%s\n", uv_strerror(r));
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Launched process with ID %d\n", child_req.pid);
|
||||
}
|
||||
|
||||
return uv_run(loop, UV_RUN_DEFAULT);
|
||||
}
|
||||
|
||||
/* main function
|
||||
*
|
||||
*/
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
/* init default variable */
|
||||
(void)init();
|
||||
|
||||
/* create the loop */
|
||||
/*
|
||||
uv_loop_t *loop;
|
||||
create_loop(loop);
|
||||
uv_process_t child_req = {0};
|
||||
uv_process_options_t options = {0};
|
||||
uv_spawn(loop, &child_req, &options);
|
||||
close_loop(loop);
|
||||
*/
|
||||
|
||||
/* connect to erlang node */
|
||||
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");
|
||||
|
||||
erlang_pid pid;
|
||||
ei_make_pid(&ec, &pid);
|
||||
erlang_pid *p = ei_self(&ec);
|
||||
printf("%d, %d, %d\n", p->num, p->serial, p->creation);
|
||||
printf("%d, %d, %d\n", pid.num, pid.serial, pid.creation);
|
||||
|
||||
char *message = "my_message";
|
||||
char *process_name = "ttt";
|
||||
|
||||
ei_x_buff x;
|
||||
ei_x_new_with_version(&x);
|
||||
ei_x_encode_string(&x, message);
|
||||
ei_reg_send(&ec, sockfd, process_name, x.buff, x.index);
|
||||
ei_x_free(&x);
|
||||
//SleepEx(100);
|
||||
shutdown(sockfd, 1);
|
||||
close(sockfd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
#define COOKIE_SIZE 255
|
||||
#define NODE_NAME_SIZE 255
|
||||
#define PROCESS_NAME 255
|
||||
|
||||
/* interfaces */
|
||||
int init_cookie(void);
|
||||
@@ -10,3 +11,9 @@ int init_node_name(void);
|
||||
int init_id(void);
|
||||
int init_creation(void);
|
||||
void init(void);
|
||||
|
||||
struct process_baton {
|
||||
char *name;
|
||||
char **arguments;
|
||||
char **environment;
|
||||
};
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <ei.h>
|
||||
#include <erl_interface.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
@@ -111,3 +110,11 @@ init() {
|
||||
|
||||
ei_init();
|
||||
}
|
||||
|
||||
/* process_create
|
||||
*
|
||||
*/
|
||||
void
|
||||
process_create() {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user