@@ -70,7 +70,7 @@ COMMAND commands[];
70
70
extern int done ;
71
71
struct nc_session * session ;
72
72
volatile int interleave ;
73
- int timed ;
73
+ int timed , monitor ;
74
74
75
75
static int cmd_disconnect (const char * arg , char * * tmp_config_file );
76
76
@@ -1264,6 +1264,12 @@ cmd_timed_help(void)
1264
1264
printf ("timed [--help] [on | off]\n" );
1265
1265
}
1266
1266
1267
+ static void
1268
+ cmd_monitor_help (void )
1269
+ {
1270
+ printf ("monitor [--help] [on | off]\n" );
1271
+ }
1272
+
1267
1273
#ifdef NC_ENABLED_SSH_TLS
1268
1274
1269
1275
static void
@@ -2557,6 +2563,61 @@ cmd_disconnect(const char *UNUSED(arg), char **UNUSED(tmp_config_file))
2557
2563
return EXIT_SUCCESS ;
2558
2564
}
2559
2565
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
+
2560
2621
static int
2561
2622
cmd_status (const char * UNUSED (arg ), char * * UNUSED (tmp_config_file ))
2562
2623
{
@@ -6575,6 +6636,7 @@ COMMAND commands[] = {
6575
6636
"ietf-subscribed-notifications <modify-subscription> operation with ietf-yang-push augments"
6576
6637
},
6577
6638
{"modify-sub" , cmd_modifysub , cmd_modifysub_help , "ietf-subscribed-notifications <modify-subscription> operation" },
6639
+ {"monitor" , cmd_monitor , cmd_monitor_help , "Monitor client connection status" },
6578
6640
{"outputformat" , cmd_outputformat , cmd_outputformat_help , "Set the output format of all the data" },
6579
6641
{"resync-sub" , cmd_resyncsub , cmd_resyncsub_help , "ietf-yang-push <resync-subscription> operation" },
6580
6642
{"searchpath" , cmd_searchpath , cmd_searchpath_help , "Set the search path for models" },
0 commit comments