diff options
author | Nick Mathewson <nickm@torproject.org> | 2006-09-19 20:41:31 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2006-09-19 20:41:31 +0000 |
commit | 93beeac01d27c3150cc998331ab79354c311bd8f (patch) | |
tree | 9ff5d506c6e4f74a01b54e26225b0485ca30eb38 /src/common | |
parent | 8648b1133b72f384fc588208c0439a1aff30ec03 (diff) | |
download | tor-93beeac01d27c3150cc998331ab79354c311bd8f.tar.gz tor-93beeac01d27c3150cc998331ab79354c311bd8f.zip |
Merge in some bsockets calls, all wrapped inside #if defined(USE_BSOCKETS)
svn:r8427
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compat.c | 12 | ||||
-rw-r--r-- | src/common/compat.h | 14 | ||||
-rw-r--r-- | src/common/tortls.c | 14 | ||||
-rw-r--r-- | src/common/util.c | 4 |
4 files changed, 36 insertions, 8 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index 674baeca0a..c98748bcd2 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -92,6 +92,10 @@ const char compat_c_id[] = #include <sys/mman.h> #endif +#ifdef USE_BSOCKETS +#include <bsocket.h> +#endif + #include "log.h" #include "util.h" @@ -425,7 +429,7 @@ touch_file(const char *fname) void set_socket_nonblocking(int socket) { -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(USE_BSOCKETS) unsigned long nonblocking = 1; ioctlsocket(socket, FIONBIO, (unsigned long*) &nonblocking); #else @@ -458,6 +462,8 @@ tor_socketpair(int family, int type, int protocol, int fd[2]) int r; r = socketpair(family, type, protocol, fd); return r < 0 ? -errno : r; +#elif defined(USE_BSOCKETS) + return bsockepair(family, type, protocol, fd); #else /* This socketpair does not work when localhost is down. So * it's really not the same thing at all. But it's close enough @@ -1233,7 +1239,7 @@ struct tor_mutex_t { * should call tor_socket_errno <em>at most once</em> on the failing * socket to get the error. */ -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(USE_BSOCKETS) int tor_socket_errno(int sock) { @@ -1249,7 +1255,7 @@ tor_socket_errno(int sock) } #endif -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(USE_BSOCKETS) #define E(code, s) { code, (s " [" #code " ]") } struct { int code; const char *msg; } windows_socket_errors[] = { E(WSAEINTR, "Interrupted function call"), diff --git a/src/common/compat.h b/src/common/compat.h index 7ed2e62e62..5567f5e9c1 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -199,7 +199,9 @@ int touch_file(const char *fname); #endif /* ===== Net compatibility */ -#ifdef MS_WINDOWS +#ifdef USE_BSOCKETS +#define tor_close_socket(s) bclose(s) +#elif defined(MS_WINDOWS) /** On Windows, you have to call close() on fds returned by open(), * and closesocket() on fds returned by socket(). On Unix, everything * gets close()'d. We abstract this difference by always using @@ -211,6 +213,14 @@ int touch_file(const char *fname); #define tor_close_socket(s) close(s) #endif +#ifdef USE_BSOCKETS +#define tor_socket_send(s, buf, len, flags) bsend(s, buf, len, flags) +#define tor_socket_recv(s, buf, len, flags) brecv(s, buf, len, flags) +#else +#define tor_socket_send(s, buf, len, flags) send(s, buf, len, flags) +#define tor_socket_recv(s, buf, len, flags) recv(s, buf, len, flags) +#endif + #if (SIZEOF_SOCKLEN_T == 0) typedef int socklen_t; #endif @@ -227,7 +237,7 @@ int network_init(void); * errnos against expected values, and use tor_socket_errno to find * the actual errno after a socket operation fails. */ -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(USE_BSOCKETS) /** Return true if e is EAGAIN or the local equivalent. */ #define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN || (e) == WSAEWOULDBLOCK) /** Return true if e is EINPROGRESS or the local equivalent. */ diff --git a/src/common/tortls.c b/src/common/tortls.c index 072f9709dc..d9e71a6380 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -414,7 +414,9 @@ tor_tls_context_new(crypto_pk_env_t *identity, const char *nickname, tor_tls_t * tor_tls_new(int sock, int isServer) { + BIO *bio = NULL; tor_tls_t *result = tor_malloc(sizeof(tor_tls_t)); + tor_assert(global_tls_context); /* make sure somebody made it first */ if (!(result->ssl = SSL_new(global_tls_context->ctx))) { tls_log_errors(LOG_WARN, "generating TLS context"); @@ -422,7 +424,17 @@ tor_tls_new(int sock, int isServer) return NULL; } result->socket = sock; - SSL_set_fd(result->ssl, sock); +#ifdef USE_BSOCKETS + bio = BIO_new_bsocket(sock, BIO_NOCLOSE); +#else + bio = BIO_new_socket(sock, BIO_NOCLOSE); +#endif + if (! bio) { + tls_log_errors(LOG_WARN, "opening BIO"); + tor_free(result); + return NULL; + } + SSL_set_bio(result->ssl, bio, bio); result->state = TOR_TLS_ST_HANDSHAKE; result->isServer = isServer; result->wantwrite_n = 0; diff --git a/src/common/util.c b/src/common/util.c index e1c8844e6b..8bd1f2aec0 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -936,7 +936,7 @@ write_all(int fd, const char *buf, size_t count, int isSocket) while (written != count) { if (isSocket) - result = send(fd, buf+written, count-written, 0); + result = tor_socket_send(fd, buf+written, count-written, 0); else result = write(fd, buf+written, count-written); if (result<0) @@ -962,7 +962,7 @@ read_all(int fd, char *buf, size_t count, int isSocket) while (numread != count) { if (isSocket) - result = recv(fd, buf+numread, count-numread, 0); + result = tor_socket_recv(fd, buf+numread, count-numread, 0); else result = read(fd, buf+numread, count-numread); if (result<0) |