@@ -405,6 +405,7 @@ static bool do_web(int argc, char *argv[])
405
405
web_fd = web_open (port );
406
406
if (web_fd > 0 ) {
407
407
printf ("listen on port %d, fd is %d\n" , port , web_fd );
408
+ line_set_eventmux_callback (web_eventmux );
408
409
use_linenoise = false;
409
410
} else {
410
411
perror ("ERROR" );
@@ -560,13 +561,13 @@ static int cmd_select(int nfds,
560
561
fd_set * exceptfds ,
561
562
struct timeval * timeout )
562
563
{
563
- int infd ;
564
564
fd_set local_readset ;
565
565
566
566
if (cmd_done ())
567
567
return 0 ;
568
568
569
569
if (!block_flag ) {
570
+ int infd ;
570
571
/* Process any commands in input buffer */
571
572
if (!readfds )
572
573
readfds = & local_readset ;
@@ -581,51 +582,18 @@ static int cmd_select(int nfds,
581
582
FD_SET (web_fd , readfds );
582
583
583
584
if (infd == STDIN_FILENO && prompt_flag ) {
584
- printf ("%s" , prompt );
585
+ char * cmdline = linenoise (prompt );
586
+ if (cmdline )
587
+ interpret_cmd (cmdline );
585
588
fflush (stdout );
586
589
prompt_flag = true;
590
+ } else if (infd != STDIN_FILENO ) {
591
+ char * cmdline = readline ();
592
+ if (cmdline )
593
+ interpret_cmd (cmdline );
587
594
}
588
-
589
- if (infd >= nfds )
590
- nfds = infd + 1 ;
591
- if (web_fd >= nfds )
592
- nfds = web_fd + 1 ;
593
595
}
594
- if (nfds == 0 )
595
- return 0 ;
596
-
597
- int result = select (nfds , readfds , writefds , exceptfds , timeout );
598
- if (result <= 0 )
599
- return result ;
600
-
601
- infd = buf_stack -> fd ;
602
- if (readfds && FD_ISSET (infd , readfds )) {
603
- /* Commandline input available */
604
- FD_CLR (infd , readfds );
605
- result -- ;
606
-
607
- set_echo (0 );
608
- char * cmdline = readline ();
609
- if (cmdline )
610
- interpret_cmd (cmdline );
611
- } else if (readfds && FD_ISSET (web_fd , readfds )) {
612
- FD_CLR (web_fd , readfds );
613
- result -- ;
614
- struct sockaddr_in clientaddr ;
615
- socklen_t clientlen = sizeof (clientaddr );
616
- web_connfd =
617
- accept (web_fd , (struct sockaddr * ) & clientaddr , & clientlen );
618
-
619
- char * p = web_recv (web_connfd , & clientaddr );
620
- char * buffer = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n" ;
621
- web_send (web_connfd , buffer );
622
-
623
- if (p )
624
- interpret_cmd (p );
625
- free (p );
626
- close (web_connfd );
627
- }
628
- return result ;
596
+ return 0 ;
629
597
}
630
598
631
599
bool finish_cmd ()
@@ -706,4 +674,4 @@ bool run_console(char *infile_name)
706
674
}
707
675
708
676
return err_cnt == 0 ;
709
- }
677
+ }
0 commit comments