pipeserver.c
来自「vxwork操作系统的相关内容」· C语言 代码 · 共 99 行
C
99 行
/* pipeServer.c - reads requests over pipe */#include "vxWorks.h"#include "pipeDrv.h"#include "taskLib.h"#include "ioLib.h"#include "signal.h"#include "logLib.h"void myHandler(int sig);typedef struct{ VOIDFUNCPTR pRoutine; int arg; } MSG_REQUEST;#define TASK_PRI 254 /* server priority */#define TASK_STACK 20000 /* server stack space */#define PIPE_NAME "/pipe/server"#define NUM_MSGS 10int pipeFd;LOCAL void pipeServer(void);/*************************************************** serverStart -- Initializes a server task to* execute functons at a low priority. Uses pipes as* the communication mechanism.** RETURNS: OK or ERROR on failure.*/STATUS serverStart (void){ /* Create the pipe device */ if (pipeDevCreate(PIPE_NAME,NUM_MSGS,sizeof(MSG_REQUEST))==ERROR) return (ERROR); /* Open the pipe */ if ((pipeFd=open(PIPE_NAME,UPDATE,0))==ERROR) return (ERROR); /* Spawn the server task */ if (taskSpawn("tServer",TASK_PRI,0,TASK_STACK,(FUNCPTR)pipeServer,0,0,0,0,0,0,0,0,0,0)==ERROR) { close(pipeFd); return (ERROR); } return (OK);}/*************************************************** serverSend -- Sends a request to the server to* execute a function at the server's priority.** RETURNS: OK or ERROR on failure.*/STATUS serverSend(VOIDFUNCPTR pRoutine,int arg){ MSG_REQUEST msgRequest; int status; /* Initialize the message structure */ msgRequest.pRoutine=pRoutine; msgRequest.arg=arg; /* Send the message and return the results */ status=write(pipeFd,(char *)&msgRequest,sizeof(MSG_REQUEST)); return ((status==sizeof(MSG_REQUEST))?(OK):(ERROR));}/*************************************************** pipeServer -- Server task which reads from a pipe* and executes the function passed in the* MSG_REQUEST data structure.**/LOCAL void pipeServer(void){ MSG_REQUEST msgRequest; signal(SIGBUS,myHandler); signal(SIGILL,myHandler); signal(SIGSEGV,myHandler); while (read(pipeFd,(char *)&msgRequest,sizeof(MSG_REQUEST))>0) (*msgRequest.pRoutine)(msgRequest.arg);}void myHandler(int sig){ logMsg("Signal %d received.Restarting Server.\n",sig,0,0,0,0,0); taskRestart (0);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?