Сигналы. Сетевая доставка сигналов. Системный вызов. Отправка сигнала процессу на удаленном узле. Программа приема сигнала, страница 8

printf( "Client: cmd args error!\n" );

exit(1);

}

if( strcmp(argv[1],"-l" ) == 0 )       flag = 0;

else if( strcmp(argv[1],"-g" ) == 0 )  flag = NAME_FLAG_ATTACH_GLOBAL;

else {

printf( "Client: cmd args error!\n" );

exit(1);

}

// Отключаем буферизацию вывода //

setbuf( stdout, NULL );

connect_id = name_open( ATTACH_POINT, flag );

if( connect_id == -1 ) {

printf( "Client: Name Open error!\n" );

exit(2);

}

channel_id = ChannelCreate( 0 );

if( channel_id == -1 ) {

printf( "Client: Channel Create error!\n" );

exit(3);

}

sconnect_id = ConnectAttach( 0, 0, channel_id, 0, 0 );

if( sconnect_id == -1 ) {

printf( "Client: Connect Attach error!\n" );

exit(4);

}

printf( "Client: started.\n" );

ThreadCtl( _NTO_TCTL_IO, 0 );

SIGEV_PULSE_INIT( &kbdEvent, sconnect_id, SIGEV_PULSE_PRIO_INHERIT, CODE_KBD_ISR, 0 );      

kbdIsr_id = InterruptAttach( IRQ1_KBD, kbdIsr, NULL, 0, 0 );

for( ; ; )

{     

rcv_id = MsgReceivePulse( channel_id, &pulse_msg, sizeof(pulse_msg), NULL );

if( rcv_id == -1 ) {

printf( "Client: Receive Pulse error!\n" );

break;

}                        

if( pulse_msg.code != CODE_KBD_ISR ) {

continue;

}

if( keyNum == 0x01 ) {

printf( "ESC pressed. Exit programm.\n" );

break;

}                        

printf( "KeyNum = %d\n", keyNum );                                            

snd_id = MsgSendPulse( connect_id, 25, CODE_KBD_ISR, (int)keyNum );

if( snd_id == -1 ) {

printf( "Client: Send Pulse error!\n" );

break;

}

}

name_close( connect_id );

ConnectDetach( sconnect_id );

InterruptDetach( kbdIsr_id );

return 0;

}

const struct sigevent *kbdIsr( void *area, int id )

{     

keyNum = in8( 0x60 );

if( keyNum >= 128 ) {

return( NULL );

}

return( &kbdEvent );

}

Результаты работы программы. Программы тестировались в лаборатории на одном (локальная передача) и нескольких (сетевая передача) компьютерах.

Локальный вариант:

Сервер

Клиент

$ ./server -l Server: started. Recieved pulse from Kbd_Isr. KeyNum=31. Recieved pulse from Kbd_Isr. KeyNum=32. Recieved pulse from Kbd_Isr. KeyNum=30. Recieved pulse from Kbd_Isr. KeyNum=33. Recieved pulse from Kbd_Isr. KeyNum=32. Recieved pulse from Kbd_Isr. KeyNum=31. Recieved pulse from Kbd_Isr. KeyNum=34. Recieved pulse from Kbd_Isr. KeyNum=33. Recieved pulse from Kbd_Isr. KeyNum=31. Recieved pulse from Kbd_Isr. KeyNum=32. Recieved pulse from Kbd_Isr. KeyNum=33.

# ./cliet_isr -l Client: started. KeyNum = 31 KeyNum = 32 KeyNum = 30 KeyNum = 33 KeyNum = 32 KeyNum = 31 KeyNum = 34 KeyNum = 33 KeyNum = 31 KeyNum = 32 KeyNum = 33 ESC pressed. Exit programm. #

Программа так же работает в сетевом варианте, для этого при запуске программы необходимо указать опцию -g.

Сервер

Клиент

# /home/gr40812/dorogoff/msg/server -g Server: started. Recieved pulse from Kbd_Isr. KeyNum=16. Recieved pulse from Kbd_Isr. KeyNum=17. Recieved pulse from Kbd_Isr. KeyNum=18. Recieved pulse from Kbd_Isr. KeyNum=30. Recieved pulse from Kbd_Isr. KeyNum=31. Recieved pulse from Kbd_Isr. KeyNum=32. Recieved pulse from Kbd_Isr. KeyNum=33. Recieved pulse from Kbd_Isr. KeyNum=31. Recieved pulse from Kbd_Isr. KeyNum=32. Recieved pulse from Kbd_Isr. KeyNum=30. Recieved pulse from Kbd_Isr. KeyNum=31. Recieved pulse from Kbd_Isr. KeyNum=32. Recieved pulse from Kbd_Isr. KeyNum=30. Recieved pulse from Kbd_Isr. KeyNum=31. Recieved pulse from Kbd_Isr. KeyNum=32.

# ./cliet_isr -g Client: started. KeyNum = 16 KeyNum = 17 KeyNum = 18 KeyNum = 30 KeyNum = 31 KeyNum = 32 KeyNum = 33 KeyNum = 31 KeyNum = 32 KeyNum = 30 KeyNum = 31 KeyNum = 32 KeyNum = 30 KeyNum = 31 KeyNum = 32 ESC pressed. Exit programm.