Skip to content

Commit

Permalink
windows fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gafferongames committed Jul 16, 2017
1 parent 0f99326 commit 4c06702
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
8 changes: 4 additions & 4 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void test_queue()
check( queue.GetSize() == QueueSize );
}

#if YOJIMBO_HAS_MBEDTLS
#if YOJIMBO_WITH_MBEDTLS

void test_base64()
{
Expand Down Expand Up @@ -167,7 +167,7 @@ void test_base64()
check( memcmp( key, decoded_key, KeyBytes ) == 0 );
}

#endif // #if YOJIMBO_HAS_MBEDTLS
#endif // #if YOJIMBO_WITH_MBEDTLS

void test_bitpacker()
{
Expand Down Expand Up @@ -2211,9 +2211,9 @@ int main()

RUN_TEST( test_endian );
RUN_TEST( test_queue );
#if YOJIMBO_HAS_MBEDTLS
#if YOJIMBO_WITH_MBEDTLS
RUN_TEST( test_base64 );
#endif // #if YOJIMBO_HAS_MBEDTLS
#endif // #if YOJIMBO_WITH_MBEDTLS
RUN_TEST( test_bitpacker );
RUN_TEST( test_stream );
RUN_TEST( test_address );
Expand Down
42 changes: 21 additions & 21 deletions yojimbo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ void ShutdownYojimbo()
#include <string.h>
#include <stdio.h>

#if YOJIMBO_HAS_MBEDTLS
#if YOJIMBO_WITH_MBEDTLS
#include <mbedtls/base64.h>
#endif // #if YOJIMBO_HAS_MBEDTLS
#endif // #if YOJIMBO_WITH_MBEDTLS

extern "C" void netcode_random_bytes( uint8_t*, int );

Expand Down Expand Up @@ -143,7 +143,7 @@ namespace yojimbo
printf( " (%d bytes)\n", data_bytes );
}

#if YOJIMBO_HAS_MBEDTLS
#if YOJIMBO_WITH_MBEDTLS

int base64_encode_string( const char * input, char * output, int output_size )
{
Expand Down Expand Up @@ -205,7 +205,7 @@ namespace yojimbo
return ( result == 0 ) ? (int) output_length : -1;
}

#endif // #if YOJIMBO_HAS_MBEDTLS
#endif // #if YOJIMBO_WITH_MBEDTLS
}

// ---------------------------------------------------------------------------------
Expand Down Expand Up @@ -872,7 +872,7 @@ double yojimbo_time()

// ---------------------------------------------------------------------------------

