diff options
author | Nick Mathewson <nickm@torproject.org> | 2003-08-12 03:08:41 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2003-08-12 03:08:41 +0000 |
commit | c336c99e609b2918ca664bc1fdbfb916a6811508 (patch) | |
tree | ff04c4774b60cef2dce98d88497ac5ac4a3cb8e7 /src/common | |
parent | 5126f203f23773f64b51e5c0c7b7e1d702f26ca9 (diff) | |
download | tor-c336c99e609b2918ca664bc1fdbfb916a6811508.tar tor-c336c99e609b2918ca664bc1fdbfb916a6811508.tar.gz |
Start of port to win32. Missing are:
- signal support
- forking for DNS farm
- changes for async IO
- daemonizing
In other words, some files still don't build, and the ones that do build,
do nonblocking IO incorrectly.
I'm also not checking in the project files till I have a good place
for them.
svn:r380
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/crypto.c | 12 | ||||
-rw-r--r-- | src/common/fakepoll.c | 17 | ||||
-rw-r--r-- | src/common/log.c | 4 | ||||
-rw-r--r-- | src/common/log.h | 11 | ||||
-rw-r--r-- | src/common/test.h | 22 | ||||
-rw-r--r-- | src/common/util.c | 32 | ||||
-rw-r--r-- | src/common/util.h | 26 |
7 files changed, 105 insertions, 19 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 130ecac85..4e9a98189 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -40,11 +40,11 @@ #define RETURN_SSL_OUTCOME(exp) return !(exp) #endif -static inline const EVP_CIPHER * -crypto_cipher_evp_cipher(int type, int enc); +/* static INLINE const EVP_CIPHER * + crypto_cipher_evp_cipher(int type, int enc); +*/ - -static inline int +static INLINE int crypto_cipher_iv_length(int type) { /* printf("%d -> %d IV\n",type, EVP_CIPHER_iv_length( @@ -61,7 +61,7 @@ crypto_cipher_iv_length(int type) { } } -static inline int +static INLINE int crypto_cipher_key_length(int type) { /* printf("%d -> %d\n",type, EVP_CIPHER_key_length( @@ -78,7 +78,7 @@ crypto_cipher_key_length(int type) { } } -static inline const EVP_CIPHER * +static INLINE const EVP_CIPHER * crypto_cipher_evp_cipher(int type, int enc) { switch(type) { diff --git a/src/common/fakepoll.c b/src/common/fakepoll.c index 9b2493e62..b059da571 100644 --- a/src/common/fakepoll.c +++ b/src/common/fakepoll.c @@ -6,13 +6,24 @@ * Nick Mathewson <nickm@freehaven.net> */ -#include "fakepoll.h" - +#include "orconfig.h" #ifdef USE_FAKE_POLL -#include <sys/time.h> #include <sys/types.h> +#ifdef HAVE_UNISTD_H #include <unistd.h> +#endif +#ifdef HAVE_STRING_H #include <string.h> +#endif +#if _MSC_VER > 1300 +#include <winsock2.h> +#include <ws2tcpip.h> +#elif defined(_MSC_VER) +#include <winsock.h> +#endif + +#include "fakepoll.h" +#include "util.h" int poll(struct pollfd *ufds, unsigned int nfds, int timeout) diff --git a/src/common/log.c b/src/common/log.c index 75a064399..8245bd4f5 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -3,6 +3,7 @@ /* $Id$ */ #include "../or/or.h" +#include "util.h" static const char *sev_to_string(int severity) { switch(severity) { @@ -30,8 +31,7 @@ logv(int severity, const char *funcname, const char *format, va_list ap) assert(format); if (severity > loglevel) return; - if (gettimeofday(&now,NULL) < 0) - return; + my_gettimeofday(&now); t = time(NULL); strftime(buf, 200, "%b %d %H:%M:%S", localtime(&t)); diff --git a/src/common/log.h b/src/common/log.h index 0b3d57d6e..38f330c08 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -7,7 +7,18 @@ #ifndef __LOG_H +#ifdef HAVE_SYSLOG_H #include <syslog.h> +#else +#define LOG_DEBUG 0 +#define LOG_INFO 1 +#define LOG_NOTICE 2 +#define LOG_WARNING 3 +#define LOG_ERR 4 +#define LOG_CRIT 5 +#define LOG_ALERT 6 +#define LOG_EMERG 7 +#endif /* magic to make GCC check for proper format strings. */ #ifdef __GNUC__ diff --git a/src/common/test.h b/src/common/test.h index e80a964fc..a22b8dd93 100644 --- a/src/common/test.h +++ b/src/common/test.h @@ -10,12 +10,18 @@ #define STMT_BEGIN do { #define STMT_END } while (0) +#ifdef __GNUC__ +#define PRETTY_FUNCTION __PRETTY_FUNCTION__ +#else +#define PRETTY_FUNCTION "" +#endif + #define test_fail() \ STMT_BEGIN \ printf("\nFile %s: line %d (%s): assertion failed.", \ __FILE__, \ __LINE__, \ - __PRETTY_FUNCTION__); \ + PRETTY_FUNCTION); \ return; \ STMT_END @@ -25,7 +31,7 @@ printf("\nFile %s: line %d (%s): assertion failed: (%s)\n", \ __FILE__, \ __LINE__, \ - __PRETTY_FUNCTION__, \ + PRETTY_FUNCTION, \ #expr); \ return; \ } STMT_END @@ -38,7 +44,7 @@ " (%ld != %ld)\n", \ __FILE__, \ __LINE__, \ - __PRETTY_FUNCTION__, \ + PRETTY_FUNCTION, \ #expr1, #expr2, \ v1, v2); \ return; \ @@ -52,7 +58,7 @@ " (%ld == %ld)\n", \ __FILE__, \ __LINE__, \ - __PRETTY_FUNCTION__, \ + PRETTY_FUNCTION, \ #expr1, #expr2, \ v1, v2); \ return; \ @@ -66,7 +72,7 @@ " (\"%s\" != \"%s\")\n", \ __FILE__, \ __LINE__, \ - __PRETTY_FUNCTION__, \ + PRETTY_FUNCTION, \ #expr1, #expr2, \ v1, v2); \ return; \ @@ -80,7 +86,7 @@ " (\"%s\" == \"%s\")\n", \ __FILE__, \ __LINE__, \ - __PRETTY_FUNCTION__, \ + PRETTY_FUNCTION, \ #expr1, #expr2, \ v1, v2); \ return; \ @@ -93,7 +99,7 @@ printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n", \ __FILE__, \ __LINE__, \ - __PRETTY_FUNCTION__, \ + PRETTY_FUNCTION, \ #expr1, #expr2); \ return; \ } STMT_END @@ -105,7 +111,7 @@ printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n", \ __FILE__, \ __LINE__, \ - __PRETTY_FUNCTION__, \ + PRETTY_FUNCTION, \ #expr1, #expr2); \ return; \ } STMT_END diff --git a/src/common/util.c b/src/common/util.c index 5eaa88f4f..cde1cb33b 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -2,8 +2,23 @@ /* See LICENSE for licensing information */ /* $Id$ */ +#include "orconfig.h" + #include <stdlib.h> #include <limits.h> +#if _MSC_VER > 1300 +#include <winsock2.h> +#include <ws2tcpip.h> +#elif defined(_MSC_VER) +#include <winsock.h> +#endif +#ifdef HAVE_SYS_FCNTL_H +#include <sys/fcntl.h> +#endif +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#endif + #include "util.h" #include "log.h" @@ -23,12 +38,18 @@ void *tor_malloc(size_t size) { void my_gettimeofday(struct timeval *timeval) { +#ifdef HAVE_GETTIMEOFDAY if (gettimeofday(timeval, NULL)) { log_fn(LOG_ERR, "gettimeofday failed."); /* If gettimeofday dies, we have either given a bad timezone (we didn't), or segfaulted.*/ exit(1); } +#elif defined(HAVE_FTIME) + ftime(timeval); +#else +#error "No way to get time." +#endif return; } @@ -75,3 +96,14 @@ void tv_addms(struct timeval *a, long ms) { a->tv_sec += ((ms * 1000) / 1000000) + (a->tv_usec / 1000000); a->tv_usec %= 1000000; } + +void set_socket_nonblocking(int socket) +{ +#ifdef _MSC_VER + /* Yes means no and no means yes. Do you not want to be nonblocking? */ + int nonblocking = 0; + ioctlsocket(socket, FIONBIO, (unsigned long*) &nonblocking); +#else + fcntl(socket, F_SETFL, O_NONBLOCK); +#endif +} diff --git a/src/common/util.h b/src/common/util.h index 6b238bf8c..68d002372 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -5,7 +5,31 @@ #ifndef __UTIL_H #define __UTIL_H +#include "orconfig.h" + +#ifdef HAVE_SYS_TIME_H #include <sys/time.h> +#endif +#ifdef HAVE_TIME_H +#include <time.h> +#endif +#ifndef HAVE_GETTIMEOFDAY +#ifdef HAVE_FTIME +#include <sys/timeb.h> +#define timeval timeb +#define tv_sec time +#define tv_usec millitm +#endif +#endif + +#ifdef _MSC_VER +/* Windows names string functions funnily. */ +#define strncasecmp strnicmp +#define strcasecmp stricmp +#define INLINE __inline +#else +#define INLINE inline +#endif void *tor_malloc(size_t size); @@ -19,4 +43,6 @@ void tv_addms(struct timeval *a, long ms); void tv_add(struct timeval *a, struct timeval *b); int tv_cmp(struct timeval *a, struct timeval *b); +void set_socket_nonblocking(int socket); + #endif |