@@ -70,7 +70,7 @@ COMMAND commands[];
7070extern int done ;
7171struct nc_session * session ;
7272volatile int interleave ;
73- int timed ;
73+ int timed , monitor ;
7474
7575static int cmd_disconnect (const char * arg , char * * tmp_config_file );
7676
@@ -1264,6 +1264,12 @@ cmd_timed_help(void)
12641264 printf ("timed [--help] [on | off]\n" );
12651265}
12661266
1267+ static void
1268+ cmd_monitor_help (void )
1269+ {
1270+ printf ("monitor [--help] [on | off]\n" );
1271+ }
1272+
12671273#ifdef NC_ENABLED_SSH_TLS
12681274
12691275static void
@@ -2557,6 +2563,61 @@ cmd_disconnect(const char *UNUSED(arg), char **UNUSED(tmp_config_file))
25572563 return EXIT_SUCCESS ;
25582564}
25592565
2566+ void
2567+ monitoring_clb (struct nc_session * sess , void * user_data )
2568+ {
2569+ int was_rawmode = 0 ;
2570+
2571+ (void )sess ;
2572+ (void )user_data ;
2573+
2574+ /* needed for the case that the user is typing a command */
2575+ if (lss .rawmode ) {
2576+ was_rawmode = 1 ;
2577+ linenoiseDisableRawMode (lss .ifd );
2578+ printf ("\n" );
2579+ }
2580+
2581+ fprintf (stdout , "Connection reset by peer.\n" );
2582+ fflush (stdout );
2583+
2584+ /* set the global session variable to NULL */
2585+ session = NULL ;
2586+
2587+ if (was_rawmode ) {
2588+ linenoiseEnableRawMode (lss .ifd );
2589+ linenoiseRefreshLine ();
2590+ }
2591+ }
2592+
2593+ static int
2594+ cmd_monitor (const char * arg , char * * UNUSED (tmp_config_file ))
2595+ {
2596+ char * args = strdupa (arg );
2597+ char * cmd = NULL ;
2598+
2599+ strtok (args , " " );
2600+ if ((cmd = strtok (NULL , " " )) == NULL ) {
2601+ fprintf (stdout , "Connection state will %sbe monitored.\n" , monitor ? "" : "not " );
2602+ } else {
2603+ if (!strcmp (cmd , "on" )) {
2604+ if (nc_client_monitoring_thread_start (monitoring_clb , NULL , NULL )) {
2605+ ERROR (__func__ , "Monitoring thread failed to start." );
2606+ return 1 ;
2607+ }
2608+ monitor = 1 ;
2609+ } else if (!strcmp (cmd , "off" )) {
2610+ monitor = 0 ;
2611+ nc_client_monitoring_thread_stop ();
2612+ } else {
2613+ ERROR (__func__ , "Unknown option %s." , cmd );
2614+ cmd_monitor_help ();
2615+ }
2616+ }
2617+
2618+ return 0 ;
2619+ }
2620+
25602621static int
25612622cmd_status (const char * UNUSED (arg ), char * * UNUSED (tmp_config_file ))
25622623{
@@ -6575,6 +6636,7 @@ COMMAND commands[] = {
65756636 "ietf-subscribed-notifications <modify-subscription> operation with ietf-yang-push augments"
65766637 },
65776638 {"modify-sub" , cmd_modifysub , cmd_modifysub_help , "ietf-subscribed-notifications <modify-subscription> operation" },
6639+ {"monitor" , cmd_monitor , cmd_monitor_help , "Monitor client connection status" },
65786640 {"outputformat" , cmd_outputformat , cmd_outputformat_help , "Set the output format of all the data" },
65796641 {"resync-sub" , cmd_resyncsub , cmd_resyncsub_help , "ietf-yang-push <resync-subscription> operation" },
65806642 {"searchpath" , cmd_searchpath , cmd_searchpath_help , "Set the search path for models" },
0 commit comments