#if YOJIMBO_HAS_MBEDTLS
#if YOJIMBO_WITH_MBEDTLS
#include <mbedtls/config.h>
#include <mbedtls/platform.h>
#include <mbedtls/net.h>
Expand All @@ -882,7 +882,7 @@ double yojimbo_time()
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/error.h>
#include <mbedtls/certs.h>
#endif // #if YOJIMBO_HAS_MBEDTLS
#endif // #if YOJIMBO_WITH_MBEDTLS
#include <inttypes.h>
#include <string.h>
#include "netcode.h"
Expand All @@ -894,46 +894,46 @@ namespace yojimbo
{
struct MatcherInternal
{
#if YOJIMBO_HAS_MBEDTLS
#if YOJIMBO_WITH_MBEDTLS
mbedtls_net_context server_fd;
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
mbedtls_x509_crt cacert;
#endif // #if YOJIMBO_HAS_MBEDTLS
#endif // #if YOJIMBO_WITH_MBEDTLS
};

Matcher::Matcher( Allocator & allocator )
{
#if YOJIMBO_HAS_MBEDTLS
#if YOJIMBO_WITH_MBEDTLS
yojimbo_assert( ConnectTokenBytes == NETCODE_CONNECT_TOKEN_BYTES );
m_allocator = &allocator;
m_initialized = false;
m_matchStatus = MATCH_IDLE;
m_internal = YOJIMBO_NEW( allocator, MatcherInternal );
memset( m_connectToken, 0, sizeof( m_connectToken ) );
#else // #if YOJIMBO_HAS_MBEDTLS
#else // #if YOJIMBO_WITH_MBEDTLS
(void) allocator;
#endif // #if YOJIMBO_HAS_MBEDTLS
#endif // #if YOJIMBO_WITH_MBEDTLS
}

Matcher::~Matcher()
{
#if YOJIMBO_HAS_MBEDTLS
#if YOJIMBO_WITH_MBEDTLS
mbedtls_net_free( &m_internal->server_fd );
mbedtls_x509_crt_free( &m_internal->cacert );
mbedtls_ssl_free( &m_internal->ssl );
mbedtls_ssl_config_free( &m_internal->conf );
mbedtls_ctr_drbg_free( &m_internal->ctr_drbg );
mbedtls_entropy_free( &m_internal->entropy );
YOJIMBO_DELETE( *m_allocator, MatcherInternal, m_internal );
#endif // #if YOJIMBO_HAS_MBEDTLS
#endif // #if YOJIMBO_WITH_MBEDTLS
}

bool Matcher::Initialize()
{
#if YOJIMBO_HAS_MBEDTLS
#if YOJIMBO_WITH_MBEDTLS

const char * pers = "yojimbo_client";

Expand All @@ -960,7 +960,7 @@ namespace yojimbo

memset( m_connectToken, 0, sizeof( m_connectToken ) );

#endif // // #if YOJIMBO_HAS_MBEDTLS
#endif // // #if YOJIMBO_WITH_MBEDTLS

m_initialized = true;

Expand All @@ -969,7 +969,7 @@ namespace yojimbo

void Matcher::RequestMatch( uint64_t protocolId, uint64_t clientId, bool verifyCertificate )
{
#if YOJIMBO_HAS_MBEDTLS
#if YOJIMBO_WITH_MBEDTLS

yojimbo_assert( m_initialized );

Expand Down Expand Up @@ -1096,14 +1096,14 @@ namespace yojimbo

mbedtls_ssl_close_notify( &m_internal->ssl );

#else // #if YOJIMBO_HAS_MBEDTLS
#else // #if YOJIMBO_WITH_MBEDTLS

(void) protocolId;
(void) clientId;
(void) verifyCertificate;
m_matchStatus = MATCH_FAILED;

#endif // #if YOJIMBO_HAS_MBEDTLS
#endif // #if YOJIMBO_WITH_MBEDTLS
}

MatchStatus Matcher::GetMatchStatus()
Expand All @@ -1113,17 +1113,17 @@ namespace yojimbo

void Matcher::GetConnectToken( uint8_t * connectToken )
{
#if YOJIMBO_HAS_MBEDTLS
#if YOJIMBO_WITH_MBEDTLS
yojimbo_assert( connectToken );
yojimbo_assert( m_matchStatus == MATCH_READY );
if ( m_matchStatus == MATCH_READY )
{
memcpy( connectToken, m_connectToken, ConnectTokenBytes );
}
#else // #if YOJIMBO_HAS_MBEDTLS
#else // #if YOJIMBO_WITH_MBEDTLS
(void) connectToken;
yojimbo_assert( false );
#endif // #if YOJIMBO_HAS_MBEDTLS
#endif // #if YOJIMBO_WITH_MBEDTLS
}
}

Expand Down
4 changes: 2 additions & 2 deletions yojimbo.h
Original file line number Diff line number Diff line change
Expand Up @@ -5614,10 +5614,10 @@ namespace yojimbo
Allocator * m_allocator; ///< The allocator passed into the constructor.
bool m_initialized; ///< True if the matcher was successfully initialized. See Matcher::Initialize.
MatchStatus m_matchStatus; ///< The current match status.
#if YOJIMBO_HAS_MBEDTLS
#if YOJIMBO_WITH_MBEDTLS
struct MatcherInternal * m_internal; ///< Internals are in here to avoid spilling details of mbedtls library outside of yojimbo_matcher.cpp
uint8_t m_connectToken[ConnectTokenBytes]; ///< The connect token data from the last call to Matcher::RequestMatch once the match status is MATCH_READY.
#endif // #if YOJIMBO_HAS_MBEDTLS
#endif // #if YOJIMBO_WITH_MBEDTLS
};
}

Expand Down

0 comments on commit 4c06702

Please sign in to comment.