예제 #1
0
파일: client.c 프로젝트: hpc/Spindle
int client_init()
{
  int initial_run = 0;
  LOGGING_INIT("Client");
  check_for_fork();
  if (!use_ldcs)
     return -1;

  init_server_connection();
  intercept_open = (opts & OPT_RELOCPY) ? 1 : 0;
  intercept_stat = (opts & OPT_RELOCPY || !(opts & OPT_NOHIDE)) ? 1 : 0;
  intercept_exec = (opts & OPT_RELOCEXEC) ? 1 : 0;
  intercept_fork = 1;
  intercept_close = 1;  

  if (getenv("LDCS_BOOTSTRAPPED")) {
     initial_run = 1;
     unsetenv("LDCS_BOOTSTRAPPED");
  }
  
  if ((opts & OPT_REMAPEXEC) &&
      ((initial_run && (opts & OPT_RELOCAOUT)) ||
       (!initial_run && (opts & OPT_RELOCEXEC))))
  {
     remap_executable(ldcsid);
  }

  return 0;
}
예제 #2
0
파일: client.c 프로젝트: hpc/Spindle
static void reset_server_connection()
{
   client_close_connection(ldcsid);

   ldcsid = -1;
   old_cwd[0] = '\0';

   init_server_connection();
}
예제 #3
0
int process_chunk_request(px_config_t * config, px_conn_t * px_conn) {
    server_conn_t * s_conn = px_conn->s_conn;
    browser_conn_t* b_conn = px_conn->b_conn;

    if (!s_conn){
        init_server_connection(config, px_conn);
        s_conn = px_conn->s_conn;
        /* server connection is reconstructed, so connection state (available
           bitrates, throughput) should be restored */
        char* slash = strrchr(b_conn->url, '/');
        history_bitrate_t* history_bitrate = config->history_bitrates;
        while(history_bitrate){
            if (strlen(history_bitrate->video_path) == (slash - b_conn->url + 1) 
                && strncmp(history_bitrate->video_path, 
                                b_conn->url, slash - b_conn->url + 1) == 0){
                s_conn->bitrates = history_bitrate->bitrates;
                px_conn->throughput = history_bitrate->throughput;
                strcpy(b_conn->video_path, history_bitrate->video_path);
                break;
            }
            history_bitrate = history_bitrate->next;
        }
    }

    // start timing
    gettimeofday(&px_conn->timer, NULL);

    // adapt bitrate
    int bitrate = -1;
    bitrate_t* p = s_conn->bitrates;
    if (!p){
        fprintf(stderr, "can not find bitrates for the connection\n");
        return -1;
    }
    while (p){
        if (px_conn->throughput >= 1.5 * p->bitrate){
            bitrate = (bitrate < p->bitrate) ? p->bitrate : bitrate;
        }
        p = p->next;
    }

    // throughput is too low to find a bitrate, use the smallest bitrate
    if (bitrate == -1){
        p = s_conn->bitrates;
        bitrate = p->bitrate;
        while (p){
            bitrate = (bitrate > p->bitrate) ? p->bitrate : bitrate;
            p = p->next;
        }
    }

    px_conn->bitrate = bitrate;
    replace_url(b_conn, bitrate);

    s_conn->resp_type = CHUNK_RESP;

    char* request = generate_request_to_server(b_conn, b_conn->url, 
                                                            "localhost:8080");
    if (send_data_to_socket(s_conn->fd, request, strlen(request)) < 0){
        fprintf(stderr, "send data to server error\n");
        free(request);
        return -1;
    }

    free(request);
    
    return 0;
}
int	main(int ac, char **av)
{
  // doit absolument etre apelle avant d'autres appels a la lib
  init_nettool();
  if (ac > 1) // server mode
    {

      // set handlers
      assign_newclient(process_newclient, NULL);
      assign_deadclient(process_deadclient, NULL);
      assign_clients(process_clients, NULL);

      // open listen connection
      if (init_server_connection(PORT))
	return (1);

      // check messages
      while (1)
	check_select(MAXSELECT);

      // close connection
      close_server_connection();
      close_connection();
    }
  else // client mode
    {
      // connect to server
      if (init_connection("localhost", PORT))
	return (1);

      assign_deadclient(process_drop, NULL);

      printf("step 1\n");fflush(stdout); fflush(stdout);
      // stock messages to send
      stock_remote_msg(WELCOME, strlen("tata"), (void*)"tata");
      printf("step 2\n");fflush(stdout); fflush(stdout);
      stock_remote_msg(HELLOWORLD, 0, NULL);
      printf("step 3\n");fflush(stdout); fflush(stdout);
      stock_remote_msg(HELLOWORLD, 0, NULL);
      printf("step 4\n");fflush(stdout); fflush(stdout);
      stock_remote_msg(HELLOWORLD, 0, NULL);
      printf("step 5\n");fflush(stdout); fflush(stdout);
      stock_remote_msg(HELLOWORLD, 0, NULL);
      printf("step 5\n");fflush(stdout); fflush(stdout);

      printf("step 7\n");fflush(stdout); fflush(stdout);
      // send messages
      while (1)
	check_select(MAXSELECT);

      printf("step 8\n");fflush(stdout); fflush(stdout);
      // close connection
      close_connection();
      printf("step 9\n");fflush(stdout); fflush(stdout);
    }
  // free memory, and close connections
  nettool_quit();
  if (players)
    free(players);
  return (0);
}