Anonymous avatar Anonymous committed a6d3fe3

removed unnecessary C files.

Comments (0)

Files changed (10)

c_src/dispatcher.c

-#include "dispatcher.h"
-#include "tc_wrapper.h"
-#include "endecode.h"
-#include <string.h> // for strncpy
-
-#include "hash_map.h"
-
-static ErlDrvData yatce_drv_start(ErlDrvPort port, char *buff){
-  hash_map_t * map = (hash_map_t*)myalloc( sizeof( hash_map_t ) );
-  init_hash_map(map, 1024);
-  return (ErlDrvData)map;
-}
-
-static void yatce_drv_stop(ErlDrvData handle){
-  hash_map_t * map = (hash_map_t*)handle;
-  fini_hash_map(map, NULL);
-  myfree(map);
-  return;
-}
-
-// inspired by http://rakuto.blogspot.com/2008/07/manipulate-erlang-binary-term-format-in.html
-// this function only apportions the request == calls function depending on its command
-// 
-// @brief
-//  Entry point from Erlang code to C code. all Driver entry goes through 
-//  this function. Don't miss it!!!
-static int yatce_drv_control(ErlDrvData drv_data, unsigned int command, 
-			     char * buf, int len, char ** rbuf, int rlen ){
-  hash_map_t * d = (hash_map_t*)drv_data;
-  int index, ver;
-  ErlDrvBinary * key, * value;
-  char * table_name;
-  TCADB * table = NULL;
-  int r;
-  index = 0;
-
-  //  printf("sleepstart %p\n", buf);
-  //  sleep(1);
-  //  printf("sleepend   %p\n", buf);
-  /** selection tree
-   <has the request size?>
-    +-Y -> YATCE_TEST
-   <is the request consists of tuple?>
-    +-Y ->
-    | +-<is the request consists of value?>
-    |    +-Y -> < tablename, key, value >
-    |    |      YATCE_PUT, YATCE_PKEEP
-    |    +-N -> < tablename, key >
-    |          YATCE_OUT, YATCE_GET, 
-    +-N ->  <request consists of only table_name>
-         YATCE_OPEN, YATCE_CLOSE, YATCE_ITERNEXT, YATCE_ITERINIT, YATCE_SYNC
-         YATCE_VANISH, YATCE_RNUM, YATCE_SIZE
-  **/
-#ifdef DEBUG_DONE
-  fprintf(stderr, "%s %d: %s( %s ) - len: %d\n", __FILE__, __LINE__,  __func__, inspect_command( command ), len );
-  if( len > 0 ){
-    ei_print_term(stderr, buf, &index);     fprintf(stderr, "\n");
-    DEBUG_INFO(buf, len);
-    index = 0;
-  }
-#endif
-
-  if( len <= 0 && command == YATCE_TEST){
-    return tc_test(rbuf);
-  }
-  // All ei_xxx functions return 0 if it will be success, else return -1
-  if( ei_decode_version(buf, &index, &ver) != 0 ){// Value of 'index' will become 1.
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "invalid_argument");
-    return rlen;
-  }
-
-  //only uses table.
-  if( (command & USE_TABLE) && !(command & USE_KEY) && !(command & USE_VALUE) ){
-    table_name = read_table_name( buf, &index, len );    
-    table = (TCADB*)get_hash_map(d, table_name);
-    //case for YATCE_OPEN
-    if( command == YATCE_OPEN ){
-      if( table == NULL ){
-	table = tcadbnew();
-
-	if( ! push_hash_map( d, table_name, (void*)table ) ){
-	  fprintf(stderr, "%s %d: failed in putting TCADB '%s' into map.\n", __FILE__, __LINE__,  table_name ); 
-	}
-	rlen = tc_open( table, table_name, rbuf );
-      }
-      driver_free(table_name);
-      return rlen;
-    }
-    else if( table == NULL ){ // error: table not found and command is not open
-      index = 0;
-      *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "db_not_found" );
-      rlen = index;
-      driver_free(table_name);
-      return rlen;
-    }
-    //case table found and no {key,value} needed operations:
-#ifdef DEBUG_DONE
-    fprintf(stderr, "%s %d: %s( %s ) %s\n", __FILE__, __LINE__,  __func__, inspect_command( command ) , table_name);
-#endif
-
-    if(command == YATCE_CLOSE) pop_hash_map(d, table_name, NULL, NULL);
-    rlen = table_operations(command, table, rbuf);
-    driver_free(table_name);
-    return rlen;
-  }
-  else if( (command & USE_TABLE) && (command & USE_KEY) && !(command & USE_VALUE) ){ //  YATCE_OUT, YATCE_GET, 
-    r = decode_tuple2( &table_name, &key, buf, &index);
-#ifdef DEBUG_DONE
-    printf( "%s %d: table name : %s\n", __FILE__, __LINE__, table_name );
-#endif
-    if( r != 0 ){
-      index = 0;
-      *rbuf = encode_atom_pair_in_tuple_with_version(&index, "error", "badarith" );
-      rlen = index;
-    }
-
-    else if( (table = (TCADB*)get_hash_map(d, table_name) ) == NULL ){
-      index = 0;
-      *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "db_not_found" );
-      rlen = index;
-    }
-    else {
-#ifdef DEBUG_DONE
-      printf( "%s %d: table name : %s\n", __FILE__, __LINE__, table_name );
-      printf( "%s %d: TCADB * adb = %p\n", __FILE__, __LINE__, table );
-      fprintf(stderr, "%s %d: %s( %s ) \n", __FILE__, __LINE__,  __func__, inspect_command( command ) );
-#endif
-      rlen = tc_key_operation(command, table, key, rbuf);
-    }
-    driver_free(table_name);
-    driver_free_binary(key);
-    return rlen;
-  }
-
-  else if( (command & USE_TABLE) && (command & USE_KEY) && (command & USE_VALUE)){ //  YATCE_OUT, YATCE_GET, 
-    r = decode_tuple3( &table_name, &key, &value, buf, &index);
-#ifdef DEBUG_DONE
-    printf( "%s %d: table name : %s\n", __FILE__, __LINE__, table_name );
-#endif
-    if( r != 0 ){
-      index = 0;
-      *rbuf = encode_atom_pair_in_tuple_with_version(&index, "error", "badarith" );
-      rlen = index;
-      return rlen;
-    }
-    if( (table = (TCADB*)get_hash_map(d, table_name) ) == NULL ){
-      index = 0;
-      *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "db_not_found" );
-      rlen = index;
-    }else{
-#ifdef DEBUG_DONE
-      printf( "%s %d: table name = %s, TCADB * adb = %p\n", __FILE__, __LINE__, table_name, table );
-      fprintf(stderr, "%s %d: %s( %s ) \n", __FILE__, __LINE__,  __func__, inspect_command( command ) );
-#endif
-      switch(command) {
-      case YATCE_PUT: //{TableName, Key, Value}
-      case YATCE_PKEEP:
-	rlen = tc_put( table, key, value, rbuf, command );       break;
-	
-      case YATCE_PUTCAT:
-      case YATCE_ADDINT:
-      case YATCE_ADDDOUBLE:
-      default:
-	index = 0;
-	*rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "unsupported_operation" );
-	rlen = index;
-      }
-    }
-    driver_free(table_name);
-    driver_free_binary(key);
-    driver_free_binary(value);
-    return rlen;
-  }
-  else{
-#ifdef DEBUG_DONE
-    fprintf(stderr, "%s %d: %s( %s ) \n", __FILE__, __LINE__,  __func__, inspect_command( command ) );
-#endif
-    //TODO: need assertion, or not?
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "unknown_operation" );
-    rlen = index;
-    return rlen;
-  }
-
-#if 0 //def DEBUG_MSG
-  DEBUG_INFO( (*rbuf), rlen-1 );
-#endif
-  fprintf(stderr, "%s:%d  ouch! program must not reach here.\n", __FILE__, __LINE__);
-  *rbuf = NULL;
-  return 0;
-}
-
-void init_tcadb_(void * TCADB){}
-void fini_tcadb_(void * TCADB){  //  tcadbdel(TCADB);
-}

