]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/raw_socket.hxx
Asynchronous host lookups+caching, attempt #2
[simgear.git] / simgear / io / raw_socket.hxx
index 1af74ce0e8d946baaeda685d84c748fbb3705ec7..9450e9eb8729cefe97caeefbfc445172e3a3513d 100644 (file)
 #ifndef SG_IO_SOCKET_HXX
 #define SG_IO_SOCKET_HXX
 
-#include <errno.h>
+//#include <errno.h>
 
-#if defined(__APPLE__) || defined(__FreeBSD__)
-#  include <netinet/in.h>
-#endif
+//#if defined(__APPLE__) || defined(__FreeBSD__)
+//#  include <netinet/in.h>
+//#endif
 
+struct sockaddr_in;
+struct sockaddr;
+     
 namespace simgear
 {
 
@@ -37,28 +40,30 @@ namespace simgear
  */
 class IPAddress
 {
+    mutable struct sockaddr_in* addr;
 public:
-  IPAddress () {}
+  IPAddress () : addr(0) {}
   IPAddress ( const char* host, int port ) ;
-  IPAddress ( struct sockaddr* addr, size_t len );
+  ~IPAddress();
+  
+  static bool lookupNonblocking(const char* host, IPAddress& addr);
   
+  IPAddress( const IPAddress& other );
+  const IPAddress& operator=(const IPAddress& other);
+
   void set ( const char* host, int port ) ;
   const char* getHost () const ;
   unsigned int getPort() const ;
+  void setPort(int port);
+  
   unsigned int getIP () const ;
   unsigned int getFamily () const ;
   static const char* getLocalHost () ;
 
   bool getBroadcast () const ;
   
-  void setPort(unsigned int port);
-  const struct sockaddr_in* getAddress() const
-      { return &_raw; }
-      
-  const size_t getAddressSize() const
-      { return sizeof(struct sockaddr_in); }
-private:
-    struct sockaddr_in _raw;
+  unsigned int getAddrLen() const;
+  sockaddr* getAddr() const;
 };
 
 
@@ -68,7 +73,7 @@ private:
 class Socket
 {
   int handle ;
-
+  
 public:
   
   Socket () ;
@@ -85,7 +90,7 @@ public:
   int   listen     ( int backlog ) ;
   int   accept      ( IPAddress* addr ) ;
   int   connect     ( const char* host, int port ) ;
-  int   connect     ( const IPAddress& addr ) ;
+  int   connect     ( IPAddress* addr ) ;
   int   send       ( const void * buffer, int size, int flags = 0 ) ;
   int   sendto      ( const void * buffer, int size, int flags, const IPAddress* to ) ;
   int   recv       ( void * buffer, int size, int flags = 0 ) ;