@@ -54,6 +54,7 @@ extern void debug3(const char *fmt,...);
54
54
extern void error (const char * fmt ,...);
55
55
extern void fatal (const char * fmt ,...);
56
56
57
+ int glob_itissshclient = 0 ; // ssh client turns it to 1
57
58
static int winsock_initialized = 0 ;
58
59
59
60
extern int logfd ;
@@ -1545,7 +1546,26 @@ int socketpair(int socks[2])
1545
1546
return SOCKET_ERROR ;
1546
1547
}
1547
1548
1549
+ int DataAvailable ( HANDLE h )
1550
+ {
1551
+ INPUT_RECORD irec = {0 };
1552
+
1553
+ DWORD events_read = 0 ;
1554
+
1555
+ int ret = PeekConsoleInput (h , & irec , 1 , & events_read );
1556
+
1557
+ if (!ret )
1558
+ {
1559
+ return 0 ;
1560
+ }
1561
+
1562
+ if (events_read ) // && irec.EventType == KEY_EVENT)
1563
+ {
1564
+ return events_read ;
1565
+ }
1548
1566
1567
+ return 0 ;
1568
+ }
1549
1569
int peekConsoleRead (int sfd )
1550
1570
{
1551
1571
DWORD sleep_time = 0 ;
@@ -2391,8 +2411,9 @@ int WSHELPread(int sfd, char *dst, unsigned int max)
2391
2411
SOCKET sock ;
2392
2412
2393
2413
int ret = -1 ;
2414
+ int sfd_type = get_sfd_type (sfd );
2394
2415
2395
- switch ( get_sfd_type ( sfd ) )
2416
+ switch ( sfd_type )
2396
2417
{
2397
2418
case SFD_TYPE_SOCKET :
2398
2419
{
@@ -2450,8 +2471,9 @@ int WSHELPread(int sfd, char *dst, unsigned int max)
2450
2471
2451
2472
case SFD_TYPE_FD :
2452
2473
case SFD_TYPE_PIPE :
2453
- case SFD_TYPE_CONSOLE :
2474
+ // case SFD_TYPE_CONSOLE:
2454
2475
{
2476
+
2455
2477
ret = _read (sfd_to_fd (sfd ), dst , max );
2456
2478
2457
2479
if (FD_ISSET (sfd_to_fd (sfd ), & debug_sfds ))
@@ -2470,6 +2492,25 @@ int WSHELPread(int sfd, char *dst, unsigned int max)
2470
2492
sfd , GetLastError ());
2471
2493
}
2472
2494
2495
+ break ;
2496
+ }
2497
+ case SFD_TYPE_CONSOLE :
2498
+ {
2499
+ //if (sfd_type == SFD_TYPE_CONSOLE) {
2500
+ // we could be send here due to ctrl-c input, so no data to read
2501
+ //if ( DataAvailable (sfd_to_handle(sfd)) <=0 )
2502
+ //return 1; // no data to read
2503
+ //}
2504
+ ret = ReadConsoleForTermEmul ( sfd_to_handle (sfd ), dst , max );
2505
+
2506
+ if (ret < 0 )
2507
+ {
2508
+ error ("read from pipe/console sfd [%d] failed with error code [%d]" ,
2509
+ sfd , GetLastError ());
2510
+ }
2511
+ if (ret == 0 )
2512
+ return 0 ; //1;
2513
+
2473
2514
break ;
2474
2515
}
2475
2516
case 99 :
@@ -2519,7 +2560,11 @@ int WSHELPwrite(int sfd, const char *buf, unsigned int max)
2519
2560
2520
2561
int ret = -1 ;
2521
2562
2522
- switch (get_sfd_type (sfd ))
2563
+ int sfd_type = get_sfd_type (sfd );
2564
+ if ( (glob_itissshclient ) && ( sfd_type == SFD_TYPE_CONSOLE ) )
2565
+ sfd_type = SFD_TYPE_PIPE ; // client write type uses _write() in place ofn console insertion
2566
+
2567
+ switch (sfd_type )
2523
2568
{
2524
2569
case SFD_TYPE_SOCKET :
2525
2570
{
0 commit comments