Exemple #1
0
int client(struct conf *conf, enum action action, int vss_restore, int json)
{
	enum cliret ret=CLIENT_OK;
	
#ifdef HAVE_WIN32
	// prevent sleep when idle
	SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
#endif
	
	switch((ret=do_client(conf, action, vss_restore, json)))
	{
		case CLIENT_RECONNECT:
			logp("Re-opening connection to server\n");
			sleep(5);
			ret=do_client(conf, action, vss_restore, json);
		default:
			break;
	}
	
#ifdef HAVE_WIN32
	// allow sleep when idle
	SetThreadExecutionState(ES_CONTINUOUS);
#endif

	// See enum cliret for return codes.
	return (int)ret;
}
Exemple #2
0
int			monitor(t_init *data)
{
  t_player_lst		*tmp;
  int			ret;
  struct timeval	tv;
  int			stay;

  init_monitor(data, &tv, &ret, &tmp);
  if ((select(max(data) + 1, &(data->read), &(data->write), NULL, &tv)) == -1)
    return (merror("select"));
  if (FD_ISSET(data->socket, &(data->read)))
    ret = do_server(data);
  else
    {
      stay = 1;
      while (stay && tmp != NULL)
	{
	  if (ret == 0 && FD_ISSET(tmp->player.fd, &(data->read)))
	    stay = do_client(tmp->player.fd, &tmp, data);
	  else
	    ret = 0;
	  tmp = tmp->next;
	}
    }
  check_timer(data);
  test_end(data);
  return (0);
}
int main (int argc, char *argv[])
{
  int result = 0;
  in_addr_t srv_ip_addr = (in_addr_t)-1;

  if (!init_libs ())
  {
    fprintf (stderr, "Can't initialize libs.\n");
    return 99;
  }

  if (argc < 2)
  {
    srv_ip_addr = htonl (INADDR_LOOPBACK);
    printf ("No server_part address is specified. Using loopback address.\n");
  }
  else if ((in_addr_t)-1 == (srv_ip_addr = inet_addr (argv[1])) || (in_addr_t)0 == srv_ip_addr)
  {
    result = 99;
    fprintf (stderr, "\"%s\" is not valid IPv4 address\n", argv[1]);
    print_usage (argc > 0 ? argv[0] : NULL);
  }

  if (0 == result)
    result = do_client (srv_ip_addr);

  if (result)
    fprintf (stderr, "\nFinished with some error.\n");
  else
    printf ("\nFinished without any errors.\n");

  deinit_libs ();
  return result;
}
Exemple #4
0
int main(int argc, char *argv[])
{
	int rv;

	memset(&cl, 0, sizeof(cl));

	rv = read_arguments(argc, argv);
	if (rv < 0)
		goto out;

	switch (cl.type) {
	case ACT_ARBITRATOR:
		rv = do_arbitrator();
		break;

	case ACT_SITE:
		rv = do_site();
		break;

	case ACT_CLIENT:
		rv = do_client();
		break;
	}

out:
	return rv ? EXIT_FAILURE : EXIT_SUCCESS;
}
Exemple #5
0
void *client(void *arg) {
    CLI *c=arg;

#ifdef DEBUG_STACK_SIZE
    stack_info(1); /* initialize */
#endif
    log(LOG_DEBUG, "%s started", c->opt->servname);
#ifndef USE_WIN32
    if(c->opt->option.remote && c->opt->option.program)
        c->local_rfd.fd=c->local_wfd.fd=connect_local(c);
            /* connect and exec options specified together */
            /* spawn local program instead of stdio */
#endif
    c->remote_fd.fd=-1;
    c->ssl=NULL;
    cleanup(c, do_client(c));
#ifdef USE_FORK
    if(!c->opt->option.remote) /* 'exec' specified */
        exec_status(); /* null SIGCHLD handler was used */
#else
    enter_critical_section(CRIT_CLIENTS); /* for multi-cpu machines */
    log(LOG_DEBUG, "%s finished (%d left)", c->opt->servname,
        --num_clients);
    leave_critical_section(CRIT_CLIENTS);
#endif
    free(c);
#ifdef DEBUG_STACK_SIZE
    stack_info(0); /* display computed value */
#endif
    return NULL;
}
Exemple #6
0
int main(int argc, char *argv[])
{
    if( argc > 1 )
        do_client(argv[1]);
    else
        do_server();

    return 0;
}
Exemple #7
0
int main(int argc, char **argv)
{
    pid_t pid;

    pid = fork();
    
    if (pid == -1) {
        perror("fork");
        exit(EXIT_FAILURE);        
    } else if (pid == 0) {
        // クライアント(子プロセス)
        int shmfd;
        
        // Unix ドメインクライントを作り shmfd を受信
        shmfd = do_client();

        // shmfd を使って mmap() を行い共有メモリに書き込み
        void *addr;
        addr = mmap(NULL, TEMPFILE_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
        if (addr == MAP_FAILED) {
            perror("mmap");
            exit(EXIT_FAILURE);
        }
        sprintf((char*)addr, "ABCDEFG");

        close(shmfd);        
    }  else {
        // サーバー(親プロセス)

        // 共有ファイルの file descriptor を取得
        int shmfd;
        shmfd = create_shm_file();

        // Unix ドメインサーバを作り shmfd を送信
        do_server(shmfd);

        // 子プロセスの終了を待つ
        if (waitpid(pid, NULL, 0) == -1) {
            perror("waitpid");
            exit(EXIT_FAILURE);
        }

        // shmfd を使って mmap() を行い共有メモリの内容を表示
        void *addr;
        addr = mmap(NULL, TEMPFILE_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
        if (addr == MAP_FAILED) {
            perror("mmap");
            exit(EXIT_FAILURE);
        }
        close(shmfd);

        // 子プロセスが書き込んだ内容が見えれば成功
        puts((const char*)addr);
    }

    return 0;
}
Exemple #8
0
static void run_client(CLI *c) {
    int error;

    c->remote_fd.fd=-1;
    c->fd=-1;
    c->ssl=NULL;
    c->sock_bytes=c->ssl_bytes=0;

    error=setjmp(c->err);
    if(!error)
        do_client(c);

    s_log(LOG_NOTICE,
        "Connection %s: %d bytes sent to SSL, %d bytes sent to socket",
         error==1 ? "reset" : "closed", c->ssl_bytes, c->sock_bytes);

        /* cleanup temporary (e.g. IDENT) socket */
    if(c->fd>=0)
        closesocket(c->fd);

        /* cleanup SSL */
    if(c->ssl) { /* SSL initialized */
        SSL_set_shutdown(c->ssl, SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
        SSL_free(c->ssl);
        ERR_remove_state(0);
    }

        /* cleanup remote socket */
    if(c->remote_fd.fd>=0) { /* remote socket initialized */
        if(error==1 && c->remote_fd.is_socket)
            reset(c->remote_fd.fd, "linger (remote)");
        closesocket(c->remote_fd.fd);
    }

        /* cleanup local socket */
    if(c->local_rfd.fd>=0) { /* local socket initialized */
        if(c->local_rfd.fd==c->local_wfd.fd) {
            if(error==1 && c->local_rfd.is_socket)
                reset(c->local_rfd.fd, "linger (local)");
            closesocket(c->local_rfd.fd);
        } else { /* STDIO */
            if(error==1 && c->local_rfd.is_socket)
                reset(c->local_rfd.fd, "linger (local_rfd)");
            if(error==1 && c->local_wfd.is_socket)
                reset(c->local_wfd.fd, "linger (local_wfd)");
       }
    }
#ifdef USE_FORK
    if(!c->opt->option.remote) /* 'exec' specified */
        child_status(); /* null SIGCHLD handler was used */
#else
    enter_critical_section(CRIT_CLIENTS); /* for multi-cpu machines */
    s_log(LOG_DEBUG, "Service %s finished (%d left)", c->opt->servname,
        --num_clients);
    leave_critical_section(CRIT_CLIENTS);
#endif
}
Exemple #9
0
int main(int argc, char *argv[]){

	int sockfd;
	int fd;
	struct sockaddr_in cli_addr, serv_addr;
	int portnumber;

	if(argc!=4){
	
		printf("Usage : %s [serv.addr] [port] [fichier]\n", argv[0]);
		exit(-1);
	}
	
	portnumber = atoi(argv[2]);
	if(portnumber<1){
	
		printf("Erreur dans le port\n");
		exit(-1);
	}

	if((fd = open(argv[3], O_RDONLY)) == -1){
	
		perror("Erreur dans l'ouverture du fichier de configuration\n");
		exit(-1);
	}
	
	bzero((char *) &serv_addr, sizeof(serv_addr));
	serv_addr.sin_family = AF_INET;
	serv_addr.sin_addr.s_addr = inet_addr(argv[1]);
	serv_addr.sin_port = htons(portnumber);
	
	if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
	
		perror("Erreur dan la création du socket\n");
		exit(-1);
	}
	
	bzero((char *) &cli_addr, sizeof(cli_addr));
	cli_addr.sin_family = AF_INET;
	cli_addr.sin_addr.s_addr = htonl(INADDR_ANY);
	cli_addr.sin_port = htons(0);
	
	if(bind(sockfd, (struct sockaddr *) &cli_addr, sizeof(cli_addr)) < 0){
	
		perror("Client : erreur dans bind\n");
		exit(-1);
	}
	
	do_client(fd, sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
	
	close(fd);
	close(sockfd);
	
	return EXIT_SUCCESS;
}
int main(int argc,char **argv)
{
  if (argc == 2) {
    if (!strcmp(argv[1],"client"))
      return do_client();
    else if (!strcmp(argv[1],"server"))
      return do_server();
  }

  printf("Usage: system_transport-test <client / server>\n");
  return -1;
}
Exemple #11
0
int client(struct config *conf, enum action act, int vss_restore, int json)
{
	int ret=0;
	
#if defined(HAVE_WIN32)
	// prevent sleep when idle
	SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
#endif
	
	if((ret=do_client(conf, act, vss_restore, json))==1)
	{
		logp("Re-opening connection to server\n");
		sleep(5);
		ret=do_client(conf, act, vss_restore, json);
	}
	
#if defined(HAVE_WIN32)
	// allow sleep when idle
	SetThreadExecutionState(ES_CONTINUOUS);
#endif
	
	return ret;
}
Exemple #12
0
int main(void) {
	printf ("libnet chat client version %d.%d\n", VER_MAJOR, VER_MINOR);
	printf ("built at " __TIME__ " on " __DATE__ "\n");
	printf ("\n");

	net_init();
	net_loadconfig (NULL);

	get_driver();
	init();

	do_client();

	return 0;
}
Exemple #13
0
int 
main(int argc, char *argv[])
{

   if (argc < 3) {
      usage(argv);
      exit(1);
   }

   isserver = argv[1][0] == 's';
   if (isserver) {
      if (argc != 3) {
         usage(argv);
         exit(1);
      }
      srcportno = atoi (argv[2]);
      netcardno = __sysinfo.si_nnetworks - 1;
      startinpackets = __sysinfo.si_networks[netcardno].rcvs;
      startoutpackets = __sysinfo.si_networks[netcardno].xmits;
      do_server ();

   } else {
      if (argc < 6) {
         usage(argv);
         exit(1);
      }
      host = argv[2];
      myhost = argv[3];
      pktcnt = atoi(argv[4]);
      pktdata = atoi(argv[5]);
      if (argc >= 7) {
         ackfreq = atoi(argv[6]);
      }
      if (argc >= 8) {
         ackdata = atoi(argv[7]);
      }

      do_client ();
   }

   if (netcardno >= 0) {
      printf ("%s done (netin %qd, netout %qd)\n", argv[0], (__sysinfo.si_networks[netcardno].rcvs - startinpackets), (__sysinfo.si_networks[netcardno].xmits - startoutpackets));
   } else {
      printf ("%s done (netcardno %d)\n", argv[0], netcardno);
   }

   return 0;
}
Exemple #14
0
int main(int argc, char *argv[])
{
	if (!do_options(&argc, &argv))
		return EXIT_FAILURE;

	switch (mode) {
	case CLIENT:
		do_client(host, port, files);
		break;
	case SERVER:
		do_server(port);
		break;
	}

	return EXIT_SUCCESS;
}
client::client(int ac, char **av)
{  
  char buf[1024];
  struct sockaddr_in		sin;
  Game                          game;

  sin = sin;
  port = atoi(av[1]);
  pe = getprotobyname("TCP");
  s = socket(AF_INET, SOCK_STREAM, pe->p_proto);
  if (s == -1)
    {
      write(2, "socket", strlen("socket"));
      exit(EXIT_FAILURE);
    }
  sin.sin_family = AF_INET;
  sin.sin_port = htons(port);
  sin.sin_addr.s_addr = inet_addr(av[2]);
  error = connect(s, (const struct sockaddr *)&sin, sizeof(sin));

  if (error == -1)
    {
      write(2, "connect", strlen("connect"));
      close(s);
      exit(EXIT_FAILURE);
    }
  std::cout << "ok" << std::endl;
  do_client(s);

  game.set_cmp(recup_info(s));
  game.set_cmp(recup_info(s));
  while(game.getMywindow().isOpen())
    {
      if (game.get_cmp() != NULL)
	{
	  game.pars();
	  game.getMywindow().clear();
	  game.getMywindow().display();
	}
      game.update();	
      game.draw();
	  
      std::cout << "end" << std::endl;
      //      return;
    }
}
Exemple #16
0
int main(int argc, const char *argv[])
{
	int peerfd = socket(PF_INET, SOCK_STREAM, 0);
	if(peerfd == -1)
		ERR_EXIT("socket");

	struct sockaddr_in server_addr;
	server_addr.sin_family = PF_INET;
	server_addr.sin_port = htons(8989);
	server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");

	if(connect(peerfd, (struct sockaddr*)&server_addr, sizeof(server_addr)) < 0)
		ERR_EXIT("connect");

	do_client(peerfd);
	close(peerfd);
	return 0;
}
Exemple #17
0
void *client(void *arg) {
    CLI *c=arg;

#ifdef DEBUG_STACK_SIZE
    stack_info(1); /* initialize */
#endif
    s_log(LOG_DEBUG, "%s started", c->opt->servname);
    if(alloc_fd(c->local_rfd.fd))
        return NULL;
    if(c->local_wfd.fd!=c->local_rfd.fd)
        if(alloc_fd(c->local_wfd.fd))
            return NULL;
#ifndef USE_WIN32
    if(c->opt->option.remote && c->opt->option.program)
        c->local_rfd.fd=c->local_wfd.fd=connect_local(c);
            /* connect and exec options specified together */
            /* spawn local program instead of stdio */
#endif
    c->remote_fd.fd=-1;
    c->ssl=NULL;
    cleanup(c, do_client(c));
#ifdef USE_FORK
    if(!c->opt->option.remote) /* 'exec' specified */
        child_status(); /* null SIGCHLD handler was used */
#else
    enter_critical_section(CRIT_CLIENTS); /* for multi-cpu machines */
    s_log(LOG_DEBUG, "%s finished (%d left)", c->opt->servname,
        --num_clients);
    leave_critical_section(CRIT_CLIENTS);
#endif
    free(c);
#ifdef DEBUG_STACK_SIZE
    stack_info(0); /* display computed value */
#endif
#ifdef USE_WIN32
    _endthread();
#endif
#ifdef USE_UCONTEXT
    s_log(LOG_DEBUG, "Context %ld closed", ready_head->id);
    s_poll_wait(NULL, 0); /* wait on poll() */
    s_log(LOG_ERR, "INTERNAL ERROR: failed to drop context");
#endif
    return NULL;
}
int
main(int argc, char *argv[])
{
	int err;

	ct_arg0 = argv[0];

	if (argc != 2) {
		usage();
	}

	if (strcmp(argv[1], "server") == 0) {
		err = do_server(ct_port);
	} else {
		err = do_client(ct_port, argv[1]);
	}

	return (err);
}
Exemple #19
0
int main(int argc, char *argv[], char *envp[])
{
	int rv;

	init_set_proc_title(argc, argv, envp);
	get_secs(&start_time);

	memset(&cl, 0, sizeof(cl));
	strncpy(cl.configfile,
			BOOTH_DEFAULT_CONF, BOOTH_PATH_LEN - 1);
	cl.lockfile[0] = 0;
	debug_level = 0;
	cl_log_set_entity("booth");
	cl_log_enable_stderr(TRUE);
	cl_log_set_facility(0);


	rv = read_arguments(argc, argv);
	if (rv < 0)
		goto out;


	switch (cl.type) {
	case STATUS:
		rv = do_status(cl.type);
		break;

	case ARBITRATOR:
	case DAEMON:
	case SITE:
		rv = do_server(cl.type);
		break;

	case CLIENT:
		rv = do_client();
		break;
	}

out:
	/* Normalize values. 0x100 would be seen as "OK" by waitpid(). */
	return (rv >= 0 && rv < 0x70) ? rv : 1;
}
Exemple #20
0
void    connect_client(t_server *server)
{
  int   i;

  server->actual = 0;
  server->fd_max = server->fd_socket;
  while (1)
    {
      FD_ZERO(&server->readf);
      FD_SET(server->fd_socket, &server->readf);
      for(i = 0 ; i < server->actual ; i++)
        {
          FD_SET(clients[i].sock, &server->readf);
	}
      if (select(server->fd_max + 1, &server->readf, NULL, NULL, NULL) == -1)
	perror("select");
      if (FD_ISSET(server->fd_socket, &server->readf))
	new_client(server);
      do_client(server);  
    }
}
Exemple #21
0
int main(int argc, char *argv[])
{
	int rv;

	memset(&cl, 0, sizeof(cl));
	strncpy(cl.configfile, BOOTH_DEFAULT_CONF,     BOOTH_PATH_LEN - 1);
	strncpy(cl.lockfile,   BOOTH_DEFAULT_LOCKFILE, BOOTH_PATH_LEN - 1);

	rv = read_arguments(argc, argv);
	if (rv < 0)
		goto out;

	if (cl.type == ACT_CLIENT) {
		cl_log_enable_stderr(TRUE);
		cl_log_set_facility(0);
	} else {
		cl_log_set_entity(logging_entity);
		cl_log_enable_stderr(debug_level ? TRUE : FALSE);
		cl_log_set_facility(HA_LOG_FACILITY);
	}
	cl_inherit_logging_environment(0);

	switch (cl.type) {
	case ACT_ARBITRATOR:
		rv = do_server(ARBITRATOR);
		break;

	case ACT_SITE:
		rv = do_server(SITE);
		break;

	case ACT_CLIENT:
		rv = do_client();
		break;
	}

out:
	return rv ? EXIT_FAILURE : EXIT_SUCCESS;
}
Exemple #22
0
int main(int argc, char *argv[]){
  bool is_server;

  /* mainでは,do_serverとdo_clientを呼ぶだけ */

  if(strcmp(argv[1], "server") != 0 && strcmp(argv[1], "client") != 0){
    puts("USAGE: 11-2 server");
    puts("USAGE: 11-2 client <server> <host>");
    exit(EXIT_FAILURE);
  }
  is_server = strcmp(argv[1], "server") == 0;
  char* server = argv[2];
  char* port = argv[3];

  if (is_server) {
    do_server();
  } else {
    do_client(server, port);
  }

  exit(EXIT_SUCCESS);
}
Exemple #23
0
/**
 * Main entry point. Doesn't do much except works out whether we are a client
 * or a server.
 */
int main(int argc, char *argv[])
{
#ifdef WIN32
    WSADATA wsaData;
    WORD wVersionRequested = MAKEWORD(2, 2);
    WSAStartup(wVersionRequested, &wsaData);
#elif !defined(CONFIG_PLATFORM_SOLARIS)
    signal(SIGPIPE, SIG_IGN);           /* ignore pipe errors */
#endif

    if (argc == 2 && strcmp(argv[1], "version") == 0)    {
        printf("axssl %s %s\n", ssl_version(), __DATE__);
        exit(0);
    }

    if (argc < 2 || (
            strcmp(argv[1], "s_server") && strcmp(argv[1], "s_client")))
        print_options(argc > 1 ? argv[1] : "");

    strcmp(argv[1], "s_server") ?
    do_client(argc, argv) : do_server(argc, argv);
    return 0;
}
Exemple #24
0
static int client(int offset)
{
	int file_fd, out_fd;
	char fname[64];

	bind_to_cpu(offset);
	if (nice(-20) < 0)
		perror("nice");

	if (!write_to_null)
		out_fd = client_open_net(offset);
	else
		out_fd = open("/dev/null", O_WRONLY);

	if (out_fd < 0)
		return error("socket");

	sprintf(fname, "%s%d", filename, same_file ? 0 : offset);
	file_fd = open(fname, O_RDONLY);
	if (file_fd < 0)
		return error("open");

	return do_client(out_fd, file_fd, offset);
}
Exemple #25
0
int main(int argc, char **argv)
{
    BIO *conn;
    SSL *ssl;
    SSL_CTX *ctx;

    init_openssl();
    seed_prng(64);

    ctx = setup_client_ctx();

    conn = BIO_new_connect(SERVER ":" PORT);
    if(!conn)
        log_err("Failed create bio connection");

    if(BIO_do_connect(conn) <= 0)
        log_err("Failed connecting to remote host");

    if(!(ssl = SSL_new(ctx)))
        log_err("Error creating an SSL context.");
    SSL_set_bio(ssl, conn, conn);
    if(SSL_connect(ssl) <= 0)
        log_err("Error connecting SSL object.");

    fprintf(stderr, "Connection opened\n");
    if(do_client(ssl))
        SSL_shutdown(ssl);
    else
        SSL_clear(ssl);
    fprintf(stderr, "Connection closed\n");

    //BIO_free(conn);
    SSL_free(ssl);
    SSL_CTX_free(ctx);
    return 0;
}
Exemple #26
0
static int
rxperf_client(int argc, char **argv)
{
    char *host = DEFAULT_HOST;
    int bytes = DEFAULT_BYTES;
    short port = DEFAULT_PORT;
    char *filename = NULL;
    afs_int32 cmd;
    int sendbytes = 3;
    int readbytes = 30;
    int times = 100;
    int dumpstats = 0;
    int nojumbo = 0;
    int nostats = 0;
    int maxmtu = 0;
    int hotthreads = 0;
    int threads = 1;
    int udpbufsz = 64 * 1024;
    int maxwsize = 0;
    int minpeertimeout = 0;
    char *ptr;
    int ch;

    cmd = RX_PERF_UNKNOWN;

    while ((ch = getopt(argc, argv, "T:S:R:b:c:d:p:P:r:s:w:W:f:HDNjm:u:4:t:V")) != -1) {
	switch (ch) {
	case 'b':
	    bytes = strtol(optarg, &ptr, 0);
	    if (ptr && *ptr != '\0')
		errx(1, "can't resolve number of bytes to transfer");
	    break;
	case 'c':
	    if (strcasecmp(optarg, "send") == 0)
		cmd = RX_PERF_SEND;
	    else if (strcasecmp(optarg, "recv") == 0)
		cmd = RX_PERF_RECV;
	    else if (strcasecmp(optarg, "rpc") == 0)
		cmd = RX_PERF_RPC;
	    else if (strcasecmp(optarg, "file") == 0)
		cmd = RX_PERF_FILE;
	    else
		errx(1, "unknown command %s", optarg);
	    break;
	case 'd':
#ifdef RXDEBUG
	    rx_debugFile = fopen(optarg, "w");
	    if (rx_debugFile == NULL)
		err(1, "fopen %s", optarg);
#else
	    errx(1, "compiled without RXDEBUG");
#endif
	    break;
	case 'P':
	    minpeertimeout = strtol(optarg, &ptr, 0);
	    if (ptr != 0 && ptr[0] != '\0')
		errx(1, "can't resolve min peer timeout");
	    break;
	case 'p':
	    port = (short) strtol(optarg, &ptr, 0);
	    if (ptr != 0 && ptr[0] != '\0')
		errx(1, "can't resolve portname");
	    break;
	case 'r':
	    rxread_size = strtol(optarg, &ptr, 0);
	    if (ptr != 0 && ptr[0] != '\0')
		errx(1, "can't resolve readsize");
	    if (rxread_size > sizeof(somebuf))
		errx(1, "%d > sizeof(somebuf) (%"AFS_SIZET_FMT")", rxread_size,
		     sizeof(somebuf));
	    break;
	case 's':
	    host = strdup(optarg);
	    if (host == NULL)
		err(1, "strdup");
	    break;
	case 'V':
	    use_rx_readv = 1;
	    break;
	case 'w':
	    rxwrite_size = strtol(optarg, &ptr, 0);
	    if (ptr != 0 && ptr[0] != '\0')
		errx(1, "can't resolve writesize");
	    if (rxwrite_size > sizeof(somebuf))
		errx(1, "%d > sizeof(somebuf) (%"AFS_SIZET_FMT")", rxwrite_size,
		     sizeof(somebuf));
	    break;
	case 'W':
	    maxwsize = strtol(optarg, &ptr, 0);
	    if (ptr && *ptr != '\0')
		errx(1, "can't resolve max send/recv window size (packets)");
	    break;
	case 'T':
	    times = strtol(optarg, &ptr, 0);
	    if (ptr && *ptr != '\0')
		errx(1, "can't resolve number of times to execute rpc");
	    break;
	case 'S':
	    sendbytes = strtol(optarg, &ptr, 0);
	    if (ptr && *ptr != '\0')
		errx(1, "can't resolve number of bytes to send");
	    break;
	case 'R':
	    readbytes = strtol(optarg, &ptr, 0);
	    if (ptr && *ptr != '\0')
		errx(1, "can't resolve number of bytes to receive");
	    break;
	case 't':
#ifdef AFS_PTHREAD_ENV
	    threads = strtol(optarg, &ptr, 0);
	    if (ptr && *ptr != '\0')
		errx(1, "can't resolve number of threads to execute");
            if (threads > MAX_THREADS)
		errx(1, "too many threads");
#else
            errx(1, "Not built for pthreads");
#endif
	    break;
	case 'f':
	    filename = optarg;
	    break;
	case 'D':
	    dumpstats = 1;
	    break;
	case 'N':
	    nostats = 1;
	    break;
	case 'H':
	    hotthreads = 1;
	    break;
	case 'j':
	  nojumbo=1;
	  break;
	case 'm':
	    maxmtu = strtol(optarg, &ptr, 0);
	    if (ptr && *ptr != '\0')
		errx(1, "can't resolve rx maxmtu to use");
	    break;
	case 'u':
	    udpbufsz = strtol(optarg, &ptr, 0) * 1024;
	    if (ptr && *ptr != '\0')
		errx(1, "can't resolve upd buffer size (Kbytes)");
	    break;
	case '4':
	  RX_IPUDP_SIZE = 28;
	  break;
	default:
	    usage();
	}
    }

    if (nostats && dumpstats)
        errx(1, "cannot set both -N and -D");

    if (threads > 1 && cmd == RX_PERF_FILE)
        errx(1, "cannot use multiple threads with file command");

    if (optind != argc)
	usage();

    if (cmd == RX_PERF_UNKNOWN)
	errx(1, "no command given to the client");

    do_client(host, port, filename, cmd, times, bytes, sendbytes,
	      readbytes, dumpstats, nojumbo, maxmtu, maxwsize, minpeertimeout,
              udpbufsz, nostats, hotthreads, threads);

    return 0;
}
Exemple #27
0
Fichier : rpc.c Projet : CCI/cci
int main(int argc, char *argv[])
{
	int ret, c;
	uint32_t caps = 0;
	char *transport = NULL;
	cci_device_t * const *devices = NULL, *device = NULL;

	name = argv[0];

	opts.iters = ITERS;
	opts.warmup = WARMUP;
	opts.req_size = REQ_SIZE;
	opts.transfer_size = TRANSFER_SIZE;
	opts.ack_size = ACK_SIZE;

	while ((c = getopt(argc, argv, "h:st:i:W:c:wrR:T:A:S")) != -1) {
		switch (c) {
		case 'h':
			strncpy(server_uri, optarg, sizeof(server_uri));
			break;
		case 's':
			is_server = 1;
			break;
		case 't':
			transport = strdup(optarg);
			break;
		case 'i':
			opts.iters = strtoul(optarg, NULL, 0);
			break;
		case 'W':
			opts.warmup = strtoul(optarg, NULL, 0);
			break;
		case 'c':
			concurrent = strtoul(optarg, NULL, 0);
			if (concurrent > 64)
				concurrent = 64;
			break;
		case 'w':
			/* The client wants to write. The server will RMA Read. */
			opts.rma_flags = CCI_FLAG_READ;
			break;
		case 'r':
			/* The client wants to read. The server will RMA Write. */
			opts.rma_flags = CCI_FLAG_WRITE;
			break;
		case 'R':
			opts.req_size = strtoul(optarg, NULL, 0);
			if (opts.req_size > REQ_SIZE)
				opts.req_size = REQ_SIZE;
			break;
		case 'T':
			opts.transfer_size = strtoul(optarg, NULL, 0);
			break;
		case 'A':
			opts.ack_size = strtoul(optarg, NULL, 0);
			if (opts.ack_size > ACK_SIZE)
				opts.ack_size = ACK_SIZE;
			break;
		case 'S':
			suppress = 1;
			break;
		default:
			print_usage();
		}
	}

	if (!opts.rma_flags)
		opts.rma_flags = CCI_FLAG_READ;

	if (!opts.transfer_size)
		opts.transfer_size = TRANSFER_SIZE;

#ifndef USE_MPI
	if (!is_server && server_uri[0] == '\0') {
		fprintf(stderr, "Must select -h or -s\n");
		print_usage();
	}
#else
	MPI_Init(&argc, &argv);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);

	if (rank == 0)
		is_server = 1;
#endif

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
	check_return(NULL, "cci_init", ret, 1);

	if (transport) {
		int i = 0;
		ret = cci_get_devices(&devices);
		check_return(NULL, "cci_get_devices", ret, 1);

		/* Select first device that matches transport. */
		for (i = 0; ; i++) {
			device = devices[i];

			if (!device)
				break;

			if (strncmp(device->transport, transport, strlen(device->transport)) == 0)
				break;
		}
	}

	/* create an endpoint */
	ret = cci_create_endpoint(device, 0, &endpoint, NULL);
	check_return(NULL, "cci_create_endpoint", ret, 1);

	ret = cci_get_opt(endpoint, CCI_OPT_ENDPT_URI, &uri);
	check_return(endpoint, "cci_get_opt", ret, 1);

	if (!suppress)
		printf("Opened %s\n", uri);

	if (is_server)
		do_server();
	else
		do_client();

	/* clean up */
	ret = cci_destroy_endpoint(endpoint);
	check_return(endpoint, "cci_destroy_endpoint", ret, 1);

	if (buffer)
		free(buffer);

	free(transport);
	free(uri);

	ret = cci_finalize();
	check_return(NULL, "cci_finalize", ret, 1);

#ifdef USE_MPI
	MPI_Barrier();
	MPI_Finalize();
#endif
	return 0;
}
Exemple #28
0
int main (int argc, char *argv[])
{
	int ret, c;
	uint32_t caps	= 0;
	char *ctl_uri	= NULL;

	name = argv[0];

	while ((c = getopt (argc, argv, "h:s")) != -1) {
		switch (c) {
			case 'h':
				server_uri = strdup (optarg);
				break;
			case 's':
				is_server = 1;
				break;
			default:
				print_usage ();
		}
	}

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
        if (ret) {
                fprintf(stderr, "cci_init() failed with %s\n",
                        cci_strerror(NULL, ret));
                exit(EXIT_FAILURE);
        }

	/* Create the endpoint for the control connection */
	ret = cci_create_endpoint(NULL, 0, &ctl_ep, NULL);
	if (ret) {                                                              
                fprintf(stderr, "cci_create_endpoint() failed with %s\n",       
                        cci_strerror(NULL, ret));                               
                exit(EXIT_FAILURE);                                             
        }

	ret = cci_get_opt(ctl_ep,                                             
                          CCI_OPT_ENDPT_URI, &ctl_uri);                             
        if (ret) {                                                              
                fprintf(stderr, "cci_get_opt() failed with %s\n", cci_strerror(NULL, ret));
                exit(EXIT_FAILURE);                                             
        }                                                                       
        printf("Opened control connection %s\n", ctl_uri);

	if (is_server)
		do_server ();
	else
		do_client ();

	ret = cci_destroy_endpoint (ctl_ep);
	if (ret) {
		fprintf (stderr, "cci_destroy_endpoint() failed with %s\n",
		         cci_strerror (NULL, ret));
		exit (EXIT_FAILURE);
	}

	free (server_uri);

	ret = cci_finalize ();
	if (ret) {
		fprintf (stderr, "cci_finalize() failed with %s\n",
		         cci_strerror (NULL, ret));
		exit (EXIT_FAILURE);
	}

	return 0;
}
Exemple #29
0
int main(int argc, char *argv[])
{
	int ret, c;
	uint32_t caps = 0;
	cci_os_handle_t *os_handle = NULL;
	char *uri = NULL;
	pid_t pid = 0;

	pid = getpid();
	srandom(pid);

	memset(&msg, 0, sizeof(msg));

	name = argv[0];

	while ((c = getopt(argc, argv, "h:si:c:wrl:o:O:R:BI")) != -1) {
		switch (c) {
		case 'h':
			server_uri = strdup(optarg);
			is_client = 1;
			break;
		case 's':
			is_server = 1;
			break;
		case 'i':
			iters = strtoul(optarg, NULL, 0);
			break;
		case 'c':
			if (strncasecmp("ru", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_RU;
			else if (strncasecmp("ro", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_RO;
			else
				print_usage();
			printf("Using %s connection\n",
			       attr == CCI_CONN_ATTR_RU ? "RU" : "RO");
			break;
		case 'w':
			opts.method = RMA_WRITE;
			break;
		case 'r':
			opts.method = RMA_READ;
			break;
		case 'l':
			length = strtoul(optarg, NULL, 0);
			break;
		case 'R':
			opts.reg_len = strtoul(optarg, NULL, 0);
			break;
		case 'o':
			local_offset = strtoul(optarg, NULL, 0);
			break;
		case 'O':
			remote_offset = strtoul(optarg, NULL, 0);
			break;
		case 'B':
			blocking = 1;
			os_handle = &fd;
			break;
		case 'I':
			ignore_os_handle = 1;
			os_handle = &fd;
			break;
		default:
			print_usage();
		}
	}

	if (!is_server && !server_uri) {
		fprintf(stderr, "Must select -h or -s\n");
		print_usage();
	}

	if (is_server && is_client) {
		fprintf(stderr, "Must select -h or -s, not both\n");
		print_usage();
	}

	if (blocking && ignore_os_handle) {
		fprintf(stderr, "-B and -I are not compatible.\n");
		fprintf(stderr, "-B will block using select() using the OS handle.\n");
		fprintf(stderr, "-I will obtain the OS handle, but not use it to wait.\n");
		print_usage();
	}

	if (!opts.method)
		opts.method = RMA_WRITE;

	if (!opts.reg_len) {
		if (!length) {
			opts.reg_len = RMA_REG_LEN;
		} else {
			opts.reg_len = length;
		}
	}

	if (!length) {
		if (!opts.reg_len)
			length = RMA_REG_LEN;
		else
			length = opts.reg_len;
	}

	if (opts.reg_len == length) {
		if (local_offset || remote_offset) {
			fprintf(stderr, "*** RMA registration length == RMA length "
					"and an offset was requested. ***\n"
					"*** This should cause an error. ***\n");
		}
	}

	if (is_client)
		fprintf(stderr, "Testing with local_offset %"PRIu64" "
				"remote_offset %"PRIu64" "
				"reg_len %"PRIu64" length %"PRIu64"\n",
				local_offset, remote_offset, opts.reg_len, length);

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
	if (ret) {
		fprintf(stderr, "cci_init() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	/* create an endpoint */
	ret = cci_create_endpoint(NULL, 0, &endpoint, os_handle);
	if (ret) {
		fprintf(stderr, "cci_create_endpoint() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	ret = cci_get_opt(endpoint,
			  CCI_OPT_ENDPT_URI, &uri);
	if (ret) {
		fprintf(stderr, "cci_get_opt() failed with %s\n", cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}
	printf("Opened %s\n", uri);

	if (blocking) {
		nfds = fd + 1;
		FD_ZERO(&rfds);
		FD_SET(fd, &rfds);
	}

	if (is_server)
		do_server();
	else
		do_client();

	/* clean up */
	ret = cci_destroy_endpoint(endpoint);
	if (ret) {
		fprintf(stderr, "cci_destroy_endpoint() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}
	free(buffer);
	free(uri);
	free(server_uri);

	ret = cci_finalize();
	if (ret) {
		fprintf(stderr, "cci_finalize() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	return 0;
}
Exemple #30
0
int main(int argc, char *argv[])
{
	int ret, c;
	uint32_t caps = 0;
	cci_os_handle_t *os_handle = NULL;
	char *uri = NULL;

	name = argv[0];

	while ((c = getopt(argc, argv, "h:sRc:nwrm:Ci:W:bo")) != -1) {
		switch (c) {
		case 'h':
			server_uri = strdup(optarg);
			break;
		case 's':
			is_server = 1;
			break;
		case 'R':
			accept = 0;
			break;
		case 'i':
			iters = strtoul(optarg, NULL, 0);
			break;
		case 'W':
			warmup = strtoul(optarg, NULL, 0);
			break;
		case 'c':
			if (strncasecmp("ru", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_RU;
			else if (strncasecmp("ro", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_RO;
			else if (strncasecmp("uu", optarg, 2) == 0)
				attr = CCI_CONN_ATTR_UU;
			else
				print_usage();
			printf("Using %s connection\n",
			       attr == CCI_CONN_ATTR_UU ? "UU" : attr ==
			       CCI_CONN_ATTR_RU ? "RU" : "RO");
			break;
		case 'n':
			opts.flags = CCI_FLAG_NO_COPY;
			break;
		case 'w':
			opts.method = RMA_WRITE;
			break;
		case 'r':
			opts.method = RMA_READ;
			break;
		case 'm':
			opts.max_rma_size = strtoul(optarg, NULL, 0);
			break;
		case 'C':
			remote_completion = 1;
			break;
		case 'b':
			blocking = 1;
			os_handle = &fd;
			break;
		case 'o':
			ignore_os_handle = 1;
			os_handle = &fd;
			break;
		default:
			print_usage();
		}
	}

	if (!is_server && !server_uri) {
		fprintf(stderr, "Must select -h or -s\n");
		print_usage();
	}

	if (blocking && ignore_os_handle) {
		fprintf(stderr, "-b and -o are not compatible.\n");
		fprintf(stderr, "-b will block using select() using the OS handle.\n");
		fprintf(stderr, "-o will obtain the OS handle, but not use it to wait.\n");
		print_usage();
	}

	if (attr == CCI_CONN_ATTR_UU) {
		if (opts.method != MSGS) {
			fprintf(stderr,
				"RMA %s not allowed with UU connections\n",
				opts.method == RMA_WRITE ? "WRITE" : "READ");
			print_usage();
		}
		if (opts.max_rma_size) {
			printf("ignoring max_rma_size (-m) with MSGs\n");
			opts.max_rma_size = 0;
		}
	} else {
		/* RO or RU */
		if (opts.flags == CCI_FLAG_NO_COPY) {
			printf("Ignoring CCI_FLAG_NO_COPY (-n) with RMA %s\n",
			       opts.method == RMA_WRITE ? "WRITE" : "READ");
			opts.flags &= ~(CCI_FLAG_NO_COPY);
		}
		if (!opts.max_rma_size)
			opts.max_rma_size = MAX_RMA_SIZE;
	}

	ret = cci_init(CCI_ABI_VERSION, 0, &caps);
	if (ret) {
		fprintf(stderr, "cci_init() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	/* create an endpoint */
	ret = cci_create_endpoint(NULL, 0, &endpoint, os_handle);
	if (ret) {
		fprintf(stderr, "cci_create_endpoint() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	ret = cci_get_opt(endpoint,
			  CCI_OPT_ENDPT_URI, &uri);
	if (ret) {
		fprintf(stderr, "cci_get_opt() failed with %s\n", cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}
	printf("Opened %s\n", uri);

	if (blocking) {
		nfds = fd + 1;
		FD_ZERO(&rfds);
		FD_SET(fd, &rfds);
	}

	if (is_server)
		do_server();
	else
		do_client();

	/* clean up */
	ret = cci_destroy_endpoint(endpoint);
	if (ret) {
		fprintf(stderr, "cci_destroy_endpoint() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}
	if (buffer)
		free(buffer);

	free(uri);
	free(server_uri);

	ret = cci_finalize();
	if (ret) {
		fprintf(stderr, "cci_finalize() failed with %s\n",
			cci_strerror(NULL, ret));
		exit(EXIT_FAILURE);
	}

	return 0;
}