Browse Source

some cleanups on classes. Changed ActiveOpenNB to ActiveOpen (change back later)

Zachary Pavlov 19 years ago
parent
commit
426dc40890

+ 14 - 6
panda/src/nativenet/Sources.pp

@@ -13,21 +13,29 @@
   #define COMBINED_SOURCES $[TARGET]_composite1.cxx 
   #define COMBINED_SOURCES $[TARGET]_composite1.cxx 
 
 
   #define SOURCES \
   #define SOURCES \
-        buffered_datagramconnection.h ringbuffer.h socket_ip.h socket_tcp_listen.h \
-        time_accumulator.h time_out.h buffered_datagramreader.h socket_address.h \
+        buffered_datagramconnection.h \
+	buffered_datagramreader.h buffered_datagramreader.i \
+	ringbuffer.h ringbuffer.i socket_ip.h \
+	socket_tcp_listen.h time_accumulator.h time_out.h \
+	socket_address.h \
         socket_portable.h  time_base.h time_span.h buffered_datagramwriter.h \
         socket_portable.h  time_base.h time_span.h buffered_datagramwriter.h \
         socket_base.h socket_selector.h socket_udp_incoming.h time_clock.h \
         socket_base.h socket_selector.h socket_udp_incoming.h time_clock.h \
-        membuffer.h socket_fdset.h socket_tcp.h socket_udp_outgoing.h time_general.h
+        membuffer.h membuffer.i socket_fdset.h socket_tcp.h \
+	socket_udp_outgoing.h time_general.h
         
         
         
         
   #define INCLUDED_SOURCES \
   #define INCLUDED_SOURCES \
   
   
   #define INSTALL_HEADERS \
   #define INSTALL_HEADERS \
-        buffered_datagramconnection.h ringbuffer.h socket_ip.h socket_tcp_listen.h \
-        time_accumulator.h time_out.h buffered_datagramreader.h socket_address.h \
+        buffered_datagramconnection.h \
+	ringbuffer.h ringbuffer.i socket_ip.h socket_tcp_listen.h \
+        time_accumulator.h time_out.h \
+	buffered_datagramreader.h buffered_datagramreader.i \
+	socket_address.h \
         socket_portable.h time_base.h time_span.h buffered_datagramwriter.h \
         socket_portable.h time_base.h time_span.h buffered_datagramwriter.h \
         socket_base.h socket_selector.h socket_udp_incoming.h time_clock.h \
         socket_base.h socket_selector.h socket_udp_incoming.h time_clock.h \
-        membuffer.h socket_fdset.h socket_tcp.h socket_udp_outgoing.h time_general.h
+        membuffer.h membuffer.i socket_fdset.h socket_tcp.h \
+	socket_udp_outgoing.h time_general.h
 
 
 
 
   #define IGATESCAN all
   #define IGATESCAN all

+ 48 - 54
panda/src/nativenet/buffered_datagramconnection.h

@@ -69,11 +69,11 @@ protected:
 public:
 public:
   inline bool GetMessageInternal(Datagram **val);
   inline bool GetMessageInternal(Datagram **val);
 PUBLISHED:
 PUBLISHED:
-  
+  inline bool IsConnected(void) { return DoConnect(); };
   inline Buffered_DatagramConnection(bool do_blocking_writes, int rbufsize, int wbufsize, int write_flush_point) ;
   inline Buffered_DatagramConnection(bool do_blocking_writes, int rbufsize, int wbufsize, int write_flush_point) ;
   virtual ~Buffered_DatagramConnection(void) ;
   virtual ~Buffered_DatagramConnection(void) ;
   // the reason thsi all exists
   // the reason thsi all exists
-  inline bool SendMessage(Datagram &msg);
+  inline bool SendMessage(const Datagram &msg);
   
   
   inline Datagram * GetMessage();
   inline Datagram * GetMessage();
   inline bool Flush(void);
   inline bool Flush(void);
@@ -87,9 +87,9 @@ private:
   Buffered_DatagramWriter	_Writer;		// buffered writing
   Buffered_DatagramWriter	_Writer;		// buffered writing
   Buffered_DatagramReader _Reader;		// buffered reader
   Buffered_DatagramReader _Reader;		// buffered reader
   AddressQueue            _Addresslist;   // the location of the round robin address list
   AddressQueue            _Addresslist;   // the location of the round robin address list
-  Socket_Address			_Adddress;	// the conection address ( active one from list being used)
+  Socket_Address          _Adddress;	// the conection address ( active one from list being used)
   // the local datagram store..
   // the local datagram store..
-  Datagram	    		_Msg;			// The temp storage for a upcalled message
+  Datagram	    	  _Msg;			// The temp storage for a upcalled message
   ////////////////////////////////
   ////////////////////////////////
   // connection state engine /////
   // connection state engine /////
   Time_Out                _LastConnectTry; // A Recycle Timer to Stop Connection/spaming.. 
   Time_Out                _LastConnectTry; // A Recycle Timer to Stop Connection/spaming.. 
@@ -109,13 +109,13 @@ private:
 // Return type		: inline void 
 // Return type		: inline void 
 // Argument         : void
 // Argument         : void
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-inline void Buffered_DatagramConnection::ClearAll(void)
-{
-	Close();
-    _tryingToOpen = false;
-	_Writer.ReSet();
-	_Reader.ReSet();
+inline void Buffered_DatagramConnection::ClearAll(void) {
+  Close();
+  _tryingToOpen = false;
+  _Writer.ReSet();
+  _Reader.ReSet();
 }	
 }	
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 // Function name	: Buffered_DatagramConnection::DoConnect
 // Function name	: Buffered_DatagramConnection::DoConnect
 // Description	    : This is the function thah does the conection for us
 // Description	    : This is the function thah does the conection for us
@@ -123,49 +123,43 @@ inline void Buffered_DatagramConnection::ClearAll(void)
 // Return type		: inline bool 
 // Return type		: inline bool 
 // Argument         : void
 // Argument         : void
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-inline bool Buffered_DatagramConnection::DoConnect(void)
-{
-	if(Active() != true)
-	{ 
-        if(_LastConnectTry.Expired() != true)
-            return false;
-
-        if(!_Addresslist.GetNext(_Adddress)) // lookup the proper value...
-            return false;
-
-		if(ActiveOpenNonBlocking(_Adddress) == true)
-		{
-             _LastConnectTry.ReStart();
-            _tryingToOpen = true; // set the flag indicating we are trying to open up 
-			SetNonBlocking(); // maybe should be blocking?
-			SetSendBufferSize(1024*50);  // we need to hand tune these for the os we are using
-			SetRecvBufferSize(1024*50);
-            NewWriteBuffer();
-			return true;
-		}
-
-		return false;
-	}
-
-    if(_tryingToOpen)  // okay handle the  i am connecting state....
-    {
-        Socket_fdset  fdset;
-        fdset.setForSocket(*this);
-        Socket_Selector  selector;
-        if(selector.WaitFor_All(fdset,0) >0)
-        {
-            _tryingToOpen = false;
-            if(selector._error.IsSetFor(*this) == true) // means we are in errorconnected. else writable
-            {
-                ClearAll();
-                return false;  // error on connect 
-            }
-            PostConnect();
-            return true;  // just got connected
-        }
-        return true; // still connecting
-    }    
-	return true;
+inline bool Buffered_DatagramConnection::DoConnect(void) {
+  if(Active() != true) { 
+    if(_LastConnectTry.Expired() != true)
+      return false;
+    
+    if(!_Addresslist.GetNext(_Adddress)) // lookup the proper value...
+      return false;
+    
+    if(ActiveOpen(_Adddress) == true) {
+      _LastConnectTry.ReStart();
+      _tryingToOpen = true; // set the flag indicating we are trying to open up 
+      SetNonBlocking(); // maybe should be blocking?
+      SetSendBufferSize(1024*50);  // we need to hand tune these for the os we are using
+      SetRecvBufferSize(1024*50);
+      NewWriteBuffer();
+      return true;
+    }
+      
+    return false;
+  }
+  
+  if(_tryingToOpen) {  // okay handle the  i am connecting state....
+    Socket_fdset  fdset;
+    fdset.setForSocket(*this);
+    Socket_Selector  selector;
+    if(selector.WaitFor_All(fdset,0) >0) {
+      _tryingToOpen = false;
+      if(selector._error.IsSetFor(*this) == true) { // means we are in errorconnected. else writable
+        ClearAll();
+        return false;  // error on connect 
+      }
+      PostConnect();
+      return true;  // just got connected
+    }
+    return true; // still connecting
+  }    
+  return true;
 }
 }
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 // Function name	: Buffered_DatagramConnection::~Buffered_DatagramConnection
 // Function name	: Buffered_DatagramConnection::~Buffered_DatagramConnection
@@ -199,7 +193,7 @@ inline Buffered_DatagramConnection::Buffered_DatagramConnection(bool do_blocking
 // Return type		: inline bool 
 // Return type		: inline bool 
 // Argument         : DataGram &msg
 // Argument         : DataGram &msg
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-inline bool  Buffered_DatagramConnection::SendMessage(Datagram &msg)
+inline bool  Buffered_DatagramConnection::SendMessage(const Datagram &msg)
 {
 {
 	if(DoConnect() == true)
 	if(DoConnect() == true)
 	{	
 	{	

+ 154 - 168
panda/src/nativenet/buffered_datagramwriter.h

@@ -1,168 +1,154 @@
-#ifndef __BufferedWriter_H__
-#define __BufferedWriter_H__
-
-#include "ringbuffer.h"
-////////////////////////////////////////////////////////////////////
-// 	 Class : Buffered_DatagramWriter
-// Description : This is the buffered writer.. it is used to buffer up
-//				 Coremessages and arbitrary data.. 
-//
-//				GmCoreMessage
-//				 
-//
-//				You must commit all rights to a socket with flush and 
-//				flush may be called internall if the buffersize is about
-//				to overrun.. This class does guaranty no partial message 
-//				rights at least to the TCP layer..
-//
-////////////////////////////////////////////////////////////////////
-class   Buffered_DatagramWriter  :  public RingBuffer
-{
-	bool	_are_we_going_to_block_on_write;
-	int		_flush_point;
-public:
-	inline void ReSet(void);			// destroy all buffered data
-
-	Buffered_DatagramWriter(bool  do_blocking, size_t in_size , int in_flush_point = -1);
-	inline int AddData(const void * data, size_t len, Socket_TCP &sck);
-	inline int AddData(const void * data, size_t len);
-// THE FUNCTIONS THAT TAKE A SOCKET NEED TO BE TEMPLATED TO WORK..
-
-    template < class SOCK_TYPE>
-    int  FlushNoBlock(SOCK_TYPE &sck)  // this is the ugly part
-    {	
-        int answer = 0;	
-        size_t Writesize = AmountBuffered();
-
-        if(Writesize > 0)
-        {
-            int Writen = sck.SendData(GetMessageHead(),(int)Writesize);
-            if(Writen > 0)
-            {
-                _StartPos += Writen;
-                FullCompress();
-                if(AmountBuffered() > 0) // send 0 if empty else send 1 for more to do
-                    answer = 1;
-            }
-            else if(Writen < 0)
-            {
-                if(!sck.ErrorIs_WouldBlocking(Writen))
-                    answer = -1;
-                else
-                    answer = 1;  // 1 = more to do.....
-            }
-        }		
-        return answer;
-    };
-
-
-    template < class SOCK_TYPE>
-        inline int  Flush(SOCK_TYPE &sck)  
-    {	
-        int answer = 0;	
-        size_t Writesize = AmountBuffered();
-
-        if(Writesize > 0)
-        {
-            int Writen = sck.SendData(GetMessageHead(),(int)Writesize);
-            if(_are_we_going_to_block_on_write == true && Writen < 0 && sck.ErrorIs_WouldBlocking(Writen) == TRUE)
-            {
-                //sck.SetBlocking();
-                Writen = sck.SendData(GetMessageHead(),(int)Writesize);		
-                //sck.SetNonBlocking();
-            }
-
-
-            if(Writen > 0)
-            {
-                _StartPos += Writen;
-                FullCompress();
-                if(AmountBuffered() > 0) // send 0 if empty else send 1 for more to do
-                    answer = 1;
-            }
-            else if(Writen < 0)
-            {
-                if(sck.ErrorIs_WouldBlocking(Writen) != TRUE)
-                    answer = -1;
-            }
-        }		
-
-        return answer;
-    };
-};
-
-///////////////////////////////////////////////////////
-// Function name	: Buffered_DatagramWriter::ReSet
-// Description	    : used to clear the buffrers ...
-//                    use of this in mid stream is a very bad thing as 
-//                    you can not guarany network writes are message alligned
-// Return type		: void 
-///////////////////////////////////////////////////////
-inline void Buffered_DatagramWriter::ReSet(void)		
-{
-	ResetContent();
-}
-////////////////////////////////////////////////
-//  Buffered_DatagramWriter::Buffered_DatagramWriter
-//
-//
-////////////////////////////////////////////////
-inline Buffered_DatagramWriter::Buffered_DatagramWriter(bool  do_blocking, size_t in_size , int in_flush_point) : RingBuffer(in_size)
-{	
-	_flush_point = in_flush_point;
-	_are_we_going_to_block_on_write = do_blocking;
-}
-
-//////////////////////////////////////////////////////////////
-// Function name	: Buffered_DatagramWriter::AddData
-// Description	    : 
-// Return type		: inline int 
-// Argument         : const void * data
-// Argument         : int len
-// Argument         : Socket_TCP &sck
-//////////////////////////////////////////////////////////////
-inline int Buffered_DatagramWriter::AddData(const void * data, size_t len, Socket_TCP &sck)
-{	
-	int answer = 0;
-	
-	if(len >  BufferAvailabe())
-		answer = Flush(sck);
-	
-	if(answer >= 0)
-		answer = AddData(data,len);
-	
-	if(answer >= 0 && _flush_point != -1)
-		if(_flush_point <  (int)AmountBuffered())
-			if(Flush(sck) < 0)
-				answer = -1;
-			
-    return answer;
-}
-//////////////////////////////////////////////////////////////
-// Function name	: Buffered_DatagramWriter::AddData
-// Description	    : 
-// Return type		: inline int 
-// Argument         : const char * data
-// Argument         : int len
-//////////////////////////////////////////////////////////////
-inline int Buffered_DatagramWriter::AddData(const void * data, size_t len)
-{
-	int answer = -1;
-    if(BufferAvailabe() > len+2)
-    {
-        unsigned short len1(len);
-        TS_GetInteger(len1,(char *)&len1);
-        if(Put((char *)&len1,sizeof(len1)) == true)
-        {
-            if(Put((char *)data,len) == true)
-            {
-                answer = 1;
-            }
-        }
-    }
-
-
-	return answer;
-}
-#endif //__BufferedWriter_H__
-
+#ifndef __BufferedWriter_H__
+#define __BufferedWriter_H__
+
+#include "ringbuffer.h"
+////////////////////////////////////////////////////////////////////
+// 	 Class : Buffered_DatagramWriter
+// Description : This is the buffered writer.. it is used to buffer up
+//				 Coremessages and arbitrary data.. 
+//
+//				GmCoreMessage
+//				 
+//
+//				You must commit all rights to a socket with flush and 
+//				flush may be called internall if the buffersize is about
+//				to overrun.. This class does guaranty no partial message 
+//				rights at least to the TCP layer..
+//
+////////////////////////////////////////////////////////////////////
+class   Buffered_DatagramWriter  :  public RingBuffer
+{
+	bool	_are_we_going_to_block_on_write;
+	int		_flush_point;
+public:
+	inline void ReSet(void);			// destroy all buffered data
+
+	Buffered_DatagramWriter(bool  do_blocking, size_t in_size , int in_flush_point = -1);
+	inline int AddData(const void * data, size_t len, Socket_TCP &sck);
+	inline int AddData(const void * data, size_t len);
+// THE FUNCTIONS THAT TAKE A SOCKET NEED TO BE TEMPLATED TO WORK..
+  
+        template < class SOCK_TYPE>
+        int  FlushNoBlock(SOCK_TYPE &sck) {  // this is the ugly part
+    
+          int answer = 0;	
+          size_t Writesize = AmountBuffered();
+
+          if(Writesize > 0) {
+            int Writen = sck.SendData(GetMessageHead(),(int)Writesize);
+            if(Writen > 0) {
+              _StartPos += Writen;
+              FullCompress();
+              if(AmountBuffered() > 0) // send 0 if empty else send 1 for more to do
+                answer = 1;
+            }
+            else if(Writen < 0) {
+              if(!sck.ErrorIs_WouldBlocking(Writen))
+                answer = -1;
+              else
+                answer = 1;  // 1 = more to do.....
+            }
+          }		
+          return answer;
+        };
+
+
+        template < class SOCK_TYPE>
+        inline int  Flush(SOCK_TYPE &sck) {	
+          int answer = 0;	
+          size_t Writesize = AmountBuffered();
+          
+          if(Writesize > 0) {
+            int Writen = sck.SendData(GetMessageHead(),(int)Writesize);
+            if(_are_we_going_to_block_on_write == true && Writen < 0 && sck.ErrorIs_WouldBlocking(Writen) == TRUE) {
+              //sck.SetBlocking();
+              Writen = sck.SendData(GetMessageHead(),(int)Writesize);		
+              //sck.SetNonBlocking();
+            }
+
+            
+            if(Writen > 0) {
+              _StartPos += Writen;
+              FullCompress();
+              if(AmountBuffered() > 0) //send 0 if empty else send 1 for more to do
+                answer = 1;
+            }
+            else if(Writen < 0) {
+              if(sck.ErrorIs_WouldBlocking(Writen) != TRUE)
+                answer = -1;
+            }
+          }		
+      
+          return answer;
+        };
+};
+
+///////////////////////////////////////////////////////
+// Function name	: Buffered_DatagramWriter::ReSet
+// Description	    : used to clear the buffrers ...
+//                    use of this in mid stream is a very bad thing as 
+//                    you can not guarany network writes are message alligned
+// Return type		: void 
+///////////////////////////////////////////////////////
+inline void Buffered_DatagramWriter::ReSet(void) {
+  ResetContent();
+}
+////////////////////////////////////////////////
+//  Buffered_DatagramWriter::Buffered_DatagramWriter
+//
+//
+////////////////////////////////////////////////
+inline Buffered_DatagramWriter::Buffered_DatagramWriter(bool  do_blocking, size_t in_size , int in_flush_point) : RingBuffer(in_size) {	
+  _flush_point = in_flush_point;
+  _are_we_going_to_block_on_write = do_blocking;
+}
+
+//////////////////////////////////////////////////////////////
+// Function name	: Buffered_DatagramWriter::AddData
+// Description	    : 
+// Return type		: inline int 
+// Argument         : const void * data
+// Argument         : int len
+// Argument         : Socket_TCP &sck
+//////////////////////////////////////////////////////////////
+inline int Buffered_DatagramWriter::AddData(const void * data, size_t len, Socket_TCP &sck) {	
+  int answer = 0;
+  
+  if(len >  BufferAvailabe())
+    answer = Flush(sck);
+	
+  if(answer >= 0)
+    answer = AddData(data,len);
+  
+  if(answer >= 0 && _flush_point != -1)
+    if(_flush_point <  (int)AmountBuffered())
+      if(Flush(sck) < 0)
+        answer = -1;
+			
+  return answer;
+}
+
+//////////////////////////////////////////////////////////////
+// Function name	: Buffered_DatagramWriter::AddData
+// Description	    : 
+// Return type		: inline int 
+// Argument         : const char * data
+// Argument         : int len
+//////////////////////////////////////////////////////////////
+inline int Buffered_DatagramWriter::AddData(const void * data, size_t len)
+{
+  int answer = -1;
+  if(BufferAvailabe() > len+2) {
+    unsigned short len1(len);
+    TS_GetInteger(len1,(char *)&len1);
+    if(Put((char *)&len1,sizeof(len1)) == true) {
+      if(Put((char *)data,len) == true) {
+        answer = 1;
+      }
+    }
+  }
+
+  return answer;
+}
+#endif //__BufferedWriter_H__
+