summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-06-05 01:50:35 +0000
committerNick Mathewson <nickm@torproject.org>2004-06-05 01:50:35 +0000
commit17b5b3685f5f2f27b05d4e7f5b1dc78939a9f5e8 (patch)
treea98d7127db6e9a733e0978668f539d211b2638c5 /src/common
parent42569ffd0fc659d81093bc1d7b0fe5171e5738cf (diff)
downloadtor-17b5b3685f5f2f27b05d4e7f5b1dc78939a9f5e8.tar.gz
tor-17b5b3685f5f2f27b05d4e7f5b1dc78939a9f5e8.zip
Make tor build on win32 again; handle locking for server
svn:r1948
Diffstat (limited to 'src/common')
-rw-r--r--src/common/fakepoll.c5
-rw-r--r--src/common/util.c50
-rw-r--r--src/common/util.h8
3 files changed, 61 insertions, 2 deletions
diff --git a/src/common/fakepoll.c b/src/common/fakepoll.c
index 46dbe85e2d..f23c20e652 100644
--- a/src/common/fakepoll.c
+++ b/src/common/fakepoll.c
@@ -11,6 +11,9 @@
#include "orconfig.h"
#include "fakepoll.h"
+#define MAXCONNECTIONS 10000 /* XXXX copied from or.h */
+#define FD_SETSIZE MAXCONNECTIONS
+
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
@@ -47,8 +50,6 @@ tor_poll(struct pollfd *ufds, unsigned int nfds, int timeout)
}
#else
-#define FD_SETSIZE MAXCONNECTIONS
-
int
tor_poll(struct pollfd *ufds, unsigned int nfds, int timeout)
{
diff --git a/src/common/util.c b/src/common/util.c
index 2db99d6c05..89d2000132 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1730,6 +1730,56 @@ int tor_lookup_hostname(const char *name, uint32_t *addr)
}
}
+#ifndef MS_WINDOWS
+struct tor_mutex_t {
+};
+tor_mutex_t *tor_mutex_new(void) { return NULL; }
+void tor_mutex_acquire(tor_mutex_t *m) { }
+void tor_mutex_release(tor_mutex_t *m) { }
+void tor_mutex_free(tor_mutex_t *m) { }
+#else
+struct tor_mutex_t {
+ HANDLE handle;
+};
+tor_mutex_t *tor_mutex_new(void)
+{
+ tor_mutex_t *m;
+ m = tor_malloc_zero(sizeof(tor_mutex_t));
+ m->handle = CreateMutex(NULL, FALSE, NULL);
+ tor_assert(m->handle != NULL);
+ return m;
+}
+void tor_mutex_free(tor_mutex_t *m)
+{
+ CloseHandle(m->handle);
+ tor_free(m);
+}
+void tor_mutex_acquire(tor_mutex_t *m)
+{
+ DWORD r;
+ r = WaitForSingleObject(m->handle, INFINITE);
+ switch (r) {
+ case WAIT_ABANDONED: /* holding thread exited. */
+ case WAIT_OBJECT_0: /* we got the mutex normally. */
+ break;
+ case WAIT_TIMEOUT: /* Should never happen. */
+ tor_assert(0);
+ break;
+ case WAIT_FAILED:
+ log_fn(LOG_WARN, "Failed to acquire mutex: %d", GetLastError());
+ }
+}
+void tor_mutex_release(tor_mutex_t *m)
+{
+ BOOL r;
+ r = ReleaseMutex(m->handle);
+ if (!r) {
+ log_fn(LOG_WARN, "Failed to release mutex: %d", GetLastError());
+ }
+}
+
+#endif
+
/*
Local Variables:
mode:c
diff --git a/src/common/util.h b/src/common/util.h
index 6f707ca729..40154e8bfa 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -221,6 +221,14 @@ int parse_line_from_file(char *line, int maxlen, FILE *f, char **key_out, char *
int spawn_func(int (*func)(void *), void *data);
void spawn_exit();
+/* Because we use threads instead of processes on Windows, we need locking on Windows.
+ * On Unixy platforms, these functions are no-ops. */
+typedef struct tor_mutex_t tor_mutex_t;
+tor_mutex_t *tor_mutex_new(void);
+void tor_mutex_acquire(tor_mutex_t *m);
+void tor_mutex_release(tor_mutex_t *m);
+void tor_mutex_free(tor_mutex_t *m);
+
int tor_socketpair(int family, int type, int protocol, int fd[2]);
int is_internal_IP(uint32_t ip);