mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-08-19 03:57:21 +00:00
experimental windows/cygwin support
This commit is contained in:
+107
@@ -2,6 +2,113 @@
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
#ifdef UWSGI_EVENT_USE_POLL
|
||||
#define UWSGI_EVENT_IN POLLIN
|
||||
#define UWSGI_EVENT_OUT POLLOUT
|
||||
|
||||
int uwsgi_poll_event_queue_max = 0;
|
||||
struct uwsgi_poll_event {
|
||||
int nevents;
|
||||
int max_events;
|
||||
struct pollfd *poll;
|
||||
};
|
||||
struct uwsgi_poll_event *uwsgi_poll_event_queue[2048];
|
||||
|
||||
static int uwsgi_poll_fd_is_registered(struct uwsgi_poll_event *upe, int fd) {
|
||||
int i;
|
||||
for(i=0;i<upe->nevents;i++) {
|
||||
if (upe->poll[i].fd == fd) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_poll_fd_add(struct uwsgi_poll_event *upe, int fd, int event) {
|
||||
int pos = upe->nevents;
|
||||
if (pos > upe->max_events) return -1;
|
||||
upe->poll[pos].fd = fd;
|
||||
upe->poll[pos].events = event;
|
||||
upe->nevents++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void uwsgi_poll_queue_rebuild(struct uwsgi_poll_event *upe) {
|
||||
}
|
||||
|
||||
int event_queue_wait(int eq, int timeout, int *interesting_fd) {
|
||||
struct uwsgi_poll_event *upe = uwsgi_poll_event_queue[eq];
|
||||
uwsgi_poll_queue_rebuild(upe);
|
||||
int ret = poll(upe->poll, upe->nevents, timeout * 1000);
|
||||
if (ret > 0) {
|
||||
int i;
|
||||
for(i=0;i<upe->nevents;i++) {
|
||||
if (upe->poll[i].revents & upe->poll[i].events) {
|
||||
*interesting_fd = upe->poll[i].fd;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int event_queue_init() {
|
||||
int eq = uwsgi_poll_event_queue_max;
|
||||
uwsgi_poll_event_queue[eq] = uwsgi_calloc(sizeof(struct uwsgi_poll_event));
|
||||
uwsgi_poll_event_queue_max++;
|
||||
uwsgi_poll_event_queue[eq]->poll = uwsgi_malloc(sizeof(struct pollfd) * uwsgi.max_fd);
|
||||
return eq;
|
||||
}
|
||||
|
||||
void *event_queue_alloc(int nevents) {
|
||||
return uwsgi_malloc(sizeof(struct pollfd) * nevents);
|
||||
}
|
||||
|
||||
int event_queue_interesting_fd_is_read(void *events, int id) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int event_queue_fd_write_to_readwrite(int eq, int fd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int event_queue_fd_read_to_readwrite(int eq, int fd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int event_queue_interesting_fd_is_write(void *events, int id) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int event_queue_add_fd_read(int eq, int fd) {
|
||||
struct uwsgi_poll_event *upe = uwsgi_poll_event_queue[eq];
|
||||
if (uwsgi_poll_fd_is_registered(upe, fd)) return 0;
|
||||
return uwsgi_poll_fd_add(upe, fd, POLLIN);
|
||||
}
|
||||
int event_queue_add_fd_write(int eq, int fd) {
|
||||
return -1;
|
||||
}
|
||||
int event_queue_del_fd(int eq, int fd, int event) {
|
||||
return -1;
|
||||
}
|
||||
int event_queue_wait_multi(int eq, int timeout, void *events, int nevents) {
|
||||
uwsgi_log("ciao\n");
|
||||
return -1;
|
||||
}
|
||||
int event_queue_interesting_fd_has_error(void *events, int id) {
|
||||
return -1;
|
||||
}
|
||||
int event_queue_interesting_fd(void *events, int id) {
|
||||
return -1;
|
||||
}
|
||||
int event_queue_fd_write_to_read(int eq, int fd) {
|
||||
return -1;
|
||||
}
|
||||
int event_queue_fd_read_to_write(int eq, int fd) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_EVENT_USE_PORT
|
||||
|
||||
#include <port.h>
|
||||
|
||||
+48
@@ -401,6 +401,54 @@ void uwsgi_rwunlock_fast(struct uwsgi_lock_item *uli) {
|
||||
uwsgi_unlock_fast(uli);
|
||||
}
|
||||
|
||||
#elif defined(UWSGI_LOCK_USE_WINDOWS_MUTEX)
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#define UWSGI_LOCK_ENGINE_NAME "windows mutexes"
|
||||
#define UWSGI_LOCK_SIZE sizeof(HANDLE)
|
||||
#define UWSGI_RWLOCK_SIZE sizeof(HANDLE)
|
||||
|
||||
|
||||
struct uwsgi_lock_item *uwsgi_lock_fast_init(char *id) {
|
||||
|
||||
struct uwsgi_lock_item *uli = uwsgi_register_lock(id, 0);
|
||||
uli->lock_ptr = CreateMutex(NULL, FALSE, id);
|
||||
return uli;
|
||||
}
|
||||
|
||||
void uwsgi_lock_fast(struct uwsgi_lock_item *uli) {
|
||||
|
||||
|
||||
uli->pid = uwsgi.mypid;
|
||||
}
|
||||
|
||||
void uwsgi_unlock_fast(struct uwsgi_lock_item *uli) {
|
||||
|
||||
uli->pid = 0;
|
||||
}
|
||||
|
||||
pid_t uwsgi_lock_fast_check(struct uwsgi_lock_item *uli) {
|
||||
return uli->pid;
|
||||
}
|
||||
|
||||
struct uwsgi_lock_item *uwsgi_rwlock_fast_init(char *id) {
|
||||
return uwsgi_lock_fast_init(id);
|
||||
}
|
||||
|
||||
void uwsgi_rlock_fast(struct uwsgi_lock_item *uli) {
|
||||
}
|
||||
void uwsgi_wlock_fast(struct uwsgi_lock_item *uli) {
|
||||
}
|
||||
|
||||
pid_t uwsgi_rwlock_fast_check(struct uwsgi_lock_item *uli) {
|
||||
return uli->pid;
|
||||
}
|
||||
|
||||
void uwsgi_rwunlock_fast(struct uwsgi_lock_item *uli) {
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#define uwsgi_lock_fast_init uwsgi_lock_ipcsem_init
|
||||
|
||||
+13
-1
@@ -314,7 +314,7 @@ static struct uwsgi_logger *setup_choosen_logger(struct uwsgi_string_list *usl)
|
||||
int is_id = 1;
|
||||
int i;
|
||||
for (i = 0; i < (space - name); i++) {
|
||||
if (!isalnum(name[i])) {
|
||||
if (!isalnum((int)name[i])) {
|
||||
is_id = 0;
|
||||
break;
|
||||
}
|
||||
@@ -686,6 +686,18 @@ void get_memusage(uint64_t * rss, uint64_t * vsz) {
|
||||
fclose(procfile);
|
||||
}
|
||||
*rss = *rss * uwsgi.page_size;
|
||||
#elif defined(__CYGWIN__)
|
||||
// same as Linux but rss is not in pages...
|
||||
FILE *procfile;
|
||||
int i;
|
||||
procfile = fopen("/proc/self/stat", "r");
|
||||
if (procfile) {
|
||||
i = fscanf(procfile, "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %llu %lld", (unsigned long long *) vsz, (unsigned long long *) rss);
|
||||
if (i != 2) {
|
||||
uwsgi_log("warning: invalid record in /proc/self/stat\n");
|
||||
}
|
||||
fclose(procfile);
|
||||
}
|
||||
#elif defined (__sun__)
|
||||
psinfo_t info;
|
||||
int procfd;
|
||||
|
||||
@@ -2941,11 +2941,13 @@ pid_t uwsgi_fork(char *name) {
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
|
||||
#ifndef __CYGWIN__
|
||||
if (uwsgi.never_swap) {
|
||||
if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
|
||||
uwsgi_error("mlockall()");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) || defined(__sun__)
|
||||
int i;
|
||||
|
||||
@@ -1785,12 +1785,14 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
// initial log setup (files and daemonization)
|
||||
uwsgi_setup_log();
|
||||
|
||||
#ifndef __CYGWIN__
|
||||
// enable never-swap mode
|
||||
if (uwsgi.never_swap) {
|
||||
if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
|
||||
uwsgi_error("mlockall()");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (uwsgi.flock2)
|
||||
uwsgi_opt_flock(NULL, uwsgi.flock2, NULL);
|
||||
|
||||
@@ -274,14 +274,15 @@ extern "C" {
|
||||
#ifdef _POSIX_C_SOURCE
|
||||
#undef _POSIX_C_SOURCE
|
||||
#endif
|
||||
#ifdef __sun__
|
||||
#if defined(__sun__)
|
||||
#define WAIT_ANY (-1)
|
||||
#include <sys/filio.h>
|
||||
#define PRIO_MAX 20
|
||||
#endif
|
||||
|
||||
#ifdef __HAIKU__
|
||||
#if defined(__HAIKU__) || defined(__CYGWIN__)
|
||||
#define WAIT_ANY (-1)
|
||||
#define PRIO_MAX 20
|
||||
#endif
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
@@ -293,6 +294,7 @@ extern "C" {
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/devpoll.h>
|
||||
#elif defined(__HAIKU__)
|
||||
#elif defined(__CYGWIN__)
|
||||
#else
|
||||
#include <sys/event.h>
|
||||
#endif
|
||||
|
||||
+10
-2
@@ -228,7 +228,7 @@ def build_uwsgi(uc, print_only=False):
|
||||
continue
|
||||
p = p.strip()
|
||||
if p == 'ugreen':
|
||||
if uwsgi_os == 'OpenBSD' or uwsgi_cpu[0:3] == 'arm' or uwsgi_os == 'Haiku':
|
||||
if uwsgi_os == 'OpenBSD' or uwsgi_cpu[0:3] == 'arm' or uwsgi_os == 'Haiku' or uwsgi_os.startswith('CYGWIN'):
|
||||
continue
|
||||
epc += "UDEP(%s);" % p
|
||||
eplc += "ULEP(%s);" % p
|
||||
@@ -291,7 +291,7 @@ def build_uwsgi(uc, print_only=False):
|
||||
p = p.strip()
|
||||
|
||||
if p == 'ugreen':
|
||||
if uwsgi_os == 'OpenBSD' or uwsgi_cpu[0:3] == 'arm' or uwsgi_os == 'Haiku':
|
||||
if uwsgi_os == 'OpenBSD' or uwsgi_cpu[0:3] == 'arm' or uwsgi_os == 'Haiku' or uwsgi_os.startswith('CYGWIN'):
|
||||
continue
|
||||
path = 'plugins/%s' % p
|
||||
path = path.rstrip('/')
|
||||
@@ -640,6 +640,8 @@ class uConf(object):
|
||||
pass
|
||||
elif uwsgi_os == 'Darwin':
|
||||
locking_mode = 'osx_spinlock'
|
||||
elif uwsgi_os.startswith('CYGWIN'):
|
||||
locking_mode = 'windows_mutex'
|
||||
|
||||
if locking_mode == 'pthread_mutex':
|
||||
self.cflags.append('-DUWSGI_LOCK_USE_MUTEX')
|
||||
@@ -648,6 +650,8 @@ class uConf(object):
|
||||
self.cflags.append('-DUWSGI_LOCK_USE_POSIX_SEM')
|
||||
elif locking_mode == 'osx_spinlock':
|
||||
self.cflags.append('-DUWSGI_LOCK_USE_OSX_SPINLOCK')
|
||||
elif locking_mode == 'windows_mutex':
|
||||
self.cflags.append('-DUWSGI_LOCK_USE_WINDOWS_MUTEX')
|
||||
|
||||
if locking_mode == 'auto':
|
||||
report['locking'] = 'sysv semaphores'
|
||||
@@ -668,6 +672,8 @@ class uConf(object):
|
||||
event_mode = 'port'
|
||||
elif uwsgi_os in ('Darwin', 'FreeBSD', 'OpenBSD', 'NetBSD'):
|
||||
event_mode = 'kqueue'
|
||||
elif uwsgi_os.startswith('CYGWIN'):
|
||||
event_mode = 'poll'
|
||||
|
||||
if event_mode == 'epoll':
|
||||
self.cflags.append('-DUWSGI_EVENT_USE_EPOLL')
|
||||
@@ -677,6 +683,8 @@ class uConf(object):
|
||||
self.cflags.append('-DUWSGI_EVENT_USE_DEVPOLL')
|
||||
elif event_mode == 'port':
|
||||
self.cflags.append('-DUWSGI_EVENT_USE_PORT')
|
||||
elif event_mode == 'poll':
|
||||
self.cflags.append('-DUWSGI_EVENT_USE_POLL')
|
||||
|
||||
report['event'] = event_mode
|
||||
|
||||
|
||||
Reference in New Issue
Block a user