trigger a proxy when a given event occurs
#include <sys/dev.h> int dev_arm( int fd, pid_t proxy, unsigned events );
The dev_arm() function triggers the specified proxy whenever one of the indicated events occurs on the terminal device associated with fd.
The dev_arm() function always returns immediately. If any of the events is currently true, the proxy is triggered immediately. If not, the request is remembered, and the proxy is triggered when (and if) the indicated event occurs. The proxy is only triggered once.
If proxy is the bitwise complement of a signal number (that is, ~SIGXXX), that signal is generated on the calling process when the event occurs, instead of a proxy. See <signal.h> for the list of signals.
If proxy is _DEV_DISARM, the specified event is disarmed.
At least the following events are defined in <sys/dev.h>:
#include <sys/dev.h> #include <sys/proxy.h> #include <sys/kernel.h> #include <fcntl.h> #include <unistd.h> int main( void ) { unsigned state; pid_t kb_proxy, mdm_proxy, pid; int kb_fd, mdm_fd, n; char buf[80]; kb_fd = open( "/dev/con1", O_RDWR ); mdm_fd = open( "/dev/ser1", O_RDWR ); kb_proxy = qnx_proxy_attach( 0, 0, 0, -1 ); mdm_proxy = qnx_proxy_attach( 0, 0, 0, -1 ); dev_mode ( kb_fd, 0, _DEV_MODES ); dev_mode ( mdm_fd, 0, _DEV_MODES ); /* Clear, then arm the proxies for future events */ dev_state( kb_fd, 0, _DEV_EVENT_INPUT ); dev_state( mdm_fd, 0, _DEV_EVENT_INPUT ); dev_arm( kb_fd, kb_proxy, _DEV_EVENT_INPUT ); dev_arm( mdm_fd, mdm_proxy, _DEV_EVENT_INPUT ); for( ; ; ) { /* Wait for either keyboard or modem to have input */ pid = Receive( 0, 0, 0 ); if( pid == kb_proxy ) { state = dev_state( kb_fd, 0, _DEV_EVENT_INPUT ); if( state & _DEV_EVENT_INPUT ) { n = read( kb_fd, &buf, sizeof( buf ) ); write( mdm_fd, &buf, n ); dev_arm( kb_fd, kb_proxy, _DEV_EVENT_INPUT ); } } else if( pid == mdm_proxy ) { state = dev_state( mdm_fd, 0, _DEV_EVENT_INPUT ); if( state & _DEV_EVENT_INPUT ) { n = read( mdm_fd, &buf, sizeof( buf ) ); write( kb_fd, &buf, n ); dev_arm( mdm_fd, mdm_proxy, _DEV_EVENT_INPUT ); } } } return( EXIT_SUCCESS ); }
QNX
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes, but modifies errno |
Thread | Yes |
console_arm(), dev_info(), dev_osize(), dev_read(), dev_readex(), dev_state(), errno, select(), tcsetattr()