c_src/dispatcher.h

-#ifndef DISPATCHER_H
-#define DISPATCHER_H
-
-//#include <ei.h>
-#include <erl_driver.h>
-#include "tokyocabinet.h"
-
-static ErlDrvData yatce_drv_start(ErlDrvPort port, char *buff);
-static void yatce_drv_stop(ErlDrvData handle);
-
-// inspired by http://rakuto.blogspot.com/2008/07/manipulate-erlang-binary-term-format-in.html
-static int yatce_drv_control(ErlDrvData handle, unsigned int command, 
-			     char * buf, int len, char ** rbuf, int rlen );
-
-void init_tcadb_(void * TCADB);
-void fini_tcadb_(void * TCADB);
-
-// for details, see http://erlang.org/doc/man/driver_entry.html
-ErlDrvEntry yatce_driver_entry = {
-  .start    = yatce_drv_start,          /* L_PTR start, called when port is opened */
-  .stop     = yatce_drv_stop,           /* F_PTR stop, called when port is closed */
-  .driver_name  = DYLIB_NAME,
-  // char *driver_name, the argument to open_port, must be same as dynamic library file name without suffix
-  .control= yatce_drv_control,             /* control, F_PTR control, port_command callback */
-  .event = NULL,      // 			  Called when an event selected by driver_event() has occurred  */
-  .extended_marker = ERL_DRV_EXTENDED_MARKER,  //       int extended_marker;        // ERL_DRV_EXTENDED_MARKER
-  .major_version   = ERL_DRV_EXTENDED_MAJOR_VERSION, //    int major_version;          // ERL_DRV_EXTENDED_MAJOR_VERSION
-  .minor_version   = ERL_DRV_EXTENDED_MINOR_VERSION, //    int minor_version;          // ERL_DRV_EXTENDED_MINOR_VERSION
-  .driver_flags    = ERL_DRV_FLAG_USE_PORT_LOCKING,//    int driver_flags;           // ERL_DRV_FLAGs 
-};
-
-//DRIVER_INIT(example_drv) <- though wrong argument allowed, duplicate of DRIVER_INIT is not allowed.
-DRIVER_INIT( DYLIB_NAME ) /* must match name in driver_entry */
-{
-  return &yatce_driver_entry;
-}
-#endif

