| | |
| | | DIRS = src test demo |
| | | DIRS = src test_socket demo |
| | | |
| | | all: |
| | | for i in $(DIRS); do \ |
New file |
| | |
| | | #include "shm_queue_wrapper.h" |
| | | #include "mm.h" |
| | | |
| | | // typedef struct message_t |
| | | // { |
| | | // char method[20]; |
| | | // int code; |
| | | |
| | | // } message_t; |
| | | |
| | | void test1() { |
| | | unsigned int i = 0; |
| | | int key = 1; |
| | | |
| | | size_t qsize = 16; |
| | | void * queue = shmqueue_create( &key, qsize); |
| | | //message_t item; |
| | | char msg[100]; |
| | | void *rtmsg; |
| | | int size; |
| | | |
| | | for(i = 0; i < qsize; i++) { |
| | | sprintf(msg, "%d hello", i); |
| | | //入队 |
| | | if(shmqueue_push(queue, (void *)msg, sizeof(msg))) { |
| | | printf("push: %s\n", msg ); |
| | | } |
| | | } |
| | | printf("key == %d\n", key); |
| | | // struct timespec timeout = {1, 0}; |
| | | // int keys[] = {1,2}; |
| | | // shm_remove_queues_exclue((void *)keys, 1); |
| | | i = 0; |
| | | // 出队 |
| | | while((shmqueue_pop_timeout(queue, &rtmsg, &size, 1, 0)) ) { |
| | | printf("pop: %s\n", (char *)rtmsg ); |
| | | free(rtmsg); |
| | | // cout << item.pic << endl; |
| | | i++; |
| | | } |
| | | |
| | | //销毁队列 |
| | | shmqueue_drop(queue); |
| | | } |
| | | |
| | | |
| | | int main () { |
| | | shm_init(512); |
| | | test1(); |
| | | |
| | | //整个进程退出时需要执行这个方法,该方法首先会检查是否还有其他进程在使用该共享内存,如果还有其他进程在使用就只是detach,如果没有其他进程在使用则销毁整块内存。 |
| | | shm_destroy(); |
| | | return 0; |
| | | } |
| | |
| | | # Makefile for common library. |
| | | # |
| | | ROOT=.. |
| | | LDLIBS+=-Wl,-rpath=$(ROOT)/queue:$(ROOT)/lib |
| | | LDLIBS+=-Wl,-rpath=$(ROOT)/lib:$(ROOT)/build/lib |
| | | # 开源工具包路径 |
| | | LDDIR += -L$(ROOT)/queue |
| | | LDDIR += -L$(ROOT)/build/lib |
| | | # 开源工具包 |
| | | LDLIBS += -lshm_queue -lusgcommon -lpthread |
| | | |
| | | INCLUDE += -I$(ROOT)/queue/ -I$(ROOT)/queue/include |
| | | INCLUDE += -I$(ROOT)/build/include |
| | | |
| | | PLATFORM=$(shell $(ROOT)/systype.sh) |
| | | include $(ROOT)/Make.defines.$(PLATFORM) |
| | | |
| | | |
| | | PROGS = req_rep pub_sub |
| | | PROGS = dgram_socket_test |
| | | |
| | | |
| | | build: $(PROGS) |
| | |
| | | clean: |
| | | rm -f $(TEMPFILES) $(PROGS) |
| | | |
| | | |
| | | |
| | | $(LIBQUEUE): |
| | | (cd $(ROOT)/queue && $(MAKE)) |