From 055356263a9a9d9125dc377b88acb6ffbcc37ac2 Mon Sep 17 00:00:00 2001 From: partic Date: Tue, 22 Nov 2022 12:22:22 +0800 Subject: [PATCH] update c build script --- c/pxprpc/make-config.mk | 7 +++++-- c/pxprpc_libuv/make-config.mk | 34 ++++++++++++++++++---------------- c/pxprpc_tbox/make-config.mk | 34 ++++++++++++++++++---------------- c/readme.md | 23 ++++++++++++++++------- typescript/pxprpc/backend.ts | 12 ++++++++++-- 5 files changed, 67 insertions(+), 43 deletions(-) rewrite c/pxprpc_libuv/make-config.mk (74%) rewrite c/pxprpc_tbox/make-config.mk (69%) diff --git a/c/pxprpc/make-config.mk b/c/pxprpc/make-config.mk index ea88fb2..9dd2bc7 100644 --- a/c/pxprpc/make-config.mk +++ b/c/pxprpc/make-config.mk @@ -2,6 +2,9 @@ # PXPRPC_SOURCE_ROOT=path of this project. -C_SOURCE_FILES+= $(PXPRPC_SOURCE_ROOT)/c/pxprpc/server.c +PXPRPC_CFLAGS+= -I$(PXPRPC_SOURCE_ROOT)/c -CFLAGS+= -I$(PXPRPC_SOURCE_ROOT)/c +PXPRPC_LDFLAGS+= pxprpc_server.o + +build_pxprpc:$(PXPRPC_SOURCE_ROOT)/c/pxprpc/server.c + $(CC) -c -o pxprpc_server.o $(CFLAGS) $< $(LDFLAGS) diff --git a/c/pxprpc_libuv/make-config.mk b/c/pxprpc_libuv/make-config.mk dissimilarity index 74% index 3e4ade2..6ca4a0b 100644 --- a/c/pxprpc_libuv/make-config.mk +++ b/c/pxprpc_libuv/make-config.mk @@ -1,16 +1,18 @@ - - -# PXPRPC_SOURCE_ROOT=path of this project. - -C_SOURCE_FILES+= $(PXPRPC_SOURCE_ROOT)/c/pxprpc_libuv/server_libuv.c - -CFLAGS+= $(LIBUV_CFLAGS) - -LDFLAGS+= $(LIBUV_LDFLAGS) - -include $(PXPRPC_SOURCE_ROOT)/c/pxprpc/make-config.mk - - -pxprpc_libuv_test:$(C_SOURCE_FILES) $(PXPRPC_SOURCE_ROOT)/c/pxprpc_libuv/test.cpp - $(CC) -o __temp_test -g $(CFLAGS) test.cpp $(C_SOURCE_FILES) $(LDFLAGS) -lstdc++ - ./__temp_test \ No newline at end of file + + +# PXPRPC_SOURCE_ROOT=path of this project. + +include $(PXPRPC_SOURCE_ROOT)/c/pxprpc/make-config.mk + +PXPRPC_LIBUV_CFLAGS=$(PXPRPC_CFLAGS) $(LIBUV_CFLAGS) + +PXPRPC_LIBUV_LDFLAGS=pxprpc_server_libuv.o $(PXPRPC_LDFLAGS) $(LIBUV_LDFLAGS) + + + +pxprpc_libuv_test:build_pxprpc_libuv $(PXPRPC_SOURCE_ROOT)/c/pxprpc_libuv/test.cpp + $(CC) -o __temp_test -g $(CFLAGS) $(PXPRPC_LIBUV_CFLAGS) test.cpp $(LDFLAGS) $(PXPRPC_LIBUV_LDFLAGS) -lstdc++ + ./__temp_test + +build_pxprpc_libuv:$(PXPRPC_SOURCE_ROOT)/c/pxprpc_libuv/server_libuv.c build_pxprpc + $(CC) -o pxprpc_server_libuv.o -c $(CFLAGS) $(PXPRPC_CFLAGS) $< \ No newline at end of file diff --git a/c/pxprpc_tbox/make-config.mk b/c/pxprpc_tbox/make-config.mk dissimilarity index 69% index e0e53d7..ce3511f 100644 --- a/c/pxprpc_tbox/make-config.mk +++ b/c/pxprpc_tbox/make-config.mk @@ -1,16 +1,18 @@ - - -# PXPRPC_SOURCE_ROOT=path of this project. - -C_SOURCE_FILES+= $(PXPRPC_SOURCE_ROOT)/c/pxprpc_tbox/server_tbox.c - -CFLAGS+= $(TBOX_CFLAGS) - -LDFLAGS+= $(TBOX_LDFLAGS) - -include $(PXPRPC_SOURCE_ROOT)/c/pxprpc/make-config.mk - - -pxprpc_tbox_test:$(C_SOURCE_FILES) $(PXPRPC_SOURCE_ROOT)/c/pxprpc_tbox/test.cpp - $(CC) -o __temp_test -g $(CFLAGS) test.cpp $(C_SOURCE_FILES) $(LDFLAGS) -lstdc++ - ./__temp_test \ No newline at end of file + + +# PXPRPC_SOURCE_ROOT=path of this project. + +include $(PXPRPC_SOURCE_ROOT)/c/pxprpc/make-config.mk + +PXPRPC_TBOX_CFLAGS=$(PXPRPC_CFLAGS) $(TBOX_CFLAGS) + +PXPRPC_TBOX_LDFLAGS=pxprpc_server_tbox.o $(PXPRPC_LDFLAGS) $(TBOX_LDFLAGS) + + + +pxprpc_tbox_test:build_pxprpc_tbox $(PXPRPC_SOURCE_ROOT)/c/pxprpc_tbox/test.cpp + $(CC) -o __temp_test -g $(CFLAGS) $(PXPRPC_TBOX_CFLAGS) test.cpp $(LDFLAGS) $(PXPRPC_TBOX_LDFLAGS) -lstdc++ + ./__temp_test + +build_pxprpc_tbox:$(PXPRPC_SOURCE_ROOT)/c/pxprpc_tbox/server_tbox.c build_pxprpc + $(CC) -o pxprpc_server_tbox.o -c $(CFLAGS) $(PXPRPC_CFLAGS) $< \ No newline at end of file diff --git a/c/readme.md b/c/readme.md index 87c0ed8..c8e2d16 100644 --- a/c/readme.md +++ b/c/readme.md @@ -6,26 +6,35 @@ Set environment variable "PXPRPC_SOURCE_ROOT" to the path of this project. In makefile, add make config script by "include", like below -`include $(PXPRPC_SOURCE_ROOT)/c/pxprpc/make-config.mk` +`include $(PXPRPC_SOURCE_ROOT)/c/pxprpc_libuv/make-config.mk` -or +`include $(PXPRPC_SOURCE_ROOT)/c/pxprpc_tbox/make-config.mk` -`include $(PXPRPC_SOURCE_ROOT)/c/pxprpc_libuv/make-config.mk` +depend on which backend you choose. +or just +`include $(PXPRPC_SOURCE_ROOT)/c/pxprpc/make-config.mk` -These scripts will add the source files list into variable `$(C_SOURCE_FILES)`, and also other build flags into `$(CFLAGS)`, `$(LDFLAGS).` -then build like below +for custom backend. -`$(CC) -o myprog $(CFLAGS) myprog.cpp $(C_SOURCE_FILES) $(LDFLAGS)` +These scripts will add build flags into variable like `$(PXPRPC_LDFLAGS)`, `$(PXPRPC_LIBUV_CFLAGS)` ,etc. + +then build like below + +``` +your_target:build_pxprpc_libuv + $(CC) -o yoursource.cpp $(CFLAGS) $(PXPRPC_LIBUV_CFLAGS) test.cpp $(LDFLAGS) $(PXPRPC_LIBUV_LDFLAGS) -lstdc++ +``` + See also pxprpc_libuv/make-config.mk, which contains a build example. You may need set `$(LIBUV_CFLAGS)` and `$(LIBUV_LDFLAGS)` variable if use pxprpc_libuv backend. -Also `$(TBOX_CFLAGS)` and `$(TBOX_LDFLAGS)` variable if use pxprpc_tbox backend. +Similarly set `$(TBOX_CFLAGS)` and `$(TBOX_LDFLAGS)` variable if use pxprpc_tbox backend. diff --git a/typescript/pxprpc/backend.ts b/typescript/pxprpc/backend.ts index 84cbaa6..5e143d4 100644 --- a/typescript/pxprpc/backend.ts +++ b/typescript/pxprpc/backend.ts @@ -22,7 +22,15 @@ export class WebSocketIo implements Io{ } }); } - async read(size: number): Promise { + public availableBytes(){ + let sumBytes=0; + let len=this.queuedData.length + for(let i1=0;i1 { let remain=size; let datar=new Uint8Array(new ArrayBuffer(size)); while(remain>0){ @@ -46,7 +54,7 @@ export class WebSocketIo implements Io{ } return datar.buffer; } - async write(data: ArrayBufferLike): Promise { + public async write(data: ArrayBufferLike): Promise { this.ws.send(data); } -- 2.11.4.GIT