PageRenderTime 27ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/llxfer_mem.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 218 lines | 121 code | 59 blank | 38 comment | 5 complexity | 1115708c88c47ae5192d3dda28834d6a MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llxfer_mem.cpp
  3. * @brief implementation of LLXfer_Mem class for a single xfer
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "llxfer_mem.h"
  28. #include "lluuid.h"
  29. #include "llerror.h"
  30. #include "llmath.h"
  31. ///////////////////////////////////////////////////////////
  32. LLXfer_Mem::LLXfer_Mem ()
  33. : LLXfer(-1)
  34. {
  35. init();
  36. }
  37. ///////////////////////////////////////////////////////////
  38. LLXfer_Mem::~LLXfer_Mem ()
  39. {
  40. cleanup();
  41. }
  42. ///////////////////////////////////////////////////////////
  43. void LLXfer_Mem::init ()
  44. {
  45. mRemoteFilename.clear();
  46. mRemotePath = LL_PATH_NONE;
  47. mDeleteRemoteOnCompletion = FALSE;
  48. }
  49. ///////////////////////////////////////////////////////////
  50. void LLXfer_Mem::cleanup ()
  51. {
  52. LLXfer::cleanup();
  53. }
  54. ///////////////////////////////////////////////////////////
  55. void LLXfer_Mem::setXferSize (S32 xfer_size)
  56. {
  57. mXferSize = xfer_size;
  58. delete[] mBuffer;
  59. mBuffer = new char[xfer_size];
  60. mBufferLength = 0;
  61. mBufferStartOffset = 0;
  62. mBufferContainsEOF = TRUE;
  63. // cout << "starting transfer of size: " << xfer_size << endl;
  64. }
  65. ///////////////////////////////////////////////////////////
  66. U64 LLXfer_Mem::registerXfer(U64 xfer_id, const void *datap, const S32 length)
  67. {
  68. mID = xfer_id;
  69. if (datap)
  70. {
  71. setXferSize(length);
  72. if (mBuffer)
  73. {
  74. memcpy(mBuffer,datap,length); /* Flawfinder : ignore */
  75. mBufferLength = length;
  76. }
  77. else
  78. {
  79. xfer_id = 0;
  80. }
  81. }
  82. mStatus = e_LL_XFER_REGISTERED;
  83. return (xfer_id);
  84. }
  85. S32 LLXfer_Mem::startSend (U64 xfer_id, const LLHost &remote_host)
  86. {
  87. S32 retval = LL_ERR_NOERR; // presume success
  88. if (mXferSize <= 0)
  89. {
  90. return LL_ERR_FILE_EMPTY;
  91. }
  92. mRemoteHost = remote_host;
  93. mID = xfer_id;
  94. mPacketNum = -1;
  95. // cout << "Sending file: " << getFileName() << endl;
  96. mStatus = e_LL_XFER_PENDING;
  97. return (retval);
  98. }
  99. ///////////////////////////////////////////////////////////
  100. S32 LLXfer_Mem::processEOF()
  101. {
  102. S32 retval = 0;
  103. mStatus = e_LL_XFER_COMPLETE;
  104. llinfos << "xfer complete: " << getFileName() << llendl;
  105. if (mCallback)
  106. {
  107. mCallback((void *)mBuffer,mBufferLength,mCallbackDataHandle,mCallbackResult,LL_EXSTAT_NONE);
  108. }
  109. return(retval);
  110. }
  111. ///////////////////////////////////////////////////////////
  112. S32 LLXfer_Mem::initializeRequest(U64 xfer_id,
  113. const std::string& remote_filename,
  114. ELLPath remote_path,
  115. const LLHost& remote_host,
  116. BOOL delete_remote_on_completion,
  117. void (*callback)(void*,S32,void**,S32,LLExtStat),
  118. void** user_data)
  119. {
  120. S32 retval = 0; // presume success
  121. mRemoteHost = remote_host;
  122. // create a temp filename string using a GUID
  123. mID = xfer_id;
  124. mCallback = callback;
  125. mCallbackDataHandle = user_data;
  126. mCallbackResult = LL_ERR_NOERR;
  127. mRemoteFilename = remote_filename;
  128. mRemotePath = remote_path;
  129. mDeleteRemoteOnCompletion = delete_remote_on_completion;
  130. llinfos << "Requesting file: " << remote_filename << llendl;
  131. delete [] mBuffer;
  132. mBuffer = NULL;
  133. mBufferLength = 0;
  134. mPacketNum = 0;
  135. mStatus = e_LL_XFER_PENDING;
  136. return retval;
  137. }
  138. //////////////////////////////////////////////////////////
  139. S32 LLXfer_Mem::startDownload()
  140. {
  141. S32 retval = 0; // presume success
  142. gMessageSystem->newMessageFast(_PREHASH_RequestXfer);
  143. gMessageSystem->nextBlockFast(_PREHASH_XferID);
  144. gMessageSystem->addU64Fast(_PREHASH_ID, mID);
  145. gMessageSystem->addStringFast(_PREHASH_Filename, mRemoteFilename);
  146. gMessageSystem->addU8("FilePath", (U8) mRemotePath);
  147. gMessageSystem->addBOOL("DeleteOnCompletion", mDeleteRemoteOnCompletion);
  148. gMessageSystem->addBOOL("UseBigPackets", BOOL(mChunkSize == LL_XFER_LARGE_PAYLOAD));
  149. gMessageSystem->addUUIDFast(_PREHASH_VFileID, LLUUID::null);
  150. gMessageSystem->addS16Fast(_PREHASH_VFileType, -1);
  151. gMessageSystem->sendReliable(mRemoteHost);
  152. mStatus = e_LL_XFER_IN_PROGRESS;
  153. return (retval);
  154. }
  155. //////////////////////////////////////////////////////////
  156. U32 LLXfer_Mem::getXferTypeTag()
  157. {
  158. return LLXfer::XFER_MEM;
  159. }