@@ -903,11 +903,12 @@ set_input_mode(void)
903903
904904int main (int argc , const char * argv [])
905905{
906+ uint32_t buf [128 * 1024 ];
907+ uint32_t filter ;
908+ int length , retval , view ;
906909 int fd = -1 ;
907910 FILE * output = NULL , * input = NULL ;
908911 poptContext con ;
909- int retval ;
910- int view ;
911912 char c ;
912913 struct pollfd pollfds [2 ];
913914
@@ -961,70 +962,62 @@ int main(int argc, const char *argv[])
961962
962963 setvbuf (stdout , NULL , _IOLBF , BUFSIZ );
963964
964- if (1 ) {
965- uint32_t buf [128 * 1024 ];
966- uint32_t filter ;
967- int length ;
965+ filter = ~0 ;
966+ if (!option_iso )
967+ filter &= ~(1 << TCODE_STREAM_DATA );
968+ if (!option_cycle_start )
969+ filter &= ~(1 << TCODE_CYCLE_START );
970+ if (view == VIEW_STATS )
971+ filter = ~(1 << TCODE_CYCLE_START );
968972
969- filter = ~0 ;
970- if (!option_iso )
971- filter &= ~(1 << TCODE_STREAM_DATA );
972- if (!option_cycle_start )
973- filter &= ~(1 << TCODE_CYCLE_START );
974- if (view == VIEW_STATS )
975- filter = ~(1 << TCODE_CYCLE_START );
973+ ioctl (fd , NOSY_IOC_FILTER , filter );
976974
977- ioctl (fd , NOSY_IOC_FILTER , filter );
975+ ioctl (fd , NOSY_IOC_START );
978976
979- ioctl (fd , NOSY_IOC_START );
977+ pollfds [0 ].fd = fd ;
978+ pollfds [0 ].events = POLLIN ;
979+ pollfds [1 ].fd = STDIN_FILENO ;
980+ pollfds [1 ].events = POLLIN ;
980981
981- pollfds [0 ].fd = fd ;
982- pollfds [0 ].events = POLLIN ;
983- pollfds [1 ].fd = STDIN_FILENO ;
984- pollfds [1 ].events = POLLIN ;
985-
986- while (run ) {
987- if (input != NULL ) {
988- if (fread (& length , sizeof length , 1 , input ) != 1 )
982+ while (run ) {
983+ if (input != NULL ) {
984+ if (fread (& length , sizeof length , 1 , input ) != 1 )
985+ return 0 ;
986+ fread (buf , 1 , length , input );
987+ } else {
988+ poll (pollfds , 2 , -1 );
989+ if (pollfds [1 ].revents ) {
990+ read (STDIN_FILENO , & c , sizeof c );
991+ switch (c ) {
992+ case 'q' :
993+ if (output != NULL )
994+ fclose (output );
989995 return 0 ;
990- fread (buf , 1 , length , input );
991- } else {
992- poll (pollfds , 2 , -1 );
993- if (pollfds [1 ].revents ) {
994- read (STDIN_FILENO , & c , sizeof c );
995- switch (c ) {
996- case 'q' :
997- if (output != NULL )
998- fclose (output );
999- return 0 ;
1000- }
1001996 }
1002-
1003- if (pollfds [0 ].revents )
1004- length = read (fd , buf , sizeof buf );
1005- else
1006- continue ;
1007997 }
1008998
1009- if (output != NULL ) {
1010- fwrite (& length , sizeof length , 1 , output );
1011- fwrite (buf , 1 , length , output );
1012- }
999+ if (pollfds [0 ].revents )
1000+ length = read (fd , buf , sizeof buf );
1001+ else
1002+ continue ;
1003+ }
10131004
1014- switch (view ) {
1015- case VIEW_TRANSACTION :
1016- handle_packet (buf , length );
1017- break ;
1018- case VIEW_PACKET :
1019- print_packet (buf , length );
1020- break ;
1021- case VIEW_STATS :
1022- print_stats (buf , length );
1023- break ;
1024- }
1005+ if (output != NULL ) {
1006+ fwrite (& length , sizeof length , 1 , output );
1007+ fwrite (buf , 1 , length , output );
1008+ }
1009+
1010+ switch (view ) {
1011+ case VIEW_TRANSACTION :
1012+ handle_packet (buf , length );
1013+ break ;
1014+ case VIEW_PACKET :
1015+ print_packet (buf , length );
1016+ break ;
1017+ case VIEW_STATS :
1018+ print_stats (buf , length );
1019+ break ;
10251020 }
1026- } else {
1027- poptPrintUsage (con , stdout , 0 );
10281021 }
10291022
10301023 if (output != NULL )
0 commit comments