diff options
author | Brian Smith <brian@briansmith.org> | 2015-01-28 09:32:08 +0300 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2015-01-28 23:24:09 +0300 |
commit | 33970e6ce0de1a553bd57d5b42527cd95292acae (patch) | |
tree | 2829eaa1e43c4a55e6a98cad876a826090c2fed2 /tool/transport_common.cc | |
parent | 9a9a193388f0b144388bfbb62c4cc4a5c8fd82f9 (diff) |
Enable bssl client/s_client and server/s_server on Windows.
Change-Id: Iea9bd25176724b56ebb21bded6925f5d30176548
Reviewed-on: https://boringssl-review.googlesource.com/3071
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'tool/transport_common.cc')
-rw-r--r-- | tool/transport_common.cc | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/tool/transport_common.cc b/tool/transport_common.cc index 528dd3e6..c2b3e0c8 100644 --- a/tool/transport_common.cc +++ b/tool/transport_common.cc @@ -14,17 +14,12 @@ #include <openssl/base.h> -// TODO(davidben): bssl client does not work on Windows. -#if !defined(OPENSSL_WINDOWS) - #include <string> #include <vector> #include <errno.h> #include <stdlib.h> #include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> #if !defined(OPENSSL_WINDOWS) #include <arpa/inet.h> @@ -32,11 +27,19 @@ #include <netdb.h> #include <netinet/in.h> #include <sys/select.h> +#include <sys/socket.h> #include <unistd.h> #else +#define WIN32_LEAN_AND_MEAN // prevent conflicting defines of X509_* names +#define NOMINMAX +#include <io.h> #include <WinSock2.h> #include <WS2tcpip.h> typedef int socklen_t; +typedef int ssize_t; +#define read _read +#define write _write +#pragma comment(lib, "Ws2_32.lib") #endif #include <openssl/err.h> @@ -45,6 +48,24 @@ typedef int socklen_t; #include "internal.h" +#if !defined(OPENSSL_WINDOWS) +static int closesocket(int sock) { + return close(sock); +} +#endif + +bool InitSocketLibrary() { +#if defined(OPENSSL_WINDOWS) + WSADATA wsaData; + int err = WSAStartup(MAKEWORD(2, 2), &wsaData); + if (err != 0) { + fprintf(stderr, "WSAStartup failed with error %d\n", err); + return false; + } +#endif + return true; +} + // Connect sets |*out_sock| to be a socket connected to the destination given // in |hostname_and_port|, which should be of the form "www.example.com:123". // It returns true on success and false otherwise. @@ -140,7 +161,7 @@ bool Accept(int *out_sock, const std::string &port) { ok = true; out: - close(server_sock); + closesocket(server_sock); return ok; } @@ -158,7 +179,7 @@ bool SocketSetNonBlocking(int sock, bool is_non_blocking) { #if defined(OPENSSL_WINDOWS) u_long arg = is_non_blocking; - ok = 0 == ioctlsocket(sock, FIOBIO, &arg); + ok = 0 == ioctlsocket(sock, FIONBIO, &arg); #else int flags = fcntl(sock, F_GETFL, 0); if (flags < 0) { @@ -217,7 +238,11 @@ bool TransferData(SSL *ssl, int sock) { if (n == 0) { FD_CLR(0, &read_fds); stdin_open = false; +#if !defined(OPENSSL_WINDOWS) shutdown(sock, SHUT_WR); +#else + shutdown(sock, SD_SEND); +#endif continue; } else if (n < 0) { perror("read from stdin"); @@ -271,6 +296,3 @@ bool TransferData(SSL *ssl, int sock) { } } } - - -#endif // !OPENSSL_WINDOWS |