c_src/endecode.c

-#include "endecode.h"
-#include "tokyocabinet.h"
-#include <string.h>
-
-int decode_tuple2(char ** table_namep, ErlDrvBinary ** key, const char * buf, int * index ){
-  int arity;
-  
-  if( ei_decode_tuple_header( buf, index, &arity ) > 0 ){ // != 0; fail
-    *table_namep = NULL;
-    return -1;
-  }
-  if( arity != 2 ){
-    *table_namep = NULL;
-    return -1;
-  }
-
-  *table_namep = (char*)driver_alloc( sizeof(char) * MAXATOMLEN );
-  if( ei_decode_atom(buf, index, *table_namep) != 0 ){
-    return -1;
-  }
-  
-  *key = decode_key( buf, index );
-  return 0;
-}
-
-// memory area for table_name is not allocated, while memory area for key and value is already allocated
-int decode_tuple3(char ** table_namep, ErlDrvBinary ** key,  ErlDrvBinary ** value, const char * buf, int * index ){
-  int arity;
-  
-  if( ei_decode_tuple_header( buf, index, &arity ) > 0 ){ // != 0; fail
-    *table_namep = NULL;
-    return -1;
-  }
-  if( arity != 3 ){
-    *table_namep = NULL;
-    return -1;
-  }
-
-  *table_namep = (char*)driver_alloc( sizeof(char) * MAXATOMLEN );
-  if( ei_decode_atom(buf, index, *table_namep) != 0 ){
-    return -1;
-  }
-  
-  *key = decode_key( buf, index );
-  *value = decode_value( buf, index );
-
-#ifdef DEBUG_DONE
-  fprintf(stderr, "%s %d: %s.\n", __FILE__, __LINE__, inspect_code( (*key)->orig_bytes[0]) );
-  printf("%s / %ld\n", ((*key)->orig_bytes + 1), (*key)->orig_size  );
-  printf("%s / %ld\n", ((*value)->orig_bytes + 1), (*value)->orig_size  );
-#endif
-  return 0;
-}
-
-
-/** from ei.h
-typedef struct {
-    char ei_type;
-    int arity; //size for tuple / list
-    int size;  //size for binary
-    union {
-	long i_val;
-	double d_val;
-	char atom_name[MAXATOMLEN+1];
-	erlang_pid pid;
-	erlang_port port;
-	erlang_ref ref;
-    } value;
-} ei_term;   */
-
-// The idea is simple; just use ei_s_print_term to get a binary length
-// accoring to erlang-VM way; and return it.
-int get_binary_size(const char * buf){
-  int i=0;
-  ei_skip_term(buf, &i);
-
-#ifdef DEBUG_DONE
-  i=0;
-  ei_print_term(stderr, buf, &i);
-  fprintf(stderr, "\n");
-  //  char * s = NULL;
-  //  ei_s_print_term(&s, buf, &i);
-  fprintf(stderr, "print:%s -size:%d\n", s, i);
-#endif
-  return i;
-}
-
-ErlDrvBinary * decode_term( const char * buf, int * index){
-  int size = get_binary_size(buf+ *index);
-  ErlDrvBinary * ret = driver_alloc_binary( size );
-  memcpy( ret->orig_bytes, buf + *index, size );
-#ifdef DEBUG_DONE
-  DEBUG_INFO( ret->orig_bytes, ret->orig_size);
-#endif
-  *index += size;
-  return ret;
-}
-
-// Decodes buf, into ErlDrvBinary, to be inserted into TC currently.
-ErlDrvBinary * decode_key( const char * buf, int * index){
-  return decode_term( buf, index );
-}
-ErlDrvBinary * decode_value( const char * buf, int * index ){
-  return decode_term( buf, index );
-}
-
-char * read_table_name( char * buf, int * index, int len ){
-  char * table_name;
-  int type, size;
-  if( ei_get_type(buf, index, &type, &size) != 0 ) return NULL;
-  if( type != ERL_ATOM_EXT ){
-#ifdef DEBUG_MSG
-    fprintf( stderr, "not a atom format.\n" );
-#endif
-    return NULL; //go ahead!
-  }
-  // normal routine.
-  table_name = (char*)driver_alloc(sizeof(char) * (len+1)); //len is always smaller than MAXATOMLEN
-  if( ei_decode_atom( buf, index, table_name ) != 0 ){
-#ifdef DEBUG_MSG
-    fprintf(stderr, "can't read table name: %s\n", table_name );
-#endif
-    driver_free( table_name );
-    return NULL;
-  }
-  table_name[len] = '\0';
-  
-  return table_name;
-}
-
-char * encode_ok_value_in_tuple_with_version( int * index, const char * result, const void * value_tmp, int size){
-  int i = 0;
-  char * ret = NULL;
-  char * value = (char*)value_tmp;
-  ei_encode_version( NULL, &i );
-  ei_encode_tuple_header( NULL, &i, 2 );
-  ei_encode_atom( NULL, &i, result);
-  i += size;
-  ret = driver_alloc( i* sizeof(char) );
-
-  i = 0;
-  ei_encode_version( ret, &i );
-  ei_encode_tuple_header( ret, &i, 2 );
-  ei_encode_atom( ret, &i, result);
-  memcpy( ret+ i, value, size );
-  i += size;
-  *index = i;
-
-  return ret;
-}
-
-// "error", "someerr"  =>  { error, someerr }
-char * encode_atom_pair_in_tuple_with_version( int * index, const char * result, const char * reason ){
-  int i = 0;
-  char * ret = NULL;
-  ei_encode_version( NULL, &i );
-  ei_encode_tuple_header( NULL, &i, 2 );
-  ei_encode_atom( NULL, &i, result);
-  ei_encode_atom( NULL, &i, reason);
-  ret = (char*)driver_alloc( sizeof( char ) * i );
-  if( ret != NULL ){
-    i = 0;
-    ei_encode_version( ret, &i );
-    ei_encode_tuple_header( ret, &i, 2 );
-    ei_encode_atom( ret, &i, result);
-    ei_encode_atom( ret, &i, reason);
-    *index = i;
-  }    
-  return ret;
-}
-
-//  some int   =>   {ok, 123}
-char * encode_ok_int_in_tuple_with_version(int * index, unsigned long long  result ){
-  int i = 0;
-  char * ret = NULL;
-  ei_encode_version( NULL, &i );
-  ei_encode_tuple_header( NULL, &i, 2 );
-  ei_encode_atom( NULL, &i, "ok");
-  ei_encode_ulonglong( NULL, &i, result );
-  ret = (char*)driver_alloc( sizeof( char ) * i );
-  if( ret != NULL ){
-    i = 0;
-    ei_encode_version( ret, &i );
-    ei_encode_tuple_header( ret, &i, 2 );
-    ei_encode_atom( ret, &i, "ok");
-    ei_encode_ulonglong( ret, &i, result );
-    *index = i;
-  }    
-  return ret;
-}
-
-
-const char * inspect_code( int code ){
-  is_this_it( code, ERL_SMALL_INTEGER_EXT );
-  is_this_it( code, ERL_INTEGER_EXT );
-  is_this_it( code, ERL_FLOAT_EXT );
-  is_this_it( code, ERL_ATOM_EXT );
-  is_this_it( code, ERL_PORT_EXT );
-  is_this_it( code, ERL_PID_EXT );
-  is_this_it( code, ERL_STRING_EXT );
-  is_this_it( code, ERL_BINARY_EXT );
-  is_this_it( code, ERL_SMALL_BIG_EXT );
-  is_this_it( code, ERL_LARGE_BIG_EXT );
-  is_this_it( code, ERL_LIST_EXT );
-  is_this_it( code, ERL_REFERENCE_EXT );
-  is_this_it( code, ERL_NEW_REFERENCE_EXT );
-  is_this_it( code, ERL_SMALL_TUPLE_EXT );
-  is_this_it( code, ERL_LARGE_TUPLE_EXT );
-  is_this_it( code, ERL_NIL_EXT );
-  is_this_it( code, ERL_NEW_FUN_EXT );
-  is_this_it( code, ERL_FUN_EXT );
-  return "UNKNOWN_CODE";
-}
-const char * inspect_command( int code ){
-  is_this_it( code, YATCE_OPEN );
-  is_this_it( code, YATCE_CLOSE );
-  is_this_it( code, YATCE_PUT );
-  is_this_it( code, YATCE_PKEEP );
-  //  is_this_it( code, YATCE_PUTCAT );
-  is_this_it( code, YATCE_OUT );
-  is_this_it( code, YATCE_GET );
-  is_this_it( code, YATCE_ADDINT );
-  is_this_it( code, YATCE_ADDDOUBLE );
-  is_this_it( code, YATCE_SYNC );
-  is_this_it( code, YATCE_ITERINIT);
-  is_this_it( code, YATCE_ITERNEXT);
-  is_this_it( code, YATCE_OPTIMIZE );
-  is_this_it( code, YATCE_VANISH );
-  is_this_it( code, YATCE_COPY );
-  //  is_this_it( code, YATCE_TX );
-  is_this_it( code, YATCE_PATH );
-  is_this_it( code, YATCE_RNUM );
-  is_this_it( code, YATCE_SIZE );
-  is_this_it( code, YATCE_TEST );
-  return "UNKNOWN_CODE";
-}
-

