Changeset 1630:b7db925dbfd1 in roaraudio


Ignore:
Timestamp:
04/28/09 12:38:49 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added command ping to roarctl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roarclients/roarctl.c

    r1585 r1630  
    2626#include <pwd.h> 
    2727#include <grp.h> 
     28#include <sys/time.h> 
     29#include <time.h> 
    2830 
    2931int g_verbose = 0; 
     
    4648        "  help                    - Show this help\n" 
    4749        "  sleep TIME              - Sleeps for TIME seconds\n" 
     50        "  ping  NUM               - Do NUM pings using NOOP commands\n" 
    4851        "\n" 
    4952        "  standby, off            - Go into standby mode\n" 
     
    8184} 
    8285 
     86int ping (struct roar_connection * con, int num) { 
     87 struct timeval         try, ans; 
     88 struct roar_message    m; 
     89 register int           ret; 
     90 int i; 
     91 
     92 for (i = 0; i < num; i++) { 
     93  m.cmd = ROAR_CMD_NOOP; 
     94  m.datalen = 0; 
     95 
     96  gettimeofday(&try, NULL); 
     97  ret = roar_req(con, &m, NULL); 
     98  gettimeofday(&ans, NULL); 
     99 
     100  if ( ret == -1 ) 
     101   return -1; 
     102 
     103  while (ans.tv_sec > try.tv_sec) { 
     104   ans.tv_sec--; 
     105   ans.tv_usec += 1000000; 
     106  } 
     107  ans.tv_usec -= try.tv_usec; 
     108 
     109  printf("Pong from server: seq=%i time=%.2fms\n", i, ans.tv_usec/1000.0); 
     110 
     111  if ( i != (num - 1) ) 
     112   sleep(1); 
     113 } 
     114 
     115 return 0; 
     116} 
     117 
    83118void server_oinfo (struct roar_connection * con) { 
    84119 struct roar_stream s; 
     
    621656   sleep(atoi(argv[++i])); 
    622657 
     658  } else if ( !strcmp(k, "ping") ) { 
     659   if ( ping(&con, atoi(argv[++i])) == -1 ) { 
     660    fprintf(stderr, "Error: can not ping\n"); 
     661   } 
     662 
    623663  } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) { 
    624664   if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) { 
Note: See TracChangeset for help on using the changeset viewer.