Example #1
0
static void checkpoint_starvation_main(int nMs, CheckpointStarvationCtx *p){
  Error err = {0};
  Sqlite db = {0};
  Threadset threads = {0};
  int nInsert = 0;
  int i;

  opendb(&err, &db, "test.db", 1);
  sql_script(&err, &db, 
      "PRAGMA page_size = 1024;"
      "PRAGMA journal_mode = WAL;"
      "CREATE TABLE t1(x);"
  );

  setstoptime(&err, nMs);

  for(i=0; i<4; i++){
    launch_thread(&err, &threads, checkpoint_starvation_reader, 0);
    usleep(CHECKPOINT_STARVATION_READMS*1000/4);
  }

  sqlite3_wal_hook(db.db, checkpoint_starvation_walhook, (void *)p);
  while( !timetostop(&err) ){
    sql_script(&err, &db, "INSERT INTO t1 VALUES(randomblob(1200))");
    nInsert++;
  }

  printf(" Checkpoint mode  : %s\n",
      p->eMode==SQLITE_CHECKPOINT_PASSIVE ? "PASSIVE" : "RESTART"
  );
  printf(" Peak WAL         : %d frames\n", p->nMaxFrame);
  printf(" Transaction count: %d transactions\n", nInsert);

  join_all_threads(&err, &threads);
  closedb(&err, &db);
  print_and_free_err(&err);
}
Example #2
0
static void vacuum1(int nMs){
  Error err = {0};
  Sqlite db = {0};
  Threadset threads = {0};

  opendb(&err, &db, "test.db", 1);
  sql_script(&err, &db, 
     "CREATE TABLE t1(x PRIMARY KEY, y BLOB);"
     "CREATE INDEX i1 ON t1(y);"
  );
  closedb(&err, &db);

  setstoptime(&err, nMs);

  sqlite3_enable_shared_cache(1);
  launch_thread(&err, &threads, vacuum1_thread_writer, 0);
  launch_thread(&err, &threads, vacuum1_thread_writer, 0);
  launch_thread(&err, &threads, vacuum1_thread_writer, 0);
  launch_thread(&err, &threads, vacuum1_thread_vacuumer, 0);
  join_all_threads(&err, &threads);
  sqlite3_enable_shared_cache(0);

  print_and_free_err(&err);
}
Example #3
0
int main(int argc, char **argv) {
    void *mod_routing = NULL;
    char *conffile = NULL;
    FILE *file = NULL;
    int nofork = 1;
    char str[100];
    int c = 0;
    char b_log  = 1;
    char b_fork = 1;
    memset(&str, 0, 100*sizeof(char));
    log_init("logFile",NULL);
    log2display(LOG_ALERT);

    p_threadpool = threadpool_create(5, 8096, 0);

    init_maps();
    init_call_id(NULL);

    while((c=getopt(argc, argv, "c:vP:fhD:"))!=-1) {
        switch(c) {
        case 'c':
            conffile = optarg;
            break;
        case 'v':
            printf("sip2smpp version: %s\n", VERSION);
            exit(0);
            break;
        case 'P':
            pid_file = optarg;
            break;
        case 'f':
            nofork = 0;
            b_fork = 0;
            break;
        case 'h':
            usage(0);
            break;
        case 'D':
        {
            char log = atoi(optarg);
            if(log >= 0 && log <= 8) {
                log2display((Loglevel)log);
                b_log = 0;
            }
            break;
        }
        default:
            abort();
        }
    }

    if(!conffile) {
        conffile = (char*)malloc(sizeof(char)*strlen(DEFAULT_CONFIG)+1);
        strcpy(conffile,DEFAULT_CONFIG);
    }

    if((file = fopen(conffile,"r")) != NULL) {
        fclose(file);
    } else {
        ERROR(LOG_FILE | LOG_SCREEN,"The INI file isn't found!");
        handler(-1);
    }

    if(load_config_file((uint8_t*)conffile, CONFIG_ALL, NULL) == -1) {
        ERROR(LOG_FILE | LOG_SCREEN,"There are errors in the INI file!");
        free_config_file(CONFIG_ALL, NULL);
        handler(-1);
    }

    if(b_log) {
        log2display((Loglevel)cfg_main->log_level);
    }

    if(b_fork) {
        nofork = !cfg_main->fork;
    }

    if(daemonize(nofork) != 0) {
        ERROR(LOG_FILE | LOG_SCREEN,"Daemoniize failed");
        exit(-1);
    }

    //Load routing module
    void* functions[2] = { send_sms_to_smpp, send_sms_to_sip };
    void* cfgs[2] = { cfg_smpp, cfg_sip };
    if(cfg_main->routing_module) {
        mod_routing = dlopen(cfg_main->routing_module, RTLD_NOW | RTLD_GLOBAL);
        if(!mod_routing) {
            ERROR(LOG_SCREEN | LOG_FILE, "%s", dlerror());
            handler(-1);
        }
        f_start_routing = dlsym(mod_routing, "start_routing");
        f_routing       = dlsym(mod_routing, "routing");
        f_close_routing = dlsym(mod_routing, "close_routing");
    } else {
        f_start_routing = default_start_routing;
        f_routing       = default_routing;
        f_close_routing = default_close_routing;
    }

    if(db_init() == -1) {
        ERROR(LOG_FILE | LOG_SCREEN,"There are errors when the DB connection!");
        handler(-1);
    } else {
        //TODO: send sms saved in db
    }

    if(f_start_routing(functions, cfgs) != 0) {
        ERROR(LOG_FILE | LOG_SCREEN, "Routing loading failed");
        handler(-1);
    }

    if(cfg_main && cfg_main->launch_msg) {
        printf("\033[0;36m%s\033[0m\n", cfg_main->launch_msg);
    }

    printf("SIP 2 SMPP Version  [%s]\n", VERSION);
    printf("Pid file            [%s]\n", pid_file);
    printf("Config File         [%s]\n", conffile);

    display_config_file(CONFIG_ALL, NULL);

    start_all_threads_interfaces();

    join_all_threads();

    threadpool_destroy(p_threadpool, threadpool_graceful);

    f_close_routing();

    if(cfg_main->routing_module) {
        dlclose(mod_routing);
    }

    free_config_file(CONFIG_ALL, NULL);

    handler(0);

    return 0;
}