c_src/endecode.h

-#ifndef ENDECODE_H
-#define ENDECODE_H
-#include <erl_driver.h>
-#include <ei.h>
-
-// {en|de}coding library.
-
-int decode_tuple2(char ** table_namep, ErlDrvBinary ** key, const char * buf, int * index );
-
-int decode_tuple3(char ** table_namep, ErlDrvBinary ** key, ErlDrvBinary ** value, const char * buf, int * index );
-
-char * read_table_name( char * buf, int * index, int len );
-
-
-// Decodes buf, into ErlDrvBinary, to be inserted into TC
-// currently, integer and string is only supported.
-ErlDrvBinary * decode_term( const  char * buf, int * index);
-ErlDrvBinary * decode_key( const  char * buf, int * index);
-ErlDrvBinary * decode_value( const char * buf, int * index ); //internally, they're all same.
-
-/**
- * modules for {en|de}code between [erlang world] <--> [real C world]
- */
-char * encode_ok_value_in_tuple_with_version( int * index,  const char * result, const void * value_tmp, int size);
-char * encode_atom_pair_in_tuple_with_version( int * index, const char * result, const char * reason );
-char * encode_ok_int_in_tuple_with_version(int * index, unsigned long long  result );
-
-const char * inspect_code( int code );
-const char * inspect_command( int code );
-
-void print_term(const char * buf, int len);
-
-#define get_name( macro ) #macro
-#define is_this_it( r, macro ) if( r == macro ){ return #macro; };
-
-#define DEBUG_INFO(buf, len)  \
-  {									\
-    int _i_ = 0;								\
-    printf("** %s:%d - %s - buflen: %d\n** ", __FILE__, __LINE__, __func__, (len)); \
-    while(_i_ < (len) ){						\
-      printf("%.3d ", (unsigned char)((buf)[_i_]));			\
-      if( 0 ==( ++_i_ % 0x10 ) )printf("\n** ");  \
-    }							\
-    putchar('\n');						\
-  } 
-
-
-
-#endif
-

