Skip to content

Commit

Permalink
[WIP] 50% support windows
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Jun 9, 2024
1 parent 9e465f4 commit 9cd6a1e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
18 changes: 18 additions & 0 deletions ww/eventloop/base/hmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,12 @@ int signal_init(procedure_t reload_fn, void* reload_userdata) {
static HANDLE s_hEventReload = NULL;

static void WINAPI on_timer(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) {
(void)dwUser;
(void)dw1;
(void)dw2;
(void)uTimerID;
(void)uMsg;

DWORD ret;
/*
ret = WaitForSingleObject(s_hEventTerm, 0);
Expand Down Expand Up @@ -566,7 +572,13 @@ static void kill_proc(int pid) {
void signal_handle(const char* signal) {
if (strcmp(signal, "start") == 0) {
if (g_main_ctx.oldpid > 0) {
#ifdef OS_WIN
printf("%s is already running, pid=%lld\n", g_main_ctx.program_name, g_main_ctx.oldpid);

#else
printf("%s is already running, pid=%d\n", g_main_ctx.program_name, g_main_ctx.oldpid);

#endif
exit(0);
}
}
Expand All @@ -589,7 +601,13 @@ void signal_handle(const char* signal) {
}
else if (strcmp(signal, "status") == 0) {
if (g_main_ctx.oldpid > 0) {
#ifdef OS_WIN
printf("%s start/running, pid=%lld\n", g_main_ctx.program_name, g_main_ctx.oldpid);

#else
printf("%s start/running, pid=%d\n", g_main_ctx.program_name, g_main_ctx.oldpid);

#endif
}
else {
printf("%s stop/waiting\n", g_main_ctx.program_name);
Expand Down
12 changes: 5 additions & 7 deletions ww/eventloop/base/hsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ const char* socket_strerror(int err) {
#ifdef OS_WIN
static char buffer[128];

FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_MAX_WIDTH_MASK,
0, ABS(err), 0, buffer, sizeof(buffer), NULL);
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, 0, ABS(err), 0, buffer, sizeof(buffer), NULL);

return buffer;
#else
Expand Down Expand Up @@ -80,7 +77,7 @@ int ResolveAddr(const char* host, sockaddr_u* addr) {
return 0;
}

const char* sockaddr_ip(sockaddr_u* addr, char *ip, int len) {
const char* sockaddr_ip(sockaddr_u* addr, char* ip, int len) {
if (addr->sa.sa_family == AF_INET) {
return inet_ntop(AF_INET, &addr->sin.sin_addr, ip, len);
}
Expand Down Expand Up @@ -239,11 +236,11 @@ static int ListenFD(int sockfd) {
static int ConnectFDTimeout(int connfd, int ms) {
int err = 0;
socklen_t optlen = sizeof(err);
struct timeval tv = { ms / 1000, (ms % 1000) * 1000 };
struct timeval tv = {ms / 1000, (ms % 1000) * 1000};
fd_set writefds;
FD_ZERO(&writefds);
FD_SET(connfd, &writefds);
int ret = select(connfd+1, 0, &writefds, 0, &tv);
int ret = select(connfd + 1, 0, &writefds, 0, &tv);
if (ret < 0) {
perror("select");
goto error;
Expand Down Expand Up @@ -344,6 +341,7 @@ int Socketpair(int family, int type, int protocol, int sv[2]) {
return -1;
}
#ifdef OS_WIN
(void)protocol;
WSAInit();
#endif
int listenfd, connfd, acceptfd;
Expand Down
3 changes: 2 additions & 1 deletion ww/eventloop/event/hloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ static void eventfd_read_cb(hio_t* io, shift_buffer_t* buf) {
assert(bufLen(buf) == sizeof(count));
readUI64(buf, &count);
#endif
(void) count;
for (uint64_t i = 0; i < count; ++i) {
hhybridmutex_lock(&loop->custom_events_mutex);
if (event_queue_empty(&loop->custom_events)) {
Expand Down Expand Up @@ -283,14 +284,14 @@ void hloop_post_event(hloop_t* loop, hevent_t* ev) {
}

int nwrite = 0;
uint64_t count = 1;
hhybridmutex_lock(&loop->custom_events_mutex);
if (loop->eventfds[EVENTFDS_WRITE_INDEX] == -1) {
if (hloop_create_eventfds(loop) != 0) {
goto unlock;
}
}
#if defined(OS_UNIX) && HAVE_EVENTFD
uint64_t count = 1;
nwrite = write(loop->eventfds[EVENTFDS_WRITE_INDEX], &count, sizeof(count));
#elif defined(OS_UNIX) && HAVE_PIPE
nwrite = write(loop->eventfds[EVENTFDS_WRITE_INDEX], "e", 1);
Expand Down
6 changes: 6 additions & 0 deletions ww/eventloop/event/wepoll/wepoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,8 @@ int init(void) {
* To compile cleanly with either compiler, do casts with this "bridge" type:
* MY_FUNC func = (MY_FUNC) (nt__fn_ptr_cast_t) addr; */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
typedef void* nt__fn_ptr_cast_t;
#else
typedef FARPROC nt__fn_ptr_cast_t;
Expand Down Expand Up @@ -903,6 +905,10 @@ int nt_global_init(void) {
return 0;
}

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

#include <string.h>

typedef struct poll_group poll_group_t;
Expand Down
8 changes: 8 additions & 0 deletions ww/utils/mathutils.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#pragma once
#include <math.h> //cel,log2,pow
#include <stdlib.h>
#include <stdint.h>

#ifdef OS_UNIX
#include <sys/types.h>
#else
typedef int64_t ssize_t;
#endif


#undef max
#undef min
static inline ssize_t min(ssize_t x, ssize_t y) { return (((x) < (y)) ? (x) : (y)); }
Expand Down

0 comments on commit 9cd6a1e

Please sign in to comment.