Skip to content

Commit

Permalink
work on example
Browse files Browse the repository at this point in the history
  • Loading branch information
gafferongames committed Dec 27, 2023
1 parent a39b2a9 commit 2f936b3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
19 changes: 3 additions & 16 deletions example.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,8 @@ int main( int argc, char ** argv )
// create client connection

config.context = &client;
#if defined(_MSC_VER)
strcpy_s( config.name, sizeof( config.name ), "client" );
#else
strcpy( config.name, "client" );
#endif

reliable_copy_string( config.name, "client", sizeof( config.name ) );
client.endpoint = reliable_endpoint_create( &config, time );

if ( client.endpoint == NULL )
{
printf( "error: could not create client endpoint\n" );
Expand All @@ -118,15 +112,8 @@ int main( int argc, char ** argv )
// create server connection

config.context = &server;

#if defined(_MSC_VER)
strcpy_s( config.name, sizeof( config.name ), "client" );
#else
strcpy( config.name, "client" );
#endif

reliable_copy_string( config.name, "server", sizeof( config.name ) );
server.endpoint = reliable_endpoint_create( &config, time );

if ( server.endpoint == NULL )
{
printf( "error: could not create server endpoint\n" );
Expand Down Expand Up @@ -154,7 +141,7 @@ int main( int argc, char ** argv )
uint16_t * acks = reliable_endpoint_get_acks( client.endpoint, &num_acks );
for ( int j = 0; j < num_acks; j++ )
{
printf( " --> server acked client packet %d\n", acks[j] );
printf( " --> server acked packet %d\n", acks[j] );
}

reliable_endpoint_clear_acks( client.endpoint );
Expand Down
14 changes: 14 additions & 0 deletions reliable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,20 @@ RELIABLE_CONST uint64_t * reliable_endpoint_counters( struct reliable_endpoint_t
return endpoint->counters;
}

void reliable_copy_string( char * dest, RELIABLE_CONST char * source, size_t dest_size )
{
reliable_assert( dest );
reliable_assert( source );
reliable_assert( dest_size >= 1 );
memset( dest, 0, dest_size );
for ( size_t i = 0; i < dest_size - 1; i++ )
{
if ( source[i] == '\0' )
break;
dest[i] = source[i];
}
}

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

#if RELIABLE_ENABLE_TESTS
Expand Down
3 changes: 3 additions & 0 deletions reliable.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <inttypes.h>

#if !defined(RELIABLE_DEBUG) && !defined(RELIABLE_RELEASE)
Expand Down Expand Up @@ -171,6 +172,8 @@ void reliable_set_assert_function( void (*function)( RELIABLE_CONST char * /*con
RELIABLE_CONST char * /*file*/,
int /*line*/ ) );

void reliable_copy_string( char * dest, RELIABLE_CONST char * source, size_t dest_size );

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 2f936b3

Please sign in to comment.