void uart_thread(struct SerialPort *ser,int pipe_r, int pipe_w){ //int n; //int i = 0; //int flags; //flags = fcntl(pipe_r, F_GETFL, 0); //获取文件的flags值。 //fcntl(pipe_r, F_SETFL, flags | O_NONBLOCK); //设置成非阻塞模式; pipe_to_gui = pipe_w; send_t(ser,pipe_r,pipe_w); }
int main(int argc, char** argv) { /* Check the command line arguments */ if (argc < 2) { fprintf(stderr, "USAGE: %s <FILE NAME>\n", argv[0]); exit(-1); } /* Connect to shared memory and the message queue */ init(&shmid, &msqid, sharedMemPtr); /* Send the file */ send_t(argv[1]); /* Cleanup */ cleanUp(sharedMemPtr); return 0; }
void cli_data(int fd,char buf[MAXNITEMS]) { memset(buf,'\0',MAXNITEMS); char *p = NULL; int flags=0; p = fgets(buf,MAXNITEMS,stdin); if (p ==NULL) perror("fgets"); /* code */ int len = strlen(buf); printf("输入消息长度,包含'\\n':%d 字节\n",len ); // /delete the \n if (p[--len] == '\n') { p[len] = '\0'; /* code */ } printf("输入有效消息长度:%d 字节\n",len ); send_t(fd,buf,len,flags); recv_t(fd,buf,MAXNITEMS,flags); }