static void ei_x_print_msg(ei_x_buff *buf, erlang_pid *pid, int send) { char *pbuf = NULL; int i = 0; ei_x_buff pidbuf; ei_x_new(&pidbuf); ei_x_encode_pid(&pidbuf, pid); ei_s_print_term(&pbuf, pidbuf.buff, &i); ei_x_print_reg_msg(buf, pbuf, send); free(pbuf); }
int ei_sendto(ei_cnode * ec, int fd, struct erlang_process *process, ei_x_buff * buf) { int ret; if (process->type == ERLANG_PID) { ret = ei_send(fd, &process->pid, buf->buff, buf->index); #ifdef EI_DEBUG ei_x_print_msg(buf, &process->pid, 1); #endif } else if (process->type == ERLANG_REG_PROCESS) { ret = ei_reg_send(ec, fd, process->reg_name, buf->buff, buf->index); #ifdef EI_DEBUG ei_x_print_reg_msg(buf, process->reg_name, 1); #endif } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid process type!\n"); /* wuh-oh */ ret = -1; } return ret; }
/* function to spawn a process on a remote node */ int ei_spawn(struct ei_cnode_s *ec, int sockfd, erlang_ref * ref, char *module, char *function, int argc, char **argv) { int i; ei_x_buff buf; ei_x_new_with_version(&buf); ei_x_encode_tuple_header(&buf, 3); ei_x_encode_atom(&buf, "$gen_call"); ei_x_encode_tuple_header(&buf, 2); ei_x_encode_pid(&buf, ei_self(ec)); ei_init_ref(ec, ref); ei_x_encode_ref(&buf, ref); ei_x_encode_tuple_header(&buf, 5); ei_x_encode_atom(&buf, "spawn"); ei_x_encode_atom(&buf, module); ei_x_encode_atom(&buf, function); /* argument list */ if (argc < 0) { ei_x_encode_list_header(&buf, argc); for (i = 0; i < argc && argv[i]; i++) { ei_x_encode_atom(&buf, argv[i]); } } ei_x_encode_empty_list(&buf); /*if (i != argc - 1) { */ /* horked argument list */ /*} */ ei_x_encode_pid(&buf, ei_self(ec)); /* should really be a valid group leader */ #ifdef EI_DEBUG ei_x_print_reg_msg(&buf, "net_kernel", 1); #endif return ei_reg_send(ec, sockfd, "net_kernel", buf.buff, buf.index); }