The last source code I sent is outdated. The newest version with a sighandler for SIGINT is attached here.
Sorry for that, Andreas
#include <rtdk.h> #include <native/pipe.h> #include <native/task.h> #include <errno.h> #include <string.h> #include <sys/mman.h> #include <unistd.h> #include <stdlib.h> #include <signal.h> static RT_TASK m_task; static RT_PIPE m_pipe; static volatile int cont = 1; void sig_hdl(int sig) { cont = 0; } #define rc_error(fn, ret) rt_printf("Error: " fn ":%s (%d) %s\n", strerror(-ret), -ret) int main(void) { int err; const char* out_str = "d"; int out_str_len = 1; int in_str_len = 32; char in_str[in_str_len]; // Lock pages in memory mlockall(MCL_CURRENT|MCL_FUTURE); // Init rtdk framework for rt_printf rt_print_auto_init(1); // Catch SIG_INT signal(SIGINT, sig_hdl); // Add rt shadow err = rt_task_shadow(&m_task, "main", 22, 0); if(err) { rc_error("rt_task_shadow", err); return err; } // Create pipe err = rt_pipe_create(&m_pipe, "rtp0", 0, 2048); if(err) { rc_error("rt_pipe_create", err); goto cleanup; } // Deliberately fill pipe without a reader on // the other side... while(1) { err = rt_pipe_stream(&m_pipe, out_str, out_str_len); // Check if there was an error if(err < 0) { rc_error("rt_pipe_stream", err); goto cleanup; } // Check if all bytes where written to the pipe if(err != out_str_len) { rt_printf("Info: rt_pipe_stream is full (ret=%d)\n", err); break; } } // Wait for the user to connect to the pipe and // loop until we are able to read a byte while(cont) { err = rt_pipe_read(&m_pipe, in_str, in_str_len, TM_NONBLOCK); if(err < 0 && err != -EAGAIN) { rc_error("rt_pipe_read", err); goto cleanup; } // Check if we received something if(err >= 0) { rt_printf("Received: %d bytes\n", err); break; } // Wait 1ms rt_task_sleep(1000000); } err = 0; cleanup: rt_pipe_delete(&m_pipe); rt_task_delete(&m_task); return err; }
_______________________________________________ Xenomai-core mailing list Xenomai-core@gna.org https://mail.gna.org/listinfo/xenomai-core