c_src/tc_performer.c

-#include <stdio.h>
-
-// for TC
-#include <tcutil.h>
-#include <tcadb.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-#include <string.h>
-
-// for performer
-#include <pthread.h>
-#include <sys/time.h>
-
-// for random char generator
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-//#include "yatce_map.h"
-
-const char * get_static_char(const unsigned int len);
-int get_random_char(char * buf, int size);
-
-static char letters[] = 
-  "1234567890" "-=`!@#$%^&" "*()_+|~" //17
-  "qwertyuiop" "[]QWERTYUI" "OP{}" //14
-  "asdfghjkl;" "'ASDFGHJKL" ":\"" //12
-  "zxcvbnm,./" "ZXCVBNM<>?"; //10
-//53 letters
-static int num_letters = 53;
-
-typedef struct initdata_{
-  TCADB * adb;
-  unsigned int Nrec;
-} initdata;
-
-void * test_put(void * arg);
-
-void usage(){
-  fprintf(stderr, "usage: "
-	  " $ tc_performer <numthreads> <numrecords> \n" );
-  exit(1);
-}
-
-
-int main(int args, char ** argv){
-  unsigned int Nth, Nrec;
-  initdata data;
-  struct timeval start, end;
-  double t;
-  char * key, * value;
-  unsigned int counter;
-  pthread_t * threads;
-
-  key   = (char*)malloc(sizeof(char)*1024);
-  value = (char*)malloc(sizeof(char)*1024);
-
-  if( args >= 3 ){
-    Nth  = atoi( argv[1] );
-    Nrec = atoi( argv[2] );
-  }else{
-    usage();
-  }
-  threads = (pthread_t*)malloc(sizeof(pthread_t)*Nth);
-
-  data.Nrec = Nrec;
-  data.adb = tcadbnew();
-  if( ! tcadbopen( data.adb, "/tmp/test.tch") ){
-    fprintf(stderr, "%d: open failed.\n", __LINE__);
-  }
-
-  gettimeofday(&start, NULL);
-
-  for( counter = 0 ; counter < Nth ; ++counter ){
-    pthread_create( &threads[counter], NULL, test_put, (void*)&data );
-  }
-
-  for( counter = 0 ; counter < Nth ; ++counter ){
-    pthread_join( threads[counter], NULL );
-  }
-
-  gettimeofday(&end, NULL);
-  t = (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0 ;
-  printf( "elasped time: %f sec, \tat least: %f qps\n" , t, Nth * Nrec / t ); 
-	  
-  tcadbclose(data.adb);
-  tcadbdel(data.adb);
-  free(key);
-  free(value);
-  //
-  return 0;
-}
-
-void * test_get(void * arg){
-  initdata * data = (initdata*)arg;
-  unsigned int counter;
-  char key[17];
-
-  for( counter = 0 ; counter < data->Nrec ; ++counter ){
-    get_random_char(key, 16);
-    char * value = tcadbget2( data->adb, get_static_char(16) );
-    if( value == NULL ){
-      fprintf(stderr, "%d: tcadbget2 failed.\n", __LINE__);
-    }
-    free(value);
-  }
-  return NULL;
-}
-
-void * test_put(void * arg){
-  initdata * data = (initdata*)arg;
-  unsigned int counter;
-  char key[17];
-  char value[129];
-
-  for( counter = 0 ; counter < data->Nrec ; ++counter ){
-    get_random_char(key, 16);
-    get_random_char(value, 128);
-    if( ! tcadbput2( data->adb, key, value ) ){
-      fprintf(stderr, "%d: tcadbput2 failed.\n", __LINE__);
-    }
-  }
-  return NULL;
-}
-
-
-const char * get_static_char(const unsigned int len){
-  if(len <= 0){
-    return NULL;
-  }
-  else if( len >= 1024 ){
-    return 
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte //256
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte //512
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte 
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte //1024
-      ;
-  }
-  else if( len >= 512 ){
-    return 
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte //256
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte //512
-      ;
-  }
-  else if( len >= 256 ){
-    return 
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte //256
-      ;
-  }
-  else if( len >= 128 ){
-    return 
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "0987654321" "hoge" //64 byte
-      ;
-  }
-  else if( len >= 0x10 ){
-    return "0123456789" "abcde";
-  }
-  return "a";
-}
-
-
-int get_random_char(char * buf, int size){
-  int bytes_read = 0;
-  int fd;
-  int i;
-  fd = open( "/dev/urandom", O_RDONLY );
-  if( fd < 0 ){
-    perror("can't open /dev/urandom" );    //    exit(1); //error,...
-    return -1;
-  }
-  while( bytes_read < size ){
-    int r=read(fd, buf, size-bytes_read);
-    if( r < 0 ){
-      perror( "can't read(2)");
-      break;
-    }
-    bytes_read+=r;
-  }
-  close(fd);
-  for( i = 0 ; i < bytes_read ; ++i ){
-    buf[i] = letters[ buf[i] % num_letters ];
-  }
-  buf[bytes_read] = '\0';
-  return bytes_read;
-}

c_src/tc_table_operation.c

-#include <erl_driver.h>
-
-#include "tc_table_operation.h"
-#include "endecode.h"
-#include "tokyocabinet.h"
-
-int table_operations(int command, TCADB * table, char ** rbuf){
-  int rlen, index;
-  switch(command) {
-  case YATCE_CLOSE:      rlen = tc_close( table, rbuf );      break;
-    
-  case YATCE_ITERINIT:      rlen = tc_iterinit(table, rbuf);      break;
-    
-  case YATCE_ITERNEXT:      rlen = tc_iternext(table, rbuf);      break;
-    
-  case YATCE_SYNC:      rlen = tc_sync(table, rbuf);      break;
-    
-  case YATCE_VANISH:      rlen = tc_vanish(table, rbuf);       break;
-    
-    //  case YATCE_PATH:      rlen = tc_path(table, rbuf);      break;
-    
-  case YATCE_RNUM:      rlen = tc_rnum(table, rbuf);      break;
-    
-  case YATCE_SIZE:      rlen = tc_size(table, rbuf);      break;
-    
-  default:
-    index = 0;
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "unknown_operation" );
-    rlen = index;
-  }
-  return rlen;
-}
-
-int tc_close( TCADB * adb, char ** rbuf ){
-  int index = 0;
-  //fprintf(stderr, "closing %s .\n", adb->name );
-  if( ! tcadbclose(adb) ){ //{error, tcadbopen_failure}
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "tcadbclose_failure" );
-  }
-
-  else{  //{ok, opened}
-#ifdef DEBUG_DONE
-    fprintf(stderr, "closing %s succeeded.\n", "tcadb");//adb->name );
-#endif
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "ok", "closed" );
-  }
-  return index; //if binary seems returned, you'd test binary_to_term( list_to_binary( Output ) )
-}
-
-int tc_iterinit(TCADB * table, char ** rbuf){
-  int index = 0;
-  if( tcadbiterinit(table) ){
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "ok", "init" );
-  }else{
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "failed" );      
-  }
-  return index;
-}
-int tc_iternext(TCADB * table, char ** rbuf){
-  int index = 0;
-  int size = 0;
-  char * tmp = NULL;
-  if( (tmp = tcadbiternext(table, &size))!= NULL ){
-    *rbuf = encode_ok_value_in_tuple_with_version( &index, "ok", tmp, size );
-    tcfree(tmp);
-  }else{
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "end_of_data" );      
-  }
-  return index;
-}
-
-int tc_sync(TCADB * table,  char ** rbuf){
-  int index = 0;
-  
-  if(table == NULL || ! tcadbsync(table)){
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "not_synced" );
-
-  }else{
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "ok", "sync" );
-
-  }
-  return index;
-}
-
-int tc_vanish(TCADB * table, char ** rbuf ){
-  int index=0;
-  if( tcadbvanish(table) ){
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "ok", "vanished" );
-  }else{
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "not_vanished" );      
-  }
-  return index;
-}
-/** int tc_path(  TCADB * table, char ** rbuf ){
-  int index = 0;
-  const char * path; //must not be freed!
-  if( (path = tcadbpath(table)) != NULL ){
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "ok", "hoge" );
-//    *rbuf = encode_ok_value_in_tuple_with_version( &index, "ok", path, strlen(path)+1 );
-    //need encoding to erlang list
-    }else{
-  *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "unknown" );
-  } 
-  *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "maybe_deprecated" );
-  return index;
-} **/
-int tc_rnum(  TCADB * table, char ** rbuf ){
-  int index = 0;
-  *rbuf = encode_ok_int_in_tuple_with_version(&index, tcadbrnum(table));
-  return index;
-}
-int tc_size(  TCADB * table, char ** rbuf ){
-  int index = 0;
-  *rbuf = encode_ok_int_in_tuple_with_version(&index, tcadbsize(table));
-  return index;
-}

