コード例 #1
0
ファイル: c_server.c プロジェクト: aronisstav/otp
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 + 1) < 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); 
}
コード例 #2
0
ファイル: cpolld.c プロジェクト: sizeof/c-poller
void *cnode_run()
{
    int fd;                                  /* fd to Erlang node */
    int got;                                 /* Result of receive */
    unsigned char buf[BUFSIZE];              /* Buffer for incoming message */
    ErlMessage emsg;                         /* Incoming message */
 
    ETERM *uid, *msg;
 
    erl_init(NULL, 0);
 
    if (erl_connect_init(1, "secretcookie", 0) == -1)
        erl_err_quit("erl_connect_init");
 
    if ((fd = erl_connect("httpdmaster@localhost")) < 0)
        erl_err_quit("erl_connect");
 
    fprintf(stderr, "Connected to httpdmaster@localhost\n\r");
 
    struct evbuffer *evbuf;
 
    while (1) {
        got = erl_receive_msg(fd, buf, BUFSIZE, &emsg);
        if (got == ERL_TICK) {
            continue;
        } else if (got == ERL_ERROR) {
            fprintf(stderr, "ERL_ERROR from erl_receive_msg.\n");
            break;
        } else {
            if (emsg.type == ERL_REG_SEND) {
                fprintf(stderr, "type of emsg is ERL_REG_SEND\n");
                // get uid and body data from eg: {123, <<"Hello">>}
                uid = erl_element(1, emsg.msg);
                msg = erl_element(2, emsg.msg);
                char *token = (char *) ERL_BIN_PTR(uid);
                char *body = (char *) ERL_BIN_PTR(msg);
                int body_len = ERL_BIN_SIZE(msg);
                char *cached = fetch_memcached(token);
                int userid = atoi(cached);
                fprintf(stderr, "memc: %d\n\r", userid);
                if(clients[userid]){
                    fprintf(stderr, "Sending %d bytes to token %s\n", body_len, token);                
                    evbuf = evbuffer_new();
                    evbuffer_add(evbuf, (const void*)body, (size_t) body_len);
                    evhttp_send_reply_chunk(clients[userid], evbuf);
                    evhttp_send_reply_end(clients[userid]);
                    evbuffer_free(evbuf);
                }else{
                    fprintf(stderr, "Discarding %d bytes to uid %d - user not connected\n",
                            body_len, userid);                
                }
                free(cached);
                erl_free_term(emsg.msg);
                erl_free_term(uid);
                erl_free_term(msg);
            }
        }
        fprintf(stderr, ".");
    }
    pthread_exit(0);
}
コード例 #3
0
ファイル: client.c プロジェクト: caox/otp
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.node_org_enc = ERLANG_LATIN1;
  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;
}
コード例 #4
0
ファイル: erl_fake_prog.c プロジェクト: 0x00evil/otp
int main(void)
#endif
{
  ei_x_buff eix;
  int index = 0;
  ETERM **etermpp = NULL, *etermp = NULL;
  char *charp = NULL;
  unsigned char uchar, **ucharpp = NULL, *ucharp = NULL;
  void *voidp = NULL;
  Erl_Heap *erl_heapp = NULL;
  int intx = 0;
  int *intp = NULL;
  unsigned int uintx, *uintp;
  unsigned long *ulongp = NULL;
  long longx = 0;
  double doublex = 0.0;
  short shortx = 42;
  FILE *filep = NULL;
  Erl_IpAddr erl_ipaddr = NULL;
  ErlMessage *erlmessagep = NULL;
  ErlConnect *erlconnectp = NULL;
  struct hostent *hostp = NULL;
  struct in_addr *inaddrp = NULL;

  /* Converion to erl_interface format is in liberl_interface */

  intx = erl_errno;

  ei_encode_term(charp, &index, voidp);
  ei_x_encode_term(&eix, voidp);
  ei_decode_term(charp, &index, voidp);

  erl_init(voidp, longx);
  erl_connect_init(intx, charp,shortx);
  erl_connect_xinit(charp,charp,charp,erl_ipaddr,charp,shortx);
  erl_connect(charp); 
  erl_xconnect(erl_ipaddr,charp);
  erl_close_connection(intx);
  erl_receive(intx, ucharp, intx);
  erl_receive_msg(intx, ucharp, intx, erlmessagep);
  erl_xreceive_msg(intx, ucharpp, intp, erlmessagep);
  erl_send(intx, etermp, etermp);
  erl_reg_send(intx, charp, etermp);
  erl_rpc(intx,charp,charp,etermp);
  erl_rpc_to(intx,charp,charp,etermp);
  erl_rpc_from(intx,intx,erlmessagep);

  erl_publish(intx);
  erl_accept(intx,erlconnectp);

  erl_thiscookie();
  erl_thisnodename();
  erl_thishostname();
  erl_thisalivename();
  erl_thiscreation();
  erl_unpublish(charp);
  erl_err_msg(charp);
  erl_err_quit(charp);
  erl_err_ret(charp);
  erl_err_sys(charp);

  erl_cons(etermp,etermp);
  erl_copy_term(etermp);
  erl_element(intx,etermp);

  erl_hd(etermp);
  erl_iolist_to_binary(etermp);
  erl_iolist_to_string(etermp);
  erl_iolist_length(etermp);
  erl_length(etermp);
  erl_mk_atom(charp);
  erl_mk_binary(charp,intx);
  erl_mk_empty_list();
  erl_mk_estring(charp, intx);
  erl_mk_float(doublex);
  erl_mk_int(intx);
  erl_mk_list(etermpp,intx);
  erl_mk_pid(charp,uintx,uintx,uchar);
  erl_mk_port(charp,uintx,uchar);
  erl_mk_ref(charp,uintx,uchar);
  erl_mk_long_ref(charp,uintx,uintx,uintx,uchar);
  erl_mk_string(charp);
  erl_mk_tuple(etermpp,intx);
  erl_mk_uint(uintx);
  erl_mk_var(charp);
  erl_print_term(filep,etermp);
  /*  erl_sprint_term(charp,etermp); */
  erl_size(etermp);
  erl_tl(etermp);
  erl_var_content(etermp, charp);

  erl_format(charp);
  erl_match(etermp, etermp);

  erl_global_names(intx, intp);
  erl_global_register(intx, charp, etermp);
  erl_global_unregister(intx, charp);
  erl_global_whereis(intx, charp, charp);

  erl_init_malloc(erl_heapp,longx);
  erl_alloc_eterm(uchar);
  erl_eterm_release();
  erl_eterm_statistics(ulongp,ulongp);
  erl_free_array(etermpp,intx);
  erl_free_term(etermp);
  erl_free_compound(etermp);
  erl_malloc(longx);
  erl_free(voidp);

  erl_compare_ext(ucharp, ucharp);
  erl_decode(ucharp);
  erl_decode_buf(ucharpp);
  erl_encode(etermp,ucharp);
  erl_encode_buf(etermp,ucharpp);
  erl_ext_size(ucharp);
  erl_ext_type(ucharp);
  erl_peek_ext(ucharp,intx);
  erl_term_len(etermp);

  erl_gethostbyname(charp);
  erl_gethostbyaddr(charp, intx, intx);
  erl_gethostbyname_r(charp, hostp, charp, intx, intp);
  erl_gethostbyaddr_r(charp, intx, intx, hostp, charp, intx, intp);

  erl_init_resolve();
  erl_distversion(intx);

  erl_epmd_connect(inaddrp);
  erl_epmd_port(inaddrp, charp, intp);

  charp  = ERL_ATOM_PTR(etermp);
  intx   = ERL_ATOM_SIZE(etermp);
  ucharp = ERL_BIN_PTR(etermp);
  intx   = ERL_BIN_SIZE(etermp);
  etermp = ERL_CONS_HEAD(etermp);
  etermp = ERL_CONS_TAIL(etermp);
  intx   = ERL_COUNT(etermp);
  doublex= ERL_FLOAT_VALUE(etermp);
  uintx  = ERL_INT_UVALUE(etermp);
  intx   = ERL_INT_VALUE(etermp);
  intx   = ERL_IS_ATOM(etermp);
  intx   = ERL_IS_BINARY(etermp);
  intx   = ERL_IS_CONS(etermp);
  intx   = ERL_IS_EMPTY_LIST(etermp);
  intx   = ERL_IS_FLOAT(etermp);
  intx   = ERL_IS_INTEGER(etermp);
  intx   = ERL_IS_LIST(etermp);
  intx   = ERL_IS_PID(etermp);
  intx   = ERL_IS_PORT(etermp);
  intx   = ERL_IS_REF(etermp);
  intx   = ERL_IS_TUPLE(etermp);
  intx   = ERL_IS_UNSIGNED_INTEGER(etermp);
  uchar  = ERL_PID_CREATION(etermp);
  charp  = ERL_PID_NODE(etermp);
  uintx  = ERL_PID_NUMBER(etermp);
  uintx  = ERL_PID_SERIAL(etermp);
  uchar  = ERL_PORT_CREATION(etermp);
  charp  = ERL_PORT_NODE(etermp);
  uintx  = ERL_PORT_NUMBER(etermp);
  uchar  = ERL_REF_CREATION(etermp);
  intx   = ERL_REF_LEN(etermp);
  charp  = ERL_REF_NODE(etermp);
  uintx  = ERL_REF_NUMBER(etermp);
  uintp  = ERL_REF_NUMBERS(etermp);
  etermp = ERL_TUPLE_ELEMENT(etermp,intx);
  intx   = ERL_TUPLE_SIZE(etermp);

  return 
      BUFSIZ +
      EAGAIN +
      EHOSTUNREACH +
      EINVAL +
      EIO +
      EMSGSIZE +
      ENOMEM +
      ERL_ATOM +
      ERL_BINARY +
      ERL_ERROR +
      ERL_EXIT +
      ERL_FLOAT +
      ERL_INTEGER +
      ERL_LINK +
      ERL_LIST +
      ERL_MSG +
      ERL_NO_TIMEOUT +
      ERL_PID +
      ERL_PORT +
      ERL_REF +
      ERL_REG_SEND +
      ERL_SEND +
      ERL_SMALL_BIG +
      ERL_TICK +
      ERL_TIMEOUT +
      ERL_TUPLE +
      ERL_UNLINK +
      ERL_U_INTEGER +
      ERL_U_SMALL_BIG +
      ERL_VARIABLE +
      ETIMEDOUT +
      MAXNODELEN +
      MAXREGLEN;
}
コード例 #5
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.node_org_enc = ERLANG_LATIN1;
    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);
}
コード例 #6
0
ファイル: erlycairo.c プロジェクト: chinnurtb/erlycairo
int main(int argc, char *argv[]) {     
    int fd;                      /* fd to Erlang node */
    unsigned char buf[BUFSIZE];  /* Buffer for incoming message */
    ErlMessage emsg;             /* Incoming message */
    int c_node;                   /* C-Node number */
    char cookie[EI_MAX_COOKIE_SIZE+1];  /* Shared cookie */
    short creation;              /* ?? */
    char *erlang_node;           /* Erlang node to connect to */
	 char *cookie_opt;				/* Where to source our cookie */
	 char *cookie_data;				/* Either the filename or literal cookie */
    ETERM *fromp, *msgp, *fnp, *argp, *resp;
    int received, loop = 1;
    
    if (argc < 5) {
        quit_with_error("invalid_args");
    }
    
    c_node = atoi(argv[1]);
    cookie_opt = argv[2];
	 cookie_data = argv[3];
    creation = 0;
    erlang_node = argv[4];
    
    erl_init(NULL, 0);

	 get_cookie(cookie_opt, cookie_data, cookie);
    
    if (!erl_connect_init(c_node, cookie, creation)) {
        quit_with_error("erl_connect_init");
    }
    
    if ((fd = erl_connect(erlang_node)) < 0) {
        quit_with_error("erl_connect"); 
    }
       
    while (loop) {
        received = erl_receive_msg(fd, buf, BUFSIZE, &emsg);

    if (received == ERL_TICK) {
        /* ignore */    
    } else if (received == ERL_ERROR) {
        loop = 0;
    } else {
        if (emsg.type == ERL_REG_SEND) {          
            fromp = erl_element(2, emsg.msg);
            msgp = erl_element(3, emsg.msg);
            fnp = erl_element(1, msgp);
            argp = erl_element(2, msgp);  
            
            if (is_function(fnp, "stop")) {
                loop = 0;
                resp = erl_format("{c_node, ~i, ok}", c_node);
            } else if (is_function(fnp, "new_image_blank")) { 
                resp = new_image_blank(argp, c_node); 
            } else if (is_function(fnp, "write_to_png")) {
                resp = write_to_png(argp, c_node);
            } else if (is_function(fnp, "close_image")) {
                resp = close_image(argp, c_node);
            } else if (is_function(fnp, "save")) {
                resp = save(argp, c_node);
            } else if (is_function(fnp, "restore")) {
                resp = restore(argp, c_node);
            } else if (is_function(fnp, "set_line_width")) {
                resp = set_line_width(argp, c_node);
            } else if (is_function(fnp, "set_source_rgba")) {
                resp = set_source_rgba(argp, c_node);	
	        } else if (is_function(fnp, "set_operator")) {
                resp = set_operator(argp, c_node);
            } else if (is_function(fnp, "move_to")) {
                resp = move_to(argp, c_node);
            } else if (is_function(fnp, "line_to")) {
                resp = line_to(argp, c_node);
            } else if (is_function(fnp, "curve_to")) {
                resp = curve_to(argp, c_node);
            } else if (is_function(fnp, "rel_move_to")) {
                resp = rel_move_to(argp, c_node);
            } else if (is_function(fnp, "rel_line_to")) {
                resp = rel_line_to(argp, c_node);
            } else if (is_function(fnp, "rel_curve_to")) {
                resp = rel_curve_to(argp, c_node);
            } else if (is_function(fnp, "rectangle")) {
                resp = rectangle(argp, c_node);
            } else if (is_function(fnp, "arc")) {
                resp = arc(argp, c_node);
            } else if (is_function(fnp, "arc_negative")) {
                resp = arc_negative(argp, c_node);
            } else if (is_function(fnp, "close_path")) {
                resp = close_path(argp, c_node);
            } else if (is_function(fnp, "paint")) {
                resp = paint(argp, c_node);
            } else if (is_function(fnp, "fill")) {
                resp = fill(argp, c_node);
            } else if (is_function(fnp, "fill_preserve")) {
                resp = fill_preserve(argp, c_node);
            } else if (is_function(fnp, "stroke")) {
                resp = stroke(argp, c_node);
            } else if (is_function(fnp, "stroke_preserve")) {
                resp = stroke_preserve(argp, c_node);
            } else if (is_function(fnp, "translate")) {
                resp = translate(argp, c_node);
            } else if (is_function(fnp, "scale")) {
                resp = scale(argp, c_node);
            } else if (is_function(fnp, "rotate")) {
                resp = rotate(argp, c_node);
            } else if (is_function(fnp, "select_font")) {
                resp = select_font_face(argp, c_node);
            } else if (is_function(fnp, "set_font_size")) {
                resp = set_font_size(argp, c_node);
            } else if (is_function(fnp, "show_text")) {
                resp = show_text(argp, c_node);
            } else if (is_function(fnp, "text_extents")) {
                resp = text_extents(argp, c_node);          
            } else if (is_function(fnp, "surface_create_from_png")) {
                resp = surface_create_from_png(argp, c_node);
            } else if (is_function(fnp, "surface_create_from_png_stream")) {
                resp = surface_create_from_png_stream(argp, c_node);
            } else if (is_function(fnp, "surface_get_width")) {
                resp = surface_get_width(argp, c_node);          
            } else if (is_function(fnp, "surface_get_height")) {
                resp = surface_get_height(argp, c_node);          
            } else if (is_function(fnp, "surface_destroy")) {
                resp = surface_destroy(argp, c_node);          
            } else if (is_function(fnp, "set_source_surface")) {
                resp = set_source_surface(argp, c_node);          
            } else if (is_function(fnp, "write_to_png_stream")) {
                resp = write_to_png_stream(argp, c_node);          
            } else {
                resp = erl_format("{c_node, ~i, {error, '~s'}}", c_node, "unknown command");
            }         
            erl_send(fd, fromp, resp);           
            erl_free_term(emsg.from); 
            erl_free_term(emsg.msg);
            erl_free_term(fromp); 
            erl_free_term(msgp);
            erl_free_term(fnp); 
            erl_free_term(argp);
            erl_free_term(resp);
      }
    }
  }
  exit(EXIT_SUCCESS);
}