Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add luacjosn lib #441

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: C/C++ CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: make
run: make -j4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
obj/
wrk
*.sw[pon]
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ else ifeq ($(TARGET), freebsd)
endif

SRC := wrk.c net.c ssl.c aprintf.c stats.c script.c units.c \
ae.c zmalloc.c http_parser.c
ae.c zmalloc.c http_parser.c lua_cjson.c strbuf.c
BIN := wrk
VER ?= $(shell git describe --tags --always --dirty)

Expand All @@ -30,11 +30,13 @@ DEPS :=
CFLAGS += -I$(ODIR)/include
LDFLAGS += -L$(ODIR)/lib

LUAJIT_VER ?= luajit-2.1

ifneq ($(WITH_LUAJIT),)
CFLAGS += -I$(WITH_LUAJIT)/include
CFLAGS += -I$(WITH_LUAJIT)/include/$(LUAJIT_VER)
LDFLAGS += -L$(WITH_LUAJIT)/lib
else
CFLAGS += -I$(ODIR)/include/luajit-2.1
CFLAGS += -I$(ODIR)/include/$(LUAJIT_VER)
DEPS += $(ODIR)/lib/libluajit-5.1.a
endif

Expand Down Expand Up @@ -87,7 +89,7 @@ $(ODIR)/$(OPENSSL): deps/$(OPENSSL).tar.gz | $(ODIR)
$(ODIR)/lib/libluajit-5.1.a: $(ODIR)/$(LUAJIT)
@echo Building LuaJIT...
@$(MAKE) -C $< PREFIX=$(abspath $(ODIR)) BUILDMODE=static install
@cd $(ODIR)/bin && ln -s luajit-2.1.0-beta3 luajit
-@cd $(ODIR)/bin && ln -s luajit-2.1.0-beta3 luajit

$(ODIR)/lib/libssl.a: $(ODIR)/$(OPENSSL)
@echo Building OpenSSL...
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

--latency: print detailed latency statistics

-j --json-format: print output as JSON format

--timeout: record a timeout if a response is not received within
this amount of time.

Expand Down
9 changes: 9 additions & 0 deletions scripts/post_json.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- example HTTP POST script which demonstrates setting the
-- HTTP method, body, and adding a header

local cjson = require "cjson"
local json_encode = cjson.encode
local json_decode = cjson.decode
wrk.method = "POST"
wrk.body = json_encode({["key"] = "value"})
wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"
15 changes: 15 additions & 0 deletions src/ae.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ aeEventLoop *aeCreateEventLoop(int setsize) {
eventLoop->stop = 0;
eventLoop->maxfd = -1;
eventLoop->beforesleep = NULL;
eventLoop->checkThreadStop = NULL;
eventLoop->checkThreadStopData = NULL;
if (aeApiCreate(eventLoop) == -1) goto err;
/* Events with mask == AE_NONE are not set. So let's initialize the
* vector with it. */
Expand Down Expand Up @@ -416,6 +418,13 @@ int aeProcessEvents(aeEventLoop *eventLoop, int flags)
fe->wfileProc(eventLoop,fd,fe->clientData,mask);
}
processed++;

