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();}
138inline void Buffered_DatagramConnection::ClearAll(
void) {
139 if (nativenet_cat.is_debug()) {
140 nativenet_cat.debug()
141 <<
"Buffered_DatagramConnection::ClearAll Starting Auto Reset\n";
148inline bool Buffered_DatagramConnection::DoConnect(
void) {
149 if(!_Addresslist.GetNext(_Adddress))
218inline Buffered_DatagramConnection::Buffered_DatagramConnection(
int rbufsize,
int wbufsize,
int write_flush_point)
219 : _Writer(wbufsize,write_flush_point) , _Reader(rbufsize)
221 if (nativenet_cat.is_debug()) {
222 nativenet_cat.debug()
223 <<
"Buffered_DatagramConnection Constructor rbufsize = " << rbufsize
224 <<
" wbufsize = " << wbufsize <<
" write_flush_point = " << write_flush_point <<
"\n";
228inline bool Buffered_DatagramConnection::SendMessageBufferOnly(
Datagram &msg)
234 nativenet_cat.error() <<
"Buffered_DatagramConnection::SendMessageBufferOnly->Error On Write--Out Buffer = " << _Writer.
AmountBuffered() <<
"\n";
244 _Addresslist.push_back(inadr);
247inline void Buffered_DatagramConnection::ClearAddresses(
void)
249 _Addresslist.clear();
258 int ans1 = _Reader.PumpMessageReader(val,*
this);
262 nativenet_cat.error() <<
"Buffered_DatagramConnection::GetMessage->Error On PumpMessageReader--Out Buffer = " << _Writer.
AmountBuffered() <<
"\n";
280 int flush_resp = _Writer.FlushNoBlock(*
this);
283 nativenet_cat.error() <<
"Buffered_DatagramConnection::Flush->Error On Flush [" <<
GetLastError() <<
"]\n"
285 <<
"Buffered_DatagramConnection::Flush->Error ..Write--Out Buffer = " << _Writer.
AmountBuffered() <<
"\n";
298 if (nativenet_cat.is_debug()) {
299 nativenet_cat.debug() <<
"Buffered_DatagramConnection::Reset()\n";
304inline bool Buffered_DatagramConnection::IsConnected(
void) {
305 return (
Active() ==
true);
void AddAddress(Socket_Address &inadr)
must be called to set value to the server
bool Flush(void)
Flush all writes.
virtual ~Buffered_DatagramConnection(void)
This is the function that does the connection for us.
bool GetMessage(Datagram &val)
Reads a message.
void ReSet(void)
Reset all read content, ie.
This is the buffered writer.
void ReSet(void)
used to clear the buffrers ... use of this in mid stream is a very bad thing as you can not guarany n...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
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.
size_t AmountBuffered(void)
Will report the number of unread chars in buffer.
A simple place to store and manipulate tcp and port address for communication layer.
static int GetLastError()
Gets the last errcode from a socket operation.
void Close()
Closes a socket if it is open (allocated).
bool Active()
Ask if the socket is open (allocated)
int SetNonBlocking()
this function will throw a socket into non-blocking mode
Base functionality for a TCP connected socket This class is pretty useless by itself but it does hide...
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...
int SetNoDelay(bool flag=true)
Disable Nagle algorithm.
TypeHandle is the identifier used to differentiate C++ class types.
This is our own Panda specialization on the default STL vector.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
int WaitFor_Read_Error(const Socket_fdset &fd, const Time_Span &timeout)
Helper function for WaitFor Only looks for readability and errors.