Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hewei.it committed Apr 30, 2021
1 parent 9ce06f5 commit 737e901
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function=pthread_mutex_timedlock && header=pthread.h && check_function
function=sem_timedwait && header=semaphore.h && check_function

# Checks for options
source config.mk
source config.mk 2>/dev/null
option=ENABLE_UDS && check_option
option=USE_MULTIMAP && check_option

Expand Down
23 changes: 12 additions & 11 deletions examples/websocket_server_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,27 @@ int main(int argc, char** argv) {
}
int port = atoi(argv[1]);

TimerID timerID = INVALID_TIMER_ID;
WebSocketServerCallbacks ws;
ws.onopen = [](const WebSocketChannelPtr& channel, const std::string& url) {
ws.onopen = [&timerID](const WebSocketChannelPtr& channel, const std::string& url) {
printf("onopen: GET %s\n", url.c_str());
// send(time) every 1s
setInterval(1000, [channel](TimerID id) {
if (channel->isConnected()) {
char str[DATETIME_FMT_BUFLEN] = {0};
datetime_t dt = datetime_now();
datetime_fmt(&dt, str);
channel->send(str);
} else {
killTimer(id);
}
timerID = setInterval(1000, [channel](TimerID id) {
char str[DATETIME_FMT_BUFLEN] = {0};
datetime_t dt = datetime_now();
datetime_fmt(&dt, str);
channel->send(str);
});
};
ws.onmessage = [](const WebSocketChannelPtr& channel, const std::string& msg) {
printf("onmessage: %s\n", msg.c_str());
};
ws.onclose = [](const WebSocketChannelPtr& channel) {
ws.onclose = [&timerID](const WebSocketChannelPtr& channel) {
printf("onclose\n");
if (timerID != INVALID_TIMER_ID) {
killTimer(timerID);
timerID = INVALID_TIMER_ID;
}
};

websocket_server_t server;
Expand Down

0 comments on commit 737e901

Please sign in to comment.