medfall

A super great game engine
Log | Files | Refs

commit 5686c8af0e98d01a2819f84baddd5ad92da083d1
parent d41d7cb550e2e997c41f9be10955b55e45f1d408
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Aug 20 23:37:05 +0300

Change dns API a bit

Diffstat:
http.cc | 17++++++-----------
http.h | 2+-
2 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/http.cc b/http.cc @@ -11,9 +11,7 @@ #include "platform_network.h" #include "http.h" -bool dns( const char * host, array< NetAddress > out, size_t * n ) { - *n = 0; - +array< NetAddress > dns( const char * host, array< NetAddress > out ) { struct addrinfo hints; memset( &hints, 0, sizeof( struct addrinfo ) ); hints.ai_family = AF_UNSPEC; @@ -23,7 +21,7 @@ bool dns( const char * host, array< NetAddress > out, size_t * n ) { struct addrinfo * addresses; int ok = getaddrinfo( host, "http", &hints, &addresses ); if( ok != 0 ) { - return false; + return out.slice( 0, 0 ); } struct addrinfo * cursor = addresses; @@ -35,16 +33,13 @@ bool dns( const char * host, array< NetAddress > out, size_t * n ) { } freeaddrinfo( addresses ); - *n = i; - - return true; + return out.slice( 0, i ); } bool dns_first( const char * host, NetAddress * address ) { - StaticArray< NetAddress, 1 > addresses; - size_t n; - bool ok = dns( host, addresses, &n ); - if( !ok ) return false; + StaticArray< NetAddress, 1 > storage; + array< NetAddress > addresses = dns( host, storage ); + if( addresses.n == 0 ) return false; *address = addresses[ 0 ]; return true; } diff --git a/http.h b/http.h @@ -20,6 +20,6 @@ enum GetResult { #define HTTP_PROGRESS_CALLBACK( f ) void f( size_t bytes_downloaded, void * data ) typedef HTTP_PROGRESS_CALLBACK( HttpProgressCallback ); -bool dns( const char * host, array< NetAddress > out, size_t * n ); +array< NetAddress > dns( const char * host, array< NetAddress > out ); bool dns_first( const char * host, NetAddress * address ); GetResult http_get( const NetAddress & address, const char * host, const char * path, std::string * body, HttpProgressCallback progress_cb = NULL, void * cb_data = NULL );