c_src/tc_table_operation.h

-#ifndef TC_TABLE_OPERATION_H
-#define TC_TABLE_OPERATION_H
-
-#include <stdio.h>
-#include <tcutil.h>
-#include <tcadb.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-int table_operations(int command, TCADB * table, char ** rbuf);
-
-int tc_close( TCADB * adb, char ** rbuf );
-int tc_iterinit(TCADB * adb, char ** rbuf);
-int tc_iternext(TCADB * adb, char ** rbuf);
-int tc_sync(  TCADB * adb, char ** rbuf );
-int tc_vanish(TCADB * adb, char ** rbuf );
-//int tc_path(  TCADB * adb, char ** rbuf );
-int tc_rnum(  TCADB * adb, char ** rbuf );
-int tc_size(  TCADB * adb, char ** rbuf );
-
-#endif

c_src/tc_wrapper.c

-#include "tc_wrapper.h"
-#include "endecode.h"
-#include "easy_test.h"
-#include <string.h>
-
-#include <ei.h> //for ei_decode_hogehoge
-#include "tokyocabinet.h"
-
-int tc_open(  TCADB * adb, const char * table_name_with_options, char ** rbuf ){
-  int index = 0;
-  if( ! tcadbopen( adb, table_name_with_options) ){ //{error, tcadbopen_failure}
-#ifdef DEBUG_DONE
-    fprintf(stderr, "%s %d: opening %s failed.\n",__FILE__, __LINE__,  table_name_with_options );
-#endif
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "tcadbopen_failure" );
-  }
-  else{    //{ok, opened}
-#ifdef DEBUG_DONE
-    fprintf(stderr, "%s %d: opening %s succeeded.\n", __FILE__, __LINE__, table_name_with_options );
-#endif
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "ok", "opened" );
-  }
-
-  return index;
-}
-
-int tc_put(   TCADB * adb, const ErlDrvBinary * key, const ErlDrvBinary * value, char ** rbuf, int command ){
-  int index = 0;
-  bool result = false;
-  const char * msg;
-  if( command == YATCE_PUT ){
-    result =  tcadbput( adb, key->orig_bytes, key->orig_size, value->orig_bytes, value->orig_size );
-    msg = "inserted";
-  }else if( command == YATCE_PKEEP ){
-    result =  tcadbputkeep( adb, key->orig_bytes, key->orig_size, value->orig_bytes, value->orig_size );
-    msg = "inserted";
-    /**
-  }else if( command == YATCE_PUTCAT ){
-    result =  tcadbputcat( adb, key->orig_bytes, key->orig_size, value->orig_bytes, value->orig_size );
-    msg = "appended";     **/
-  }
-  if( !result ){
-#ifdef DEBUG_DONE
-    fprintf(stderr, "inserting into %s failed.\n", "name");//adb->name );
-#endif
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "tcadbput(keep)_failure" );
-  }
-  else{  //{ok, opened}
-#ifdef DEBUG_DONE
-    fprintf(stderr, "inserting into %s succeeded.\n", "the table");// adb->name );
-    fprintf(stderr, " value -> %s, %ld.\n", inspect_code(value->orig_bytes[0]), value->orig_size );
-#endif
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "ok", msg );
-  }
-  return index;
-}
-
-int tc_key_operation( int command, TCADB * adb, const ErlDrvBinary * key, char ** rbuf ){
-  int index;
-  int rlen;
-  switch(command) {
-  case YATCE_OUT:       rlen = tc_out( adb, key, rbuf );       break;
-  case YATCE_GET:       rlen = tc_get( adb, key, rbuf );       break;
-    
-  default:
-    index = 0;
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "unknown_operation" );
-    rlen = index;
-  }
-  return rlen;
-}
-
-int tc_get(   TCADB * adb, const ErlDrvBinary * key, char ** rbuf ){
-  int index = 0;
-  int size  = 0;
-
-  char * value = (char*)tcadbget( adb, key->orig_bytes, key->orig_size, &size );
-  if( value == NULL ){
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "record_doesnt_exist" );
-  }
-
-  else{  //{ok, opened}
-#ifdef DEBUG_DONE
-    fprintf(stderr, "getting from %s succeeded.\n", "table");//adb->name );
-    fprintf(stderr, " value -> %s, %ld.\n", inspect_code(value[0]), size );
-    int i=0;
-    ei_print_term(stderr, value, &i);
-    fprintf( stderr, "\t%d=?=%d\n", i, size);
-#endif
-    *rbuf = encode_ok_value_in_tuple_with_version( &index, "ok", value, size );
-    free(value);
-  }
-  return index;
-}
-
-int tc_out(   TCADB * adb, const ErlDrvBinary * key, char ** rbuf ){
-  int index = 0;
-
-  if( ! tcadbout( adb, key->orig_bytes, key->orig_size) ){
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "tcadbout_failure" );
-  }
-
-  else{  //{ok, deleted}
-#ifdef DEBUG_DONE
-    fprintf(stderr, "removing from %s succeeded.\n", "tablename");//adb->name );
-#endif
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "ok", "deleted" );
-  }
-  return index;
-}
-
-int tc_test(char ** rbuf){
-  int index = 0;
-  bool result;
-/*   prepare();
-   test_yatce_list();
-   test_yatce_map(); 
-   result = print_result(__func__); */
-  result = true;
-  if( result ){
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "ok", "all_passed" );
-  }else{
-    *rbuf = encode_atom_pair_in_tuple_with_version( &index, "error", "test_failed" );
-  }
-  return index;
-}
-  /*
-   http://archive.netbsd.se/view_attachment.php?id=7320381.78759
-   When the C-program processed the request from erlang it will use the
-   ei-interface to create an Erlang term. This term will be sent the
-   erlang via a socket. The Erlang control process, will forward
-   it to the client that does binary_to_term before returning the result
-   to the client program.
-   */
-

