Use Select signal handling in examples
This commit is contained in:
committed by
Keith Winstein
parent
4f23326a92
commit
f7be5c8cec
@@ -37,7 +37,6 @@
|
|||||||
#include <util.h>
|
#include <util.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "sigfd.h"
|
|
||||||
#include "swrite.h"
|
#include "swrite.h"
|
||||||
#include "completeterminal.h"
|
#include "completeterminal.h"
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
|
|||||||
+3
-18
@@ -49,7 +49,6 @@
|
|||||||
#include "swrite.h"
|
#include "swrite.h"
|
||||||
#include "fatal_assert.h"
|
#include "fatal_assert.h"
|
||||||
#include "locale_utils.h"
|
#include "locale_utils.h"
|
||||||
#include "sigfd.h"
|
|
||||||
#include "select.h"
|
#include "select.h"
|
||||||
|
|
||||||
/* For newer skalibs */
|
/* For newer skalibs */
|
||||||
@@ -198,15 +197,6 @@ bool tick( Terminal::Framebuffer &state, Terminal::Framebuffer &new_frame,
|
|||||||
|
|
||||||
void emulate_terminal( int fd )
|
void emulate_terminal( int fd )
|
||||||
{
|
{
|
||||||
/* establish WINCH fd and start listening for signal */
|
|
||||||
int signal_fd = sigfd_init();
|
|
||||||
if ( signal_fd < 0 ) {
|
|
||||||
perror( "sigfd_init" );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fatal_assert( sigfd_trap(SIGWINCH) == 0 );
|
|
||||||
|
|
||||||
/* get current window size */
|
/* get current window size */
|
||||||
struct winsize window_size;
|
struct winsize window_size;
|
||||||
if ( ioctl( STDIN_FILENO, TIOCGWINSZ, &window_size ) < 0 ) {
|
if ( ioctl( STDIN_FILENO, TIOCGWINSZ, &window_size ) < 0 ) {
|
||||||
@@ -230,7 +220,7 @@ void emulate_terminal( int fd )
|
|||||||
Select &sel = Select::get_instance();
|
Select &sel = Select::get_instance();
|
||||||
sel.add_fd( STDIN_FILENO );
|
sel.add_fd( STDIN_FILENO );
|
||||||
sel.add_fd( fd );
|
sel.add_fd( fd );
|
||||||
sel.add_fd( signal_fd );
|
sel.add_signal( SIGWINCH );
|
||||||
|
|
||||||
swrite( STDOUT_FILENO, Terminal::Emulator::open().c_str() );
|
swrite( STDOUT_FILENO, Terminal::Emulator::open().c_str() );
|
||||||
|
|
||||||
@@ -238,9 +228,7 @@ void emulate_terminal( int fd )
|
|||||||
|
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
int active_fds = sel.select( timeout );
|
int active_fds = sel.select( timeout );
|
||||||
if ( active_fds < 0 && errno == EINTR ) {
|
if ( active_fds < 0 ) {
|
||||||
continue;
|
|
||||||
} else if ( active_fds < 0 ) {
|
|
||||||
perror( "select" );
|
perror( "select" );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -285,10 +273,7 @@ void emulate_terminal( int fd )
|
|||||||
if ( swrite( fd, terminal_to_host.c_str(), terminal_to_host.length() ) < 0 ) {
|
if ( swrite( fd, terminal_to_host.c_str(), terminal_to_host.length() ) < 0 ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if ( sel.read( signal_fd ) ) {
|
} else if ( sel.signal( SIGWINCH ) ) {
|
||||||
/* resize */
|
|
||||||
fatal_assert( sigfd_read() == SIGWINCH );
|
|
||||||
|
|
||||||
/* get new size */
|
/* get new size */
|
||||||
if ( ioctl( STDIN_FILENO, TIOCGWINSZ, &window_size ) < 0 ) {
|
if ( ioctl( STDIN_FILENO, TIOCGWINSZ, &window_size ) < 0 ) {
|
||||||
perror( "ioctl TIOCGWINSZ" );
|
perror( "ioctl TIOCGWINSZ" );
|
||||||
|
|||||||
Reference in New Issue
Block a user