recentConnectionReader.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Filename: recentConnectionReader.h
  2. // Created by: drose (23Jun00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef RECENTCONNECTIONREADER_H
  19. #define RECENTCONNECTIONREADER_H
  20. #include "pandabase.h"
  21. #include "connectionReader.h"
  22. #include "netDatagram.h"
  23. #include <prlock.h>
  24. ////////////////////////////////////////////////////////////////////
  25. // Class : RecentConnectionReader
  26. // Description : This flavor of ConnectionReader will read from its
  27. // sockets and retain only the single most recent
  28. // datagram for inspection by client code. It's useful
  29. // particularly for reading telemetry-type data from UDP
  30. // sockets where you don't care about getting every last
  31. // socket, and in fact if the sockets are coming too
  32. // fast you'd prefer to skip some of them.
  33. //
  34. // This class will always create one thread for itself.
  35. ////////////////////////////////////////////////////////////////////
  36. class EXPCL_PANDA RecentConnectionReader : public ConnectionReader {
  37. PUBLISHED:
  38. RecentConnectionReader(ConnectionManager *manager);
  39. virtual ~RecentConnectionReader();
  40. bool data_available();
  41. bool get_data(NetDatagram &result);
  42. bool get_data(Datagram &result);
  43. protected:
  44. virtual void receive_datagram(const NetDatagram &datagram);
  45. private:
  46. bool _available;
  47. Datagram _datagram;
  48. PRLock *_mutex;
  49. };
  50. #endif