c_src/tc_wrapper.h

-#ifndef TC_WRAPPER_H
-#define TC_WRAPPER_H
-
-#include <stdio.h>
-#include <tcutil.h>
-#include <tcadb.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-#include <erl_driver.h>
-#include "tc_table_operation.h"
-
-void quit( TCADB * adb );
-
-char * get_table_name(char * buff);
-
-int tc_open(  TCADB * adb, const char * table_name_with_options, char ** rbuf );
-
-int tc_put(   TCADB * adb, const ErlDrvBinary * key, const ErlDrvBinary * value, char ** rbuf, int command );
-
-int tc_key_operation( int command, TCADB * adb, const ErlDrvBinary * key, char ** rbuf );
-
-int tc_get(   TCADB * adb, const ErlDrvBinary * key, char ** rbuf );
-int tc_out(   TCADB * adb, const ErlDrvBinary * key, char ** rbuf );
-int tc_test(char ** rbuf);
-
-#endif
-

test/yatce.coverspec

 
 %% Specific modules to include in cover.
 %% Mods = [atom()]
-{incl_mods, [tcadb, yatce, yatce_sup, yatce_server, perf_controller, perf_sup, perf_timer, unit_performer]}.
+{incl_mods, [tcadb, perf_controller, perf_sup, perf_timer, unit_performer]}.
 
 %% Directories to exclude in cover.
 %{excl_dirs, Dirs}.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.