if (eventLoop->checkThreadStop != NULL) {
if (eventLoop->checkThreadStop(eventLoop) == 1) {
eventLoop->stop = 1;
break;
}
}
}
}
/* Check time events */
Expand Down Expand Up @@ -463,3 +472,9 @@ char *aeGetApiName(void) {
void aeSetBeforeSleepProc(aeEventLoop *eventLoop, aeBeforeSleepProc *beforesleep) {
eventLoop->beforesleep = beforesleep;
}

void aeSetCheckThreadStopProc(aeEventLoop *eventLoop,
aeCheckThreadStopProc *checkThreadStop, void *checkData) {
eventLoop->checkThreadStop = checkThreadStop;
eventLoop->checkThreadStopData = checkData;
}
77 changes: 40 additions & 37 deletions src/ae.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,40 +44,41 @@

#define AE_FILE_EVENTS 1
#define AE_TIME_EVENTS 2
#define AE_ALL_EVENTS (AE_FILE_EVENTS|AE_TIME_EVENTS)
#define AE_ALL_EVENTS (AE_FILE_EVENTS | AE_TIME_EVENTS)
#define AE_DONT_WAIT 4

#define AE_NOMORE -1
#define AE_DELETED_EVENT_ID -1

/* Macros */
#define AE_NOTUSED(V) ((void) V)
#define AE_NOTUSED(V) ((void)V)

struct aeEventLoop;

/* Types and data structures */
typedef void aeFileProc(struct aeEventLoop *eventLoop, int fd, void *clientData, int mask);
typedef int aeTimeProc(struct aeEventLoop *eventLoop, long long id, void *clientData);
typedef void aeEventFinalizerProc(struct aeEventLoop *eventLoop, void *clientData);
typedef void aeBeforeSleepProc(struct aeEventLoop *eventLoop);
typedef void aeFileProc(struct aeEventLoop* eventLoop, int fd, void* clientData, int mask);
typedef int aeTimeProc(struct aeEventLoop* eventLoop, long long id, void* clientData);
typedef void aeEventFinalizerProc(struct aeEventLoop* eventLoop, void* clientData);
typedef void aeBeforeSleepProc(struct aeEventLoop* eventLoop);
typedef int aeCheckThreadStopProc(struct aeEventLoop* eventLoop);

/* File event structure */
typedef struct aeFileEvent {
int mask; /* one of AE_(READABLE|WRITABLE) */
aeFileProc *rfileProc;
aeFileProc *wfileProc;
void *clientData;
aeFileProc* rfileProc;
aeFileProc* wfileProc;
void* clientData;
} aeFileEvent;

/* Time event structure */
typedef struct aeTimeEvent {
long long id; /* time event identifier. */
long when_sec; /* seconds */
long when_ms; /* milliseconds */
aeTimeProc *timeProc;
aeEventFinalizerProc *finalizerProc;
void *clientData;
struct aeTimeEvent *next;
aeTimeProc* timeProc;
aeEventFinalizerProc* finalizerProc;
void* clientData;
struct aeTimeEvent* next;
} aeTimeEvent;

/* A fired event */
Expand All @@ -88,36 +89,38 @@ typedef struct aeFiredEvent {

/* State of an event based program */
typedef struct aeEventLoop {
int maxfd; /* highest file descriptor currently registered */
int maxfd; /* highest file descriptor currently registered */
int setsize; /* max number of file descriptors tracked */
long long timeEventNextId;
time_t lastTime; /* Used to detect system clock skew */
aeFileEvent *events; /* Registered events */
aeFiredEvent *fired; /* Fired events */
aeTimeEvent *timeEventHead;
time_t lastTime; /* Used to detect system clock skew */
aeFileEvent* events; /* Registered events */
aeFiredEvent* fired; /* Fired events */
aeTimeEvent* timeEventHead;
int stop;
void *apidata; /* This is used for polling API specific data */
aeBeforeSleepProc *beforesleep;
void* apidata; /* This is used for polling API specific data */
aeBeforeSleepProc* beforesleep;
aeCheckThreadStopProc* checkThreadStop;
void* checkThreadStopData;
} aeEventLoop;

/* Prototypes */
aeEventLoop *aeCreateEventLoop(int setsize);
void aeDeleteEventLoop(aeEventLoop *eventLoop);
void aeStop(aeEventLoop *eventLoop);
int aeCreateFileEvent(aeEventLoop *eventLoop, int fd, int mask,
aeFileProc *proc, void *clientData);
void aeDeleteFileEvent(aeEventLoop *eventLoop, int fd, int mask);
int aeGetFileEvents(aeEventLoop *eventLoop, int fd);
long long aeCreateTimeEvent(aeEventLoop *eventLoop, long long milliseconds,
aeTimeProc *proc, void *clientData,
aeEventFinalizerProc *finalizerProc);
int aeDeleteTimeEvent(aeEventLoop *eventLoop, long long id);
int aeProcessEvents(aeEventLoop *eventLoop, int flags);
aeEventLoop* aeCreateEventLoop(int setsize);
void aeDeleteEventLoop(aeEventLoop* eventLoop);
void aeStop(aeEventLoop* eventLoop);
int aeCreateFileEvent(aeEventLoop* eventLoop, int fd, int mask,
aeFileProc* proc, void* clientData);
void aeDeleteFileEvent(aeEventLoop* eventLoop, int fd, int mask);
int aeGetFileEvents(aeEventLoop* eventLoop, int fd);
long long aeCreateTimeEvent(aeEventLoop* eventLoop, long long milliseconds,
aeTimeProc* proc, void* clientData,
aeEventFinalizerProc* finalizerProc);
int aeDeleteTimeEvent(aeEventLoop* eventLoop, long long id);
int aeProcessEvents(aeEventLoop* eventLoop, int flags);
int aeWait(int fd, int mask, long long milliseconds);
void aeMain(aeEventLoop *eventLoop);
char *aeGetApiName(void);
void aeSetBeforeSleepProc(aeEventLoop *eventLoop, aeBeforeSleepProc *beforesleep);
int aeGetSetSize(aeEventLoop *eventLoop);
int aeResizeSetSize(aeEventLoop *eventLoop, int setsize);
void aeMain(aeEventLoop* eventLoop);
char* aeGetApiName(void);
void aeSetBeforeSleepProc(aeEventLoop* eventLoop, aeBeforeSleepProc* beforesleep);
void aeSetCheckThreadStopProc(aeEventLoop* eventLoop,
aeCheckThreadStopProc* checkThreadStop, void* checkData);

#endif
Loading