@@ -405,6 +405,7 @@ static bool do_web(int argc, char *argv[])
405405 web_fd = web_open (port );
406406 if (web_fd > 0 ) {
407407 printf ("listen on port %d, fd is %d\n" , port , web_fd );
408+ line_set_eventmux_callback (web_eventmux );
408409 use_linenoise = false;
409410 } else {
410411 perror ("ERROR" );
@@ -560,13 +561,13 @@ static int cmd_select(int nfds,
560561 fd_set * exceptfds ,
561562 struct timeval * timeout )
562563{
563- int infd ;
564564 fd_set local_readset ;
565565
566566 if (cmd_done ())
567567 return 0 ;
568568
569569 if (!block_flag ) {
570+ int infd ;
570571 /* Process any commands in input buffer */
571572 if (!readfds )
572573 readfds = & local_readset ;
@@ -581,51 +582,18 @@ static int cmd_select(int nfds,
581582 FD_SET (web_fd , readfds );
582583
583584 if (infd == STDIN_FILENO && prompt_flag ) {
584- printf ("%s" , prompt );
585+ char * cmdline = linenoise (prompt );
586+ if (cmdline )
587+ interpret_cmd (cmdline );
585588 fflush (stdout );
586589 prompt_flag = true;
590+ } else if (infd != STDIN_FILENO ) {
591+ char * cmdline = readline ();
592+ if (cmdline )
593+ interpret_cmd (cmdline );
587594 }
588-
589- if (infd >= nfds )
590- nfds = infd + 1 ;
591- if (web_fd >= nfds )
592- nfds = web_fd + 1 ;
593595 }
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 ;
629597}
630598
631599bool finish_cmd ()
@@ -706,4 +674,4 @@ bool run_console(char *infile_name)
706674 }
707675
708676 return err_cnt == 0 ;
709- }
677+ }
0 commit comments