llpacketack.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * @file llpacketack.h
  3. * @brief Reliable UDP helpers for the message system.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLPACKETACK_H
  33. #define LL_LLPACKETACK_H
  34. #include "llhost.h"
  35. class LLReliablePacketParams
  36. {
  37. public:
  38. LLReliablePacketParams()
  39. {
  40. clear();
  41. }
  42. ~LLReliablePacketParams() {}
  43. void clear()
  44. {
  45. mHost.invalidate();
  46. mRetries = 0;
  47. mPingBasedRetry = true;
  48. mTimeout = 0.f;
  49. mCallback = NULL;
  50. mCallbackData = NULL;
  51. mMessageName = NULL;
  52. }
  53. void set(const LLHost& host, S32 retries, bool ping_based_retry,
  54. F32 timeout, void (*callback)(void**, S32),
  55. void** callback_data, char* name)
  56. {
  57. mHost = host;
  58. mRetries = retries;
  59. mPingBasedRetry = ping_based_retry;
  60. mTimeout = timeout;
  61. mCallback = callback;
  62. mCallbackData = callback_data;
  63. mMessageName = name;
  64. }
  65. public:
  66. LLHost mHost;
  67. S32 mRetries;
  68. F32 mTimeout;
  69. void (*mCallback)(void **, S32);
  70. void** mCallbackData;
  71. char* mMessageName;
  72. bool mPingBasedRetry;
  73. };
  74. class LLReliablePacket
  75. {
  76. friend class LLCircuitData;
  77. public:
  78. LLReliablePacket(S32 socket, U8* buf_ptr, S32 buf_len,
  79. LLReliablePacketParams* params);
  80. ~LLReliablePacket()
  81. {
  82. mCallback = NULL;
  83. delete[] mBuffer;
  84. mBuffer = NULL;
  85. }
  86. protected:
  87. S32 mSocket;
  88. LLHost mHost;
  89. S32 mRetries;
  90. F32 mTimeout;
  91. void (*mCallback)(void**, S32);
  92. void** mCallbackData;
  93. char* mMessageName;
  94. U8* mBuffer;
  95. S32 mBufferLength;
  96. TPACKETID mPacketID;
  97. F64 mExpirationTime;
  98. bool mPingBasedRetry;
  99. };
  100. #endif