Skip to content

Commit

Permalink
httpc support windows
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Jan 22, 2024
1 parent 40bf332 commit f9c75c6
Show file tree
Hide file tree
Showing 5 changed files with 432 additions and 52 deletions.
6 changes: 4 additions & 2 deletions pkg/ant.httpc/make.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ lm:lua_source "httpc" {
},
windows = {
sources = {
"src/download_win.c",
"src/httpc.cpp",
},
links = "urlmon",
links = {
"Wininet",
}
},
macos = {
sources = {
Expand Down
33 changes: 33 additions & 0 deletions pkg/ant.httpc/src/channel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <mutex>
#include <vector>
#include <bee/thread/spinlock.h>

#if defined(__APPLE__)
typedef void(^SelectHandler)(void* data);
#else
#include <functional>
using SelectHandler = std::function<void(void*)>;
#endif

class MessageChannel {
public:
void push(void* data) {
std::unique_lock<bee::spinlock> lk(mutex);
queue.push_back(data);
}
void select(SelectHandler handler) {
std::unique_lock<bee::spinlock> lk(mutex);
if (queue.empty()) {
return;
}
for (void* data: queue) {
handler(data);
}
queue.clear();
}
private:
std::vector<void*> queue;
bee::spinlock mutex;
};
Loading

0 comments on commit f9c75c6

Please sign in to comment.