15 #ifndef __BUFFERED_DATAGRAM_CONNECTION_H__ 16 #define __BUFFERED_DATAGRAM_CONNECTION_H__ 25 #include "socket_base.h" 28 #include "buffered_datagramreader.h" 29 #include "buffered_datagramwriter.h" 38 struct AddressQueue :
private pvector<Socket_Address>
42 INLINE AddressQueue() : _active_index(0) {}
45 size_t the_size = size();
50 if (_active_index >= the_size) {
54 out = (*this)[_active_index++];
64 for(ii = begin(); ii != end(); ii++)
75 virtual void PostConnect(
void) { };
76 virtual void NewWriteBuffer(
void) { };
78 inline void ClearAll(
void);
80 inline bool SendMessageBufferOnly(
Datagram &msg);
82 inline bool GetMessage(
Datagram &val);
83 inline bool DoConnect(
void);
84 inline bool IsConnected(
void);
88 bool SendMessage(
const Datagram &msg);
89 inline bool Flush(
void);
90 inline void Reset(
void);
95 inline void WaitForNetworkReadEvent(PN_stdfloat MaxTime)
98 fdset.setForSocket(*
this);
105 inline size_t AddressQueueSize() {
return _Addresslist.size(); };
107 inline void ClearAddresses(
void);
111 AddressQueue _Addresslist;
121 static void init_type() {
122 Socket_IP::init_type();
124 Socket_IP::get_class_type());
127 return get_class_type();
129 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
138 inline void Buffered_DatagramConnection::ClearAll(
void) {
139 nativenet_cat.error() <<
"Buffered_DatagramConnection::ClearAll Starting Auto Reset\n";
145 inline bool Buffered_DatagramConnection::DoConnect(
void) {
146 if(!_Addresslist.GetNext(_Adddress))
215 inline Buffered_DatagramConnection::Buffered_DatagramConnection(
int rbufsize,
int wbufsize,
int write_flush_point)
216 : _Writer(wbufsize,write_flush_point) , _Reader(rbufsize)
218 nativenet_cat.error() <<
"Buffered_DatagramConnection Constructor rbufsize = " << rbufsize
219 <<
" wbufsize = " << wbufsize <<
" write_flush_point = " << write_flush_point <<
"\n";
222 inline bool Buffered_DatagramConnection::SendMessageBufferOnly(
Datagram &msg)
228 nativenet_cat.error() <<
"Buffered_DatagramConnection::SendMessageBufferOnly->Error On Write--Out Buffer = " << _Writer.
AmountBuffered() <<
"\n";
238 _Addresslist.push_back(inadr);
241 inline void Buffered_DatagramConnection::ClearAddresses(
void)
243 _Addresslist.clear();
252 int ans1 = _Reader.PumpMessageReader(val,*
this);
256 nativenet_cat.error() <<
"Buffered_DatagramConnection::GetMessage->Error On PumpMessageReader--Out Buffer = " << _Writer.
AmountBuffered() <<
"\n";
274 int flush_resp = _Writer.FlushNoBlock(*
this);
277 nativenet_cat.error() <<
"Buffered_DatagramConnection::Flush->Error On Flush [" <<
GetLastError() <<
"]\n" 279 <<
"Buffered_DatagramConnection::Flush->Error ..Write--Out Buffer = " << _Writer.
AmountBuffered() <<
"\n";
292 nativenet_cat.error() <<
"Buffered_DatagramConnection::Reset()\n";
296 inline bool Buffered_DatagramConnection::IsConnected(
void) {
297 return (
Active() ==
true);
300 #endif //__BUFFERED_DATAGRAM_CONNECTION_H__ void AddAddress(Socket_Address &inadr)
must be called to set value to the server
Base functionality for a TCP connected socket This class is pretty useless by itself but it does hide...
int SetNonBlocking()
this function will throw a socket into non-blocking mode
void ReSet(void)
Reset all read content, ie.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool Active()
Ask if the socket is open (allocated)
bool Flush(void)
Flush all writes.
This is our own Panda specialization on the default STL vector.
bool GetMessage(Datagram &val)
Reads a message.
size_t AmountBuffered(void)
Will report the number of unread chars in buffer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A simple place to store and manipulate tcp and port address for communication layer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static int GetLastError()
Gets the last errcode from a socket operation.
void Close()
Closes a socket if it is open (allocated).
This is the buffered writer.
virtual ~Buffered_DatagramConnection(void)
This is the function that does the connection for us.
TypeHandle is the identifier used to differentiate C++ class types.
int WaitFor_Read_Error(const Socket_fdset &fd, const Time_Span &timeout)
Helper function for WaitFor Only looks for readability and errors.
bool ActiveOpen(const Socket_Address &theaddress, bool setdelay)
This function will try and set the socket up for active open to a specified address and port provided...
void ReSet(void)
used to clear the buffrers ...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
int SetNoDelay(bool flag=true)
Disable Nagle algorithm.
size_t get_length() const
Returns the number of bytes in the datagram.
const void * get_data() const
Returns a pointer to the beginning of the datagram's data.