?? test.c
字號:
#include <stdio.h>#include <stdlib.h>#include "fifo.h"#define TOTAL_COUNT 100void proc_put(HFIFO handle){ int cnt, remain; char buf[2048]; remain = 8; for(cnt = 0; cnt < TOTAL_COUNT; cnt++) { sprintf(buf, "Count: %d", cnt); fifo_put(handle, buf, strlen(buf), FIFO_FLG_BLOCK); printf("[FIFO] [SEND] %s\n", buf); remain--; if(remain == 0) { fifo_tag_trigger(handle, 0); remain = 8; } { struct timespec tm; tm.tv_sec = 0; tm.tv_nsec = 1000000; nanosleep(&tm, NULL); } } fifo_tag_trigger(handle, 0);}void proc_get(){ int cnt; HFIFO handle; size_t slotsz; int len; char buf[2048]; handle = fifo_find_handle("fifotest", &slotsz); printf("We get it! Address: %p\n", handle); for(cnt = 0; cnt < TOTAL_COUNT; ) { if(fifo_tag_check(handle, 0)) { while((len=fifo_get(handle, buf, 2048, FIFO_FLG_BLOCK)) >= 0) { buf[len] = 0; printf("[FIFO] [RECV] %s\n", buf); cnt++; } } else { struct timespec tm; tm.tv_sec = 0; tm.tv_nsec = 1000000; nanosleep(&tm, NULL); } }}main(){ HFIFO handle; /* Create FIFO */ handle = fifo_create("fifotest", 128, 1460); if(!fork()) { proc_get(); sleep(1); } else { proc_put(handle); sleep(10); fifo_destroy(handle); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -