PacketizedTCP.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \file
  11. /// \brief A simple TCP based server allowing sends and receives. Can be connected by any TCP client, including telnet.
  12. ///
  13. #include "NativeFeatureIncludes.h"
  14. #if _RAKNET_SUPPORT_PacketizedTCP==1 && _RAKNET_SUPPORT_TCPInterface==1
  15. #ifndef __PACKETIZED_TCP
  16. #define __PACKETIZED_TCP
  17. #include "TCPInterface.h"
  18. #include "DS_ByteQueue.h"
  19. #include "DS_Map.h"
  20. namespace RakNet
  21. {
  22. class RAK_DLL_EXPORT PacketizedTCP : public TCPInterface
  23. {
  24. public:
  25. // GetInstance() and DestroyInstance(instance*)
  26. STATIC_FACTORY_DECLARATIONS(PacketizedTCP)
  27. PacketizedTCP();
  28. virtual ~PacketizedTCP();
  29. /// Stops the TCP server
  30. void Stop(void);
  31. /// Sends a byte stream
  32. void Send( const char *data, unsigned length, const SystemAddress &systemAddress, bool broadcast );
  33. // Sends a concatenated list of byte streams
  34. bool SendList( const char **data, const unsigned int *lengths, const int numParameters, const SystemAddress &systemAddress, bool broadcast );
  35. /// Returns data received
  36. Packet* Receive( void );
  37. /// Disconnects a player/address
  38. void CloseConnection( SystemAddress systemAddress );
  39. /// Has a previous call to connect succeeded?
  40. /// \return UNASSIGNED_SYSTEM_ADDRESS = no. Anything else means yes.
  41. SystemAddress HasCompletedConnectionAttempt(void);
  42. /// Has a previous call to connect failed?
  43. /// \return UNASSIGNED_SYSTEM_ADDRESS = no. Anything else means yes.
  44. SystemAddress HasFailedConnectionAttempt(void);
  45. /// Queued events of new incoming connections
  46. SystemAddress HasNewIncomingConnection(void);
  47. /// Queued events of lost connections
  48. SystemAddress HasLostConnection(void);
  49. protected:
  50. void ClearAllConnections(void);
  51. void RemoveFromConnectionList(const SystemAddress &sa);
  52. void AddToConnectionList(const SystemAddress &sa);
  53. void PushNotificationsToQueues(void);
  54. Packet *ReturnOutgoingPacket(void);
  55. // A single TCP recieve may generate multiple split packets. They are stored in the waitingPackets list until Receive is called
  56. DataStructures::Queue<Packet*> waitingPackets;
  57. DataStructures::Map<SystemAddress, DataStructures::ByteQueue *> connections;
  58. // Mirrors single producer / consumer, but processes them in Receive() before returning to user
  59. DataStructures::Queue<SystemAddress> _newIncomingConnections, _lostConnections, _failedConnectionAttempts, _completedConnectionAttempts;
  60. };
  61. } // namespace RakNet
  62. #endif
  63. #endif // _RAKNET_SUPPORT_*
粤ICP备19079148号