This commit is contained in:
niamtokik
2020-06-20 07:13:19 +00:00
parent dadba5cd45
commit 0b3e43d4c4
2 changed files with 36 additions and 10 deletions

View File

@@ -73,6 +73,11 @@ process_new(uv_loop_t *loop) {
return uv_run(loop, UV_RUN_DEFAULT);
}
void action(uv_tcp_t* handle) {
printf("receive data");
}
/* main function
*
*/
@@ -82,28 +87,32 @@ main(int argc, char *argv[]) {
(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);
*/
/* create a tcp structure and init it */
uv_tcp_t server;
uv_tcp_init(loop, &server);
/* connect to erlang node */
ei_cnode ec;
ei_connect_init(&ec, node_name, cookie, creation);
/* create the connection to the server */
int sockfd;
if ((sockfd = ei_connect(&ec, node_target)) < 0)
fprintf(stderr, "ERROR: ei_connect failed\n");
/* open the tcp socket with */
uv_tcp_open(&server, sockfd);
/* create an erlang pid
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";
@@ -113,9 +122,12 @@ main(int argc, char *argv[]) {
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);
// uv_tcp_close_reset(server, close_cb);
close(sockfd);
close_loop(loop);
return 0;
}

View File

@@ -17,3 +17,17 @@ struct process_baton {
char **arguments;
char **environment;
};
enum message_tag {
PING,
PONG,
TEST,
START,
STATUS,
STOP,
KILL,
};
struct message {
enum message_tag tag;
};