int main(int argc, char **argv) #endif { struct hostent *hp; MyTimeval start, stop; int i, fd, ires, tries; CORBA_Environment *env; char *this_node_name = NULL; char *peer_node = NULL; char *cookie = NULL; char host[HOSTNAMESZ + 1]; char this_node[NODENAMESZ + 1]; erlang_msg msg; int status, loop; #ifdef __WIN32__ WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD(2, 0); if (WSAStartup(wVersionRequested, &wsaData) != 0) { fprintf(stderr, "Could not load winsock2 v2.0 compatible DLL"); exit(1); } #endif progname = argv[0]; host[HOSTNAMESZ] = '\0'; if (gethostname(host, HOSTNAMESZ) < 0) { fprintf(stderr, "Can't find own hostname\n"); done(1); } if ((hp = gethostbyname(host)) == 0) { fprintf(stderr, "Can't get ip address for host %s\n", host); done(1); } for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-help") == 0) { usage(); done(0); } else if (strcmp(argv[i], "-this-node-name") == 0) { i++; this_node_name = argv[i]; } else if (strcmp(argv[i], "-peer-node") == 0) { i++; peer_node = argv[i]; } else if (strcmp(argv[i], "-cookie") == 0) { i++; cookie = argv[i]; } else { fprintf(stderr, "Error : invalid argument \"%s\"\n", argv[i]); usage(); done(1); } } if (this_node_name == NULL || peer_node == NULL || cookie == NULL) { fprintf(stderr, "Error: missing option\n"); usage(); done(1); } /* Behead hostname at first dot */ for (i=0; host[i] != '\0'; i++) { if (host[i] == '.') { host[i] = '\0'; break; } } sprintf(this_node, "%s@%s", this_node_name, host); fprintf(stderr, "c_server: this node: \"%s\"\n", this_node); fprintf(stderr, "c_server: peer node: \"%s\"\n", peer_node); /* initialize erl_interface */ erl_init(NULL, 0); for (tries = 0; tries < MAXTRIES; tries++) { /* connect to peer node */ ires = erl_connect_xinit(host, this_node_name, this_node, (struct in_addr *)*hp->h_addr_list, cookie, 0); fprintf(stderr, "c_server: erl_connect_xinit(): %d\n", ires); fd = erl_connect(peer_node); fprintf(stderr, "c_server: erl_connect(): %d\n", fd); if (fd >= 0) break; fprintf(stderr, "c_server: cannot connect, retrying\n"); } if (fd < 0) { fprintf(stderr, "c_server: cannot connect, exiting\n"); done(1); } env = CORBA_Environment_alloc(INBUFSZ, OUTBUFSZ); env->_fd = fd; status = 1; loop = 1; my_gettimeofday(&start); while (status >= 0 && loop > 0) { status = ei_receive_encoded(env->_fd, &env->_inbuf, &env->_inbufsz, &msg, &env->_iin); switch(status) { case ERL_SEND: case ERL_REG_SEND: /* get result */ m_i__switch(NULL, env); switch(env->_major) { case CORBA_NO_EXCEPTION: break; case CORBA_SYSTEM_EXCEPTION: fprintf(stderr, "Request failure, reason : %s\n", (char *) CORBA_exception_value(env)); CORBA_exception_free(env); break; default: /* Should not happen */ CORBA_exception_free(env); break; } /* send back result data */ if (env->_iout > 0) ei_send_encoded(env->_fd, &env->_caller, env->_outbuf, env->_iout); loop = 0; break; case ERL_TICK: break; default: if (status < 0) { fprintf(stderr, "Status negative: %d\n", status); loop = 0; } break; } } my_gettimeofday(&stop); showtime(&start, &stop); erl_close_connection(fd); CORBA_free(env->_inbuf); CORBA_free(env->_outbuf); CORBA_free(env); if (status < 0) done(-status); else done(0); }
int main(int argc, char **argv) #endif { struct hostent *hp; erlang_pid pid; MyTimeval start, stop; int i, fd, ires, tres; IC_Env *env; int tries = 0; char *this_node_name = NULL; char *peer_node = NULL; char *peer_process_name = NULL; char *cookie = NULL; char host[HOSTNAMESZ + 1]; TestFunc test_func = NULL; TestCase *test_case; char *test_case_name = NULL; #ifdef __WIN32__ WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD(2, 0); if (WSAStartup(wVersionRequested, &wsaData) != 0) { fprintf(stderr, "Could not load winsock2 v2.0 compatible DLL"); exit(1); } #endif progname = argv[0]; host[HOSTNAMESZ] = '\0'; if (gethostname(host, HOSTNAMESZ) < 0) { fprintf(stderr, "Can't find own hostname\n"); done(1); } if ((hp = gethostbyname(host)) == 0) { fprintf(stderr, "Can't get ip address for host %s\n", host); done(1); } for (i = 1; i < argc; i++) { if (cmp_str(argv[i], "-help")) { usage(); done(0); } else if (cmp_str(argv[i], "-this-node-name")) { i++; this_node_name = argv[i]; } else if (cmp_str(argv[i], "-peer-node")) { i++; peer_node = argv[i]; } else if (cmp_str(argv[i], "-peer-process-name")) { i++; peer_process_name = argv[i]; } else if (cmp_str(argv[i], "-cookie")) { i++; cookie = argv[i]; } else if (cmp_str(argv[i], "-test-case")) { i++; test_case_name = argv[i]; } else { fprintf(stderr, "Error : invalid argument \"%s\"\n", argv[i]); usage(); done(1); } } if (this_node_name == NULL || peer_node == NULL || test_case_name == NULL || peer_process_name == NULL || cookie == NULL) { fprintf(stderr, "Error: missing option\n"); usage(); done(1); } test_case = test_cases; while (test_case->func) { if (cmp_str(test_case->name, test_case_name)) { test_func = test_case->func; break; } test_case++; } if (test_func == NULL) { fprintf(stderr, "Error: illegal test case: \"%s\"\n", test_case_name); done(1); } /* Behead hostname at first dot */ for (i=0; host[i] != '\0'; i++) { if (host[i] == '.') { host[i] = '\0'; break; } } sprintf(this_node, "%s@%s", this_node_name, host); fprintf(stderr, "c_client: this node: \"%s\"\n", this_node); fprintf(stderr, "c_client: peer node: \"%s\"\n", peer_node); fprintf(stderr, "c_client: test case: \"%s\"\n", test_case_name); fprintf(stderr, "c_client: starting\n"); /* initialize erl_interface */ erl_init(NULL, 0); for (tries = 0; tries < MAXTRIES; tries++) { /* connect to erlang node */ ires = erl_connect_xinit(host, this_node_name, this_node, (struct in_addr *)*hp->h_addr_list, cookie, 0); fprintf(stderr, "c_client: erl_connect_xinit(): %d\n", ires); fd = erl_connect(peer_node); fprintf(stderr, "c_client: erl_connect(): %d\n", fd); if (fd >= 0) break; fprintf(stderr, "c_client: cannot connect, retrying\n"); } if (fd < 0) { fprintf(stderr, "c_client: cannot connect, exiting\n"); done(1); } env = CORBA_Environment_alloc(INBUFSZ, OUTBUFSZ); env->_fd = fd; strcpy(env->_regname, peer_process_name); env->_to_pid = NULL; env->_from_pid = &pid; strcpy(pid.node, this_node); pid.num = fd; pid.serial = 0; pid.creation = 0; my_gettimeofday(&start); tres = test_func(env); /* Call test case */ my_gettimeofday(&stop); showtime(&start, &stop); erl_close_connection(fd); printf("c_client: env->_inbuf before : %d\n", INBUFSZ); printf("c_client: env->_outbuf before : %d\n", OUTBUFSZ); printf("c_client: env->_inbuf after : %d\n", env->_inbufsz); printf("c_client: env->_outbuf after : %d\n", env->_outbufsz); CORBA_free(env->_inbuf); CORBA_free(env->_outbuf); CORBA_free(env); done(tres); }
static void server_loop(int sd, int epmd_fd) { ErlConnect conn; erlang_msg msg; int status=1; CORBA_Environment *env; /* Create and init CORBA_Environment */ env = CORBA_Environment_alloc(INBUFSZ,OUTBUFSZ); while (status >= 0) { status = 1; if ((env->_fd = erl_accept(sd,&conn)) < 0) { /* error */ fprintf(stderr,"Accept failed: %s\n",strerror(errno)); } else { /* connection */ fprintf(stderr,"Accepted connection from %s\n",conn.nodename); while (status >= 0) { /* write message to buffer */ status = ei_receive_encoded(env->_fd, &env->_inbuf, &env->_inbufsz, &msg, &env->_iin); switch(status) { case ERL_SEND: case ERL_REG_SEND : /* do transaction with fd */ rmod_random__switch(NULL,env); switch(env->_major) { case CORBA_NO_EXCEPTION: /* Success */ break; case CORBA_SYSTEM_EXCEPTION: /* System exception */ printf("Request failure, reason : %s\n",(char *) CORBA_exception_value(env)); CORBA_exception_free(env); break; default: /* Should not come here */ CORBA_exception_free(env); break; } /* send outdata */ if (env->_iout > 0) ei_send_encoded(env->_fd,&env->_caller,env->_outbuf,env->_iout); break; case ERL_TICK : break; default : /* < 0 */ printf("Connection terminated\n"); break; } } } status=0; /* restart */ } /* close file descriptors */ terminate(&env->_fd, &sd, &epmd_fd); /* Free env & buffers */ CORBA_free(env->_inbuf); CORBA_free(env->_outbuf); CORBA_free(env); }
int main() { double result=0; int i=0; erlang_pid pid; CORBA_Environment *env; ei_cnode ec; /* Create and init CORBA_Environment */ env = CORBA_Environment_alloc(INBUFSZ,OUTBUFSZ); /* Initiating the connection */ ei_connect_init(&ec, "c47", COOKIE, 0); /* Initiating pid*/ strcpy(pid.node, CLNODE); pid.num = 99; pid.serial = 0; pid.creation = 0; /* Fixing environment variable */ env->_fd = ei_connect(&ec, SNODE); strcpy(env->_regname,SERVER); env->_to_pid = NULL; env->_from_pid = &pid; if (env->_fd < 0) { fprintf(stderr,"Error : Cannot connect to Server\n"); /* Free env & buffers */ CORBA_free(env->_inbuf); CORBA_free(env->_outbuf); CORBA_free(env); exit(1); } /* Calling the init function */ rmod_random_init(NULL, 1, 2, 3, env); switch(env->_major) { case CORBA_NO_EXCEPTION: /* Success */ printf("Init complete !\n"); break; case CORBA_SYSTEM_EXCEPTION: /* System exception */ printf("Init call failure, reason : %s\n",(char *) CORBA_exception_value(env)); CORBA_exception_free(env); client_exit(env); default: /* Should not come here */ client_exit(env); } /* Calling the produce function */ for(i=1; i<=10; i++) { result = rmod_random_produce(NULL, env); switch(env->_major) { case CORBA_NO_EXCEPTION: /* Success */ break; case CORBA_SYSTEM_EXCEPTION: /* System exception */ printf("Init call failure, reason : %s\n",(char *) CORBA_exception_value(env)); CORBA_exception_free(env); client_exit(env); default: /* Should not come here */ client_exit(env); } printf("the random number nr%d is %f\n",i,result); } /* Closing the connection */ close(env->_fd); /* Free env & buffers */ CORBA_free(env->_inbuf); CORBA_free(env->_outbuf); CORBA_free(env); return 0; }
int main(){ double result=0; int i=0; int error = 0; erlang_pid pid; char host[HOSTNAMESZ]; char server_node[HOSTNAMESZ]; char client_node[HOSTNAMESZ]; CORBA_Environment *env; /* Initiate names */ #ifdef __WIN32__ WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD(1, 1); if ((error = WSAStartup(wVersionRequested, &wsaData))) { fprintf(stderr,"Can't initialize windows sockets: %d",error); return 0; } #endif error = gethostname(host,HOSTNAMESZ); if (error) { #ifdef __WIN32__ fprintf(stderr,"can't find own hostname (error = %ld) !\n",WSAGetLastError()); #else /* not __WIN32__ */ fprintf(stderr,"can't find own hostname !\n"); #endif } sprintf(client_node,"%s@%s",CLNODENAME,host); sprintf(server_node,"%s@%s",SNODENAME,host); /* Create and init CORBA_Environment */ env = CORBA_Environment_alloc(INBUFSZ,OUTBUFSZ); /* Initiating the connection */ erl_init(NULL,0); erl_connect_init(50,COOKIE,0); /* Initiating pid*/ strcpy(pid.node,client_node); pid.num = 99; pid.serial = 0; pid.creation = 0; /* Fixing environment variable */ env->_fd=erl_connect(server_node); strcpy(env->_regname,SREGNAME); env->_to_pid = NULL; env->_from_pid = &pid; if (env->_fd < 0) { fprintf(stderr,"Error : Cannot connect to Server\n"); /* Free env & buffers */ CORBA_free(env->_inbuf); CORBA_free(env->_outbuf); CORBA_free(env); exit(1); } /* Calling the init function */ rmod_random_init(NULL, 1, 2, 3, env); switch(env->_major) { case CORBA_NO_EXCEPTION: /* Success */ printf("Init complete !\n"); break; case CORBA_SYSTEM_EXCEPTION: /* System exception */ printf("Init call failure, reason : %s\n",(char *) CORBA_exception_value(env)); CORBA_exception_free(env); client_exit(env); default: /* Should not come here */ client_exit(env); } /* Calling the produce function */ for(i=1; i<=10; i++) { result = rmod_random_produce(NULL, env); switch(env->_major) { case CORBA_NO_EXCEPTION: /* Success */ break; case CORBA_SYSTEM_EXCEPTION: /* System exception */ printf("Init call failure, reason : %s\n",(char *) CORBA_exception_value(env)); CORBA_exception_free(env); client_exit(env); default: /* Should not come here */ client_exit(env); } printf("the random number nr%d is %f\n",i,result); } /* Closing the connection */ erl_close_connection(env->_fd); /* Free env & buffers */ CORBA_free(env->_inbuf); CORBA_free(env->_outbuf); CORBA_free(env); return 0; }