chore: add example for testing blocking tasks
							parent
							
								
									f78738ca92
								
							
						
					
					
						commit
						854e8c3809
					
				| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
root = true
 | 
			
		||||
 | 
			
		||||
[*.{c,cpp,h}]
 | 
			
		||||
indent_style = space
 | 
			
		||||
indent_size = 2
 | 
			
		||||
| 
						 | 
				
			
			@ -1,2 +1,5 @@
 | 
			
		|||
build/
 | 
			
		||||
.cache/
 | 
			
		||||
compile_commands.json
 | 
			
		||||
.cache/
 | 
			
		||||
vgcore.*
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										6
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										6
									
								
								Makefile
								
								
								
								
							| 
						 | 
				
			
			@ -9,14 +9,20 @@ SRCS != find '$(SRC_DIR)' -iname '*.c'
 | 
			
		|||
SRCS_H != find include -iname '*.h'
 | 
			
		||||
SRCS_H_INTERNAL != find $(SRC_DIR) -iname '*.h'
 | 
			
		||||
SRCS_TEST != find '$(TEST_DIR)' -iname '*.c'
 | 
			
		||||
SRCS_EXAMPLE != find '$(EXAMPLE_DIR)' -iname '*.c'
 | 
			
		||||
 | 
			
		||||
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
 | 
			
		||||
OBJS_TEST := $(SRCS_TEST:%=$(BUILD_DIR)/%.o)
 | 
			
		||||
OBJS_EXAMPLE := $(SRCS_EXAMPLE:%=$(BUILD_DIR)/%.o)
 | 
			
		||||
 | 
			
		||||
DEPS := $(SRCS:%=$(BUILD_DIR)/%.d) $(SRCS_TEST:%=$(BUILD_DIR)/%.d)
 | 
			
		||||
 | 
			
		||||
BINS_TEST := $(OBJS_TEST:%.c.o=%)
 | 
			
		||||
BINS_EXAMPLE := $(OBJS_EXAMPLE:%.c.o=%)
 | 
			
		||||
 | 
			
		||||
TARGETS_TEST := $(BINS_TEST:%=test-%)
 | 
			
		||||
TARGETS_MEM_TEST := $(BINS_TEST:%=test-mem-%)
 | 
			
		||||
TARGETS_EXAMPLE := $(BINS_EXAMPLE:%=example-%)
 | 
			
		||||
 | 
			
		||||
_CFLAGS := $(addprefix -I,$(INC_DIRS)) $(CFLAGS) -Wall -Wextra
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,6 +3,7 @@ LIB_FILENAME = liblnm.a
 | 
			
		|||
BUILD_DIR = build
 | 
			
		||||
SRC_DIR = src
 | 
			
		||||
TEST_DIR = test
 | 
			
		||||
EXAMPLE_DIR = example
 | 
			
		||||
THIRDPARTY = src/picohttpparser.c include/picohttpparser.h
 | 
			
		||||
 | 
			
		||||
PUB_INC_DIR = include
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,38 @@
 | 
			
		|||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
#include "lnm/log.h"
 | 
			
		||||
#include "lnm/http/loop.h"
 | 
			
		||||
 | 
			
		||||
lnm_err ctx_init(void **c_ctx, void *gctx) {
 | 
			
		||||
  *c_ctx = NULL;
 | 
			
		||||
 | 
			
		||||
  return lnm_err_ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ctx_reset(void *c_ctx) {}
 | 
			
		||||
void ctx_free(void *c_ctx) {}
 | 
			
		||||
 | 
			
		||||
lnm_http_step_err slow_step(lnm_http_conn *conn) {
 | 
			
		||||
  sleep(1);
 | 
			
		||||
 | 
			
		||||
  return lnm_http_step_err_done;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
  lnm_http_loop *hl;
 | 
			
		||||
  lnm_http_step *step = NULL;
 | 
			
		||||
  lnm_http_route *route;
 | 
			
		||||
 | 
			
		||||
  lnm_http_loop_init(&hl, NULL, ctx_init,
 | 
			
		||||
                     ctx_reset,
 | 
			
		||||
                     ctx_free);
 | 
			
		||||
 | 
			
		||||
  lnm_http_step_init(&step, slow_step);
 | 
			
		||||
  lnm_http_route_init_literal(&route, lnm_http_method_get, "/", step);
 | 
			
		||||
  lnm_http_loop_route_add(hl, route);
 | 
			
		||||
 | 
			
		||||
  lnm_log_init_global();
 | 
			
		||||
  lnm_log_register_stdout(lnm_log_level_debug);
 | 
			
		||||
 | 
			
		||||
  lnm_http_loop_run(hl, 8080, 1);
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue