llxfer.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * @file llxfer.h
  3. * @brief definition of LLXfer class for a single xfer
  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_LLXFER_H
  33. #define LL_LLXFER_H
  34. #include "llextendedstatus.h"
  35. #include "lltimer.h"
  36. #include "llmessage.h"
  37. // Size of chunks read from/written to disk
  38. constexpr U32 LL_MAX_XFER_FILE_BUFFER = 65536;
  39. constexpr S32 LL_XFER_LARGE_PAYLOAD = 7680;
  40. constexpr S32 LL_ERR_FILE_EMPTY = -44;
  41. constexpr int LL_ERR_FILE_NOT_FOUND = -43;
  42. constexpr int LL_ERR_CANNOT_OPEN_FILE = -42;
  43. constexpr int LL_ERR_EOF = -39;
  44. typedef enum ELLXferStatus {
  45. e_LL_XFER_UNINITIALIZED,
  46. e_LL_XFER_REGISTERED, // a buffer which has been registered as available for a request
  47. e_LL_XFER_PENDING, // a transfer which has been requested but is waiting for a free slot
  48. e_LL_XFER_IN_PROGRESS,
  49. e_LL_XFER_COMPLETE,
  50. e_LL_XFER_ABORTED,
  51. e_LL_XFER_NONE
  52. } ELLXferStatus;
  53. class LLXfer
  54. {
  55. protected:
  56. LOG_CLASS(LLXfer);
  57. public:
  58. LLXfer(S32 chunk_size);
  59. virtual ~LLXfer();
  60. void init(S32 chunk_size);
  61. virtual void cleanup();
  62. virtual S32 startSend(U64 xfer_id, const LLHost& remote_host);
  63. virtual void closeFileHandle();
  64. virtual S32 reopenFileHandle();
  65. virtual void sendPacket(S32 packet_num);
  66. virtual void sendNextPacket();
  67. virtual void resendLastPacket();
  68. virtual S32 processEOF();
  69. virtual S32 startDownload();
  70. virtual S32 receiveData(char* datap, S32 data_size);
  71. virtual void abort(S32);
  72. virtual S32 suck(S32 start_position);
  73. virtual S32 flush();
  74. virtual S32 encodePacketNum(S32 packet_num, bool is_eof);
  75. virtual void setXferSize(S32 data_size);
  76. virtual S32 getMaxBufferSize();
  77. virtual std::string getFileName();
  78. virtual U32 getXferTypeTag();
  79. friend std::ostream& operator<<(std::ostream& os, LLXfer& hh);
  80. public:
  81. static constexpr U32 XFER_FILE = 1;
  82. static constexpr U32 XFER_VFILE = 2;
  83. static constexpr U32 XFER_MEM = 3;
  84. U64 mID;
  85. S32 mPacketNum;
  86. LLHost mRemoteHost;
  87. S32 mXferSize;
  88. char* mBuffer;
  89. // Size of valid data, not actual allocated buffer size:
  90. U32 mBufferLength;
  91. U32 mBufferStartOffset;
  92. bool mBufferContainsEOF;
  93. ELLXferStatus mStatus;
  94. void (*mCallback)(void**, S32, LLExtStat);
  95. void** mCallbackDataHandle;
  96. S32 mCallbackResult;
  97. LLTimer ACKTimer;
  98. S32 mRetries;
  99. bool mWaitingForACK;
  100. protected:
  101. S32 mChunkSize;
  102. };
  103. #endif