aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llassetstorage.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:50 -0500
committerJacek Antonelli2008-08-15 23:44:50 -0500
commit89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch)
treebcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/llmessage/llassetstorage.cpp
parentSecond Life viewer sources 1.13.3.2 (diff)
downloadmeta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.zip
meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.gz
meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.bz2
meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.xz
Second Life viewer sources 1.14.0.0
Diffstat (limited to 'linden/indra/llmessage/llassetstorage.cpp')
-rw-r--r--linden/indra/llmessage/llassetstorage.cpp318
1 files changed, 268 insertions, 50 deletions
diff --git a/linden/indra/llmessage/llassetstorage.cpp b/linden/indra/llmessage/llassetstorage.cpp
index eb26157..a8cd0e5 100644
--- a/linden/indra/llmessage/llassetstorage.cpp
+++ b/linden/indra/llmessage/llassetstorage.cpp
@@ -174,10 +174,40 @@ LLAssetRequest::LLAssetRequest(const LLUUID &uuid, const LLAssetType::EType type
174 mTime = LLMessageSystem::getMessageTimeSeconds(TRUE); 174 mTime = LLMessageSystem::getMessageTimeSeconds(TRUE);
175} 175}
176 176
177// virtual
177LLAssetRequest::~LLAssetRequest() 178LLAssetRequest::~LLAssetRequest()
178{ 179{
179} 180}
180 181
182// virtual
183LLSD LLAssetRequest::getTerseDetails() const
184{
185 LLSD sd;
186 sd["asset_id"] = getUUID();
187 sd["type_long"] = LLAssetType::lookupHumanReadable(getType());
188 sd["type"] = LLAssetType::lookup(getType());
189 sd["time"] = mTime;
190 time_t timestamp = (time_t) mTime;
191 std::ostringstream time_string;
192 time_string << ctime(&timestamp);
193 sd["time_string"] = time_string.str();
194 return sd;
195}
196
197// virtual
198LLSD LLAssetRequest::getFullDetails() const
199{
200 LLSD sd = getTerseDetails();
201 sd["host"] = mHost.getIPandPort();
202 sd["requesting_agent"] = mRequestingAgentID;
203 sd["is_temp"] = mIsTemp;
204 sd["is_local"] = mIsLocal;
205 sd["is_priority"] = mIsPriority;
206 sd["data_send_in_first_packet"] = mDataSentInFirstPacket;
207 sd["data_is_in_vfs"] = mDataIsInVFS;
208
209 return sd;
210}
181 211
182///---------------------------------------------------------------------------- 212///----------------------------------------------------------------------------
183/// LLInvItemRequest 213/// LLInvItemRequest
@@ -298,47 +328,41 @@ void LLAssetStorage::checkForTimeouts()
298 328
299void LLAssetStorage::_cleanupRequests(BOOL all, S32 error) 329void LLAssetStorage::_cleanupRequests(BOOL all, S32 error)
300{ 330{
301 const S32 NUM_QUEUES = 3;
302 F64 mt_secs = LLMessageSystem::getMessageTimeSeconds(); 331 F64 mt_secs = LLMessageSystem::getMessageTimeSeconds();
303 332
304 std::list<LLAssetRequest*>* requests[NUM_QUEUES]; 333 request_list_t timed_out;
305 requests[0] = &mPendingDownloads; 334 S32 rt;
306 requests[1] = &mPendingUploads; 335 for (rt = 0; rt < RT_COUNT; rt++)
307 requests[2] = &mPendingLocalUploads;
308 static const char* REQUEST_TYPE[NUM_QUEUES] = { "download", "upload", "localuploads"};
309
310 std::list<LLAssetRequest*> timed_out;
311
312 for (S32 ii = 0; ii < NUM_QUEUES; ++ii)
313 { 336 {
314 for (std::list<LLAssetRequest*>::iterator iter = requests[ii]->begin(); 337 request_list_t* requests = getRequestList((ERequestType)rt);
315 iter != requests[ii]->end(); ) 338 for (request_list_t::iterator iter = requests->begin();
339 iter != requests->end(); )
316 { 340 {
317 std::list<LLAssetRequest*>::iterator curiter = iter++; 341 request_list_t::iterator curiter = iter++;
318 LLAssetRequest* tmp = *curiter; 342 LLAssetRequest* tmp = *curiter;
319 // if all is true, we want to clean up everything 343 // if all is true, we want to clean up everything
320 // otherwise just check for timed out requests 344 // otherwise just check for timed out requests
321 // EXCEPT for upload timeouts 345 // EXCEPT for upload timeouts
322 if (all 346 if (all
323 || ((0 == ii) 347 || ((RT_DOWNLOAD == rt)
324 && LL_ASSET_STORAGE_TIMEOUT < (mt_secs - tmp->mTime))) 348 && LL_ASSET_STORAGE_TIMEOUT < (mt_secs - tmp->mTime)))
325 { 349 {
326 llwarns << "Asset " << REQUEST_TYPE[ii] << " request " 350 llwarns << "Asset " << getRequestName((ERequestType)rt) << " request "
327 << (all ? "aborted" : "timed out") << " for " 351 << (all ? "aborted" : "timed out") << " for "
328 << tmp->getUUID() << "." 352 << tmp->getUUID() << "."
329 << LLAssetType::lookup(tmp->getType()) << llendl; 353 << LLAssetType::lookup(tmp->getType()) << llendl;
330 354
331 timed_out.push_front(tmp); 355 timed_out.push_front(tmp);
332 iter = requests[ii]->erase(curiter); 356 iter = requests->erase(curiter);
333 } 357 }
334 } 358 }
335 } 359 }
336 360
337 LLAssetInfo info; 361 LLAssetInfo info;
338 for (std::list<LLAssetRequest*>::iterator iter = timed_out.begin(); 362 for (request_list_t::iterator iter = timed_out.begin();
339 iter != timed_out.end(); ) 363 iter != timed_out.end(); )
340 { 364 {
341 std::list<LLAssetRequest*>::iterator curiter = iter++; 365 request_list_t::iterator curiter = iter++;
342 LLAssetRequest* tmp = *curiter; 366 LLAssetRequest* tmp = *curiter;
343 if (tmp->mUpCallback) 367 if (tmp->mUpCallback)
344 { 368 {
@@ -401,7 +425,7 @@ void LLAssetStorage::getAssetData(const LLUUID uuid, LLAssetType::EType type, vo
401 BOOL duplicate = FALSE; 425 BOOL duplicate = FALSE;
402 426
403 // check to see if there's a pending download of this uuid already 427 // check to see if there's a pending download of this uuid already
404 for (std::list<LLAssetRequest*>::iterator iter = mPendingDownloads.begin(); 428 for (request_list_t::iterator iter = mPendingDownloads.begin();
405 iter != mPendingDownloads.end(); ++iter ) 429 iter != mPendingDownloads.end(); ++iter )
406 { 430 {
407 LLAssetRequest *tmp = *iter; 431 LLAssetRequest *tmp = *iter;
@@ -523,11 +547,11 @@ void LLAssetStorage::downloadCompleteCallback(
523 // find and callback ALL pending requests for this UUID 547 // find and callback ALL pending requests for this UUID
524 // SJB: We process the callbacks in reverse order, I do not know if this is important, 548 // SJB: We process the callbacks in reverse order, I do not know if this is important,
525 // but I didn't want to mess with it. 549 // but I didn't want to mess with it.
526 std::list<LLAssetRequest*> requests; 550 request_list_t requests;
527 for (std::list<LLAssetRequest*>::iterator iter = gAssetStorage->mPendingDownloads.begin(); 551 for (request_list_t::iterator iter = gAssetStorage->mPendingDownloads.begin();
528 iter != gAssetStorage->mPendingDownloads.end(); ) 552 iter != gAssetStorage->mPendingDownloads.end(); )
529 { 553 {
530 std::list<LLAssetRequest*>::iterator curiter = iter++; 554 request_list_t::iterator curiter = iter++;
531 LLAssetRequest* tmp = *curiter; 555 LLAssetRequest* tmp = *curiter;
532 if ((tmp->getUUID() == req->getUUID()) && (tmp->getType()== req->getType())) 556 if ((tmp->getUUID() == req->getUUID()) && (tmp->getType()== req->getType()))
533 { 557 {
@@ -535,10 +559,10 @@ void LLAssetStorage::downloadCompleteCallback(
535 iter = gAssetStorage->mPendingDownloads.erase(curiter); 559 iter = gAssetStorage->mPendingDownloads.erase(curiter);
536 } 560 }
537 } 561 }
538 for (std::list<LLAssetRequest*>::iterator iter = requests.begin(); 562 for (request_list_t::iterator iter = requests.begin();
539 iter != requests.end(); ) 563 iter != requests.end(); )
540 { 564 {
541 std::list<LLAssetRequest*>::iterator curiter = iter++; 565 request_list_t::iterator curiter = iter++;
542 LLAssetRequest* tmp = *curiter; 566 LLAssetRequest* tmp = *curiter;
543 if (tmp->mDownCallback) 567 if (tmp->mDownCallback)
544 { 568 {
@@ -896,11 +920,11 @@ void LLAssetStorage::_callUploadCallbacks(const LLUUID &uuid, LLAssetType::EType
896{ 920{
897 // SJB: We process the callbacks in reverse order, I do not know if this is important, 921 // SJB: We process the callbacks in reverse order, I do not know if this is important,
898 // but I didn't want to mess with it. 922 // but I didn't want to mess with it.
899 std::list<LLAssetRequest*> requests; 923 request_list_t requests;
900 for (std::list<LLAssetRequest*>::iterator iter = mPendingUploads.begin(); 924 for (request_list_t::iterator iter = mPendingUploads.begin();
901 iter != mPendingUploads.end(); ) 925 iter != mPendingUploads.end(); )
902 { 926 {
903 std::list<LLAssetRequest*>::iterator curiter = iter++; 927 request_list_t::iterator curiter = iter++;
904 LLAssetRequest* req = *curiter; 928 LLAssetRequest* req = *curiter;
905 if ((req->getUUID() == uuid) && (req->getType() == asset_type)) 929 if ((req->getUUID() == uuid) && (req->getType() == asset_type))
906 { 930 {
@@ -908,10 +932,10 @@ void LLAssetStorage::_callUploadCallbacks(const LLUUID &uuid, LLAssetType::EType
908 iter = mPendingUploads.erase(curiter); 932 iter = mPendingUploads.erase(curiter);
909 } 933 }
910 } 934 }
911 for (std::list<LLAssetRequest*>::iterator iter = mPendingLocalUploads.begin(); 935 for (request_list_t::iterator iter = mPendingLocalUploads.begin();
912 iter != mPendingLocalUploads.end(); ) 936 iter != mPendingLocalUploads.end(); )
913 { 937 {
914 std::list<LLAssetRequest*>::iterator curiter = iter++; 938 request_list_t::iterator curiter = iter++;
915 LLAssetRequest* req = *curiter; 939 LLAssetRequest* req = *curiter;
916 if ((req->getUUID() == uuid) && (req->getType() == asset_type)) 940 if ((req->getUUID() == uuid) && (req->getType() == asset_type))
917 { 941 {
@@ -919,10 +943,10 @@ void LLAssetStorage::_callUploadCallbacks(const LLUUID &uuid, LLAssetType::EType
919 iter = mPendingLocalUploads.erase(curiter); 943 iter = mPendingLocalUploads.erase(curiter);
920 } 944 }
921 } 945 }
922 for (std::list<LLAssetRequest*>::iterator iter = requests.begin(); 946 for (request_list_t::iterator iter = requests.begin();
923 iter != requests.end(); ) 947 iter != requests.end(); )
924 { 948 {
925 std::list<LLAssetRequest*>::iterator curiter = iter++; 949 request_list_t::iterator curiter = iter++;
926 LLAssetRequest* req = *curiter; 950 LLAssetRequest* req = *curiter;
927 if (req->mUpCallback) 951 if (req->mUpCallback)
928 { 952 {
@@ -932,45 +956,239 @@ void LLAssetStorage::_callUploadCallbacks(const LLUUID &uuid, LLAssetType::EType
932 } 956 }
933} 957}
934 958
959LLAssetStorage::request_list_t* LLAssetStorage::getRequestList(LLAssetStorage::ERequestType rt)
960{
961 switch (rt)
962 {
963 case RT_DOWNLOAD:
964 return &mPendingDownloads;
965 case RT_UPLOAD:
966 return &mPendingUploads;
967 case RT_LOCALUPLOAD:
968 return &mPendingLocalUploads;
969 default:
970 llwarns << "Unable to find request list for request type '" << rt << "'" << llendl;
971 return NULL;
972 }
973}
974
975const LLAssetStorage::request_list_t* LLAssetStorage::getRequestList(LLAssetStorage::ERequestType rt) const
976{
977 switch (rt)
978 {
979 case RT_DOWNLOAD:
980 return &mPendingDownloads;
981 case RT_UPLOAD:
982 return &mPendingUploads;
983 case RT_LOCALUPLOAD:
984 return &mPendingLocalUploads;
985 default:
986 llwarns << "Unable to find request list for request type '" << rt << "'" << llendl;
987 return NULL;
988 }
989}
990
991// static
992std::string LLAssetStorage::getRequestName(LLAssetStorage::ERequestType rt)
993{
994 switch (rt)
995 {
996 case RT_DOWNLOAD:
997 return "download";
998 case RT_UPLOAD:
999 return "upload";
1000 case RT_LOCALUPLOAD:
1001 return "localupload";
1002 default:
1003 llwarns << "Unable to find request name for request type '" << rt << "'" << llendl;
1004 return "";
1005 }
1006}
1007
1008S32 LLAssetStorage::getNumPending(LLAssetStorage::ERequestType rt) const
1009{
1010 const request_list_t* requests = getRequestList(rt);
1011 S32 num_pending = -1;
1012 if (requests)
1013 {
1014 num_pending = requests->size();
1015 }
1016 return num_pending;
1017}
935 1018
936S32 LLAssetStorage::getNumPendingDownloads() const 1019S32 LLAssetStorage::getNumPendingDownloads() const
937{ 1020{
938 return mPendingDownloads.size(); 1021 return getNumPending(RT_DOWNLOAD);
939} 1022}
940 1023
941S32 LLAssetStorage::getNumPendingUploads() const 1024S32 LLAssetStorage::getNumPendingUploads() const
942{ 1025{
943 return mPendingUploads.size(); 1026 return getNumPending(RT_UPLOAD);
944} 1027}
945 1028
946S32 LLAssetStorage::getNumPendingLocalUploads() 1029S32 LLAssetStorage::getNumPendingLocalUploads()
947{ 1030{
948 return mPendingLocalUploads.size(); 1031 return getNumPending(RT_LOCALUPLOAD);
1032}
1033
1034// virtual
1035LLSD LLAssetStorage::getPendingDetails(LLAssetStorage::ERequestType rt,
1036 LLAssetType::EType asset_type,
1037 const std::string& detail_prefix) const
1038{
1039 const request_list_t* requests = getRequestList(rt);
1040 LLSD sd;
1041 sd["requests"] = getPendingDetails(requests, asset_type, detail_prefix);
1042 return sd;
1043}
1044
1045// virtual
1046LLSD LLAssetStorage::getPendingDetails(const LLAssetStorage::request_list_t* requests,
1047 LLAssetType::EType asset_type,
1048 const std::string& detail_prefix) const
1049{
1050 LLSD details;
1051 if (requests)
1052 {
1053 request_list_t::const_iterator it = requests->begin();
1054 request_list_t::const_iterator end = requests->end();
1055 for ( ; it != end; ++it)
1056 {
1057 LLAssetRequest* req = *it;
1058 if ( (LLAssetType::AT_NONE == asset_type)
1059 || (req->getType() == asset_type) )
1060 {
1061 LLSD row = req->getTerseDetails();
1062
1063 std::ostringstream detail;
1064 detail << detail_prefix << "/" << LLAssetType::lookup(req->getType())
1065 << "/" << req->getUUID();
1066 row["detail"] = LLURI(detail.str());
1067
1068 details.append(row);
1069 }
1070 }
1071 }
1072 return details;
1073}
1074
1075
1076// static
1077const LLAssetRequest* LLAssetStorage::findRequest(const LLAssetStorage::request_list_t* requests,
1078 LLAssetType::EType asset_type,
1079 const LLUUID& asset_id)
1080{
1081 if (requests)
1082 {
1083 // Search the requests list for the asset.
1084 request_list_t::const_iterator iter = requests->begin();
1085 request_list_t::const_iterator end = requests->end();
1086 for (; iter != end; ++iter)
1087 {
1088 const LLAssetRequest* req = *iter;
1089 if (asset_type == req->getType() &&
1090 asset_id == req->getUUID() )
1091 {
1092 return req;
1093 }
1094 }
1095 }
1096 return NULL;
949} 1097}
950 1098
951LLSD LLAssetStorage::getPendingTypes(const std::list<LLAssetRequest*>& requests) const 1099// static
1100LLAssetRequest* LLAssetStorage::findRequest(LLAssetStorage::request_list_t* requests,
1101 LLAssetType::EType asset_type,
1102 const LLUUID& asset_id)
952{ 1103{
953 LLSD type_counts; 1104 if (requests)
954 std::list<LLAssetRequest*>::const_iterator it = requests.begin();
955 std::list<LLAssetRequest*>::const_iterator end = requests.end();
956 for ( ; it != end; ++it)
957 { 1105 {
958 LLAssetRequest* req = *it; 1106 // Search the requests list for the asset.
1107 request_list_t::iterator iter = requests->begin();
1108 request_list_t::iterator end = requests->end();
1109 for (; iter != end; ++iter)
1110 {
1111 LLAssetRequest* req = *iter;
1112 if (asset_type == req->getType() &&
1113 asset_id == req->getUUID() )
1114 {
1115 return req;
1116 }
1117 }
1118 }
1119 return NULL;
1120}
1121
959 1122
960 const char* type_name = LLAssetType::lookupHumanReadable(req->getType()); 1123// virtual
961 type_counts[type_name] = type_counts[type_name].asInteger() + 1; 1124LLSD LLAssetStorage::getPendingRequest(LLAssetStorage::ERequestType rt,
1125 LLAssetType::EType asset_type,
1126 const LLUUID& asset_id) const
1127{
1128 const request_list_t* requests = getRequestList(rt);
1129 return getPendingRequest(requests, asset_type, asset_id);
1130}
1131
1132// virtual
1133LLSD LLAssetStorage::getPendingRequest(const LLAssetStorage::request_list_t* requests,
1134 LLAssetType::EType asset_type,
1135 const LLUUID& asset_id) const
1136{
1137 LLSD sd;
1138 const LLAssetRequest* req = findRequest(requests, asset_type, asset_id);
1139 if (req)
1140 {
1141 sd = req->getFullDetails();
962 } 1142 }
963 return type_counts; 1143 return sd;
964} 1144}
965 1145
966LLSD LLAssetStorage::getPendingDownloadTypes() const 1146// virtual
1147bool LLAssetStorage::deletePendingRequest(LLAssetStorage::ERequestType rt,
1148 LLAssetType::EType asset_type,
1149 const LLUUID& asset_id)
967{ 1150{
968 return getPendingTypes(mPendingDownloads); 1151 request_list_t* requests = getRequestList(rt);
1152 if (deletePendingRequest(requests, asset_type, asset_id))
1153 {
1154 llinfos << "Asset " << getRequestName(rt) << " request for "
1155 << asset_id << "." << LLAssetType::lookup(asset_type)
1156 << " removed from pending queue." << llendl;
1157 return true;
1158 }
1159 return false;
969} 1160}
970 1161
971LLSD LLAssetStorage::getPendingUploadTypes() const 1162// virtual
1163bool LLAssetStorage::deletePendingRequest(LLAssetStorage::request_list_t* requests,
1164 LLAssetType::EType asset_type,
1165 const LLUUID& asset_id)
972{ 1166{
973 return getPendingTypes(mPendingUploads); 1167 LLAssetRequest* req = findRequest(requests, asset_type, asset_id);
1168 if (req)
1169 {
1170 // Remove the request from this list.
1171 requests->remove(req);
1172 S32 error = LL_ERR_TCP_TIMEOUT;
1173 // Run callbacks.
1174 if (req->mUpCallback)
1175 {
1176 req->mUpCallback(req->getUUID(), req->mUserData, error);
1177 }
1178 if (req->mDownCallback)
1179 {
1180 req->mDownCallback(mVFS, req->getUUID(), req->getType(), req->mUserData, error);
1181 }
1182 if (req->mInfoCallback)
1183 {
1184 LLAssetInfo info;
1185 req->mInfoCallback(&info, req->mUserData, error);
1186 }
1187 delete req;
1188 return true;
1189 }
1190
1191 return false;
974} 1192}
975 1193
976// static 1194// static
@@ -1015,7 +1233,7 @@ const char* LLAssetStorage::getErrorString(S32 status)
1015void LLAssetStorage::getAssetData(const LLUUID uuid, LLAssetType::EType type, void (*callback)(const char*, const LLUUID&, void *, S32), void *user_data, BOOL is_priority) 1233void LLAssetStorage::getAssetData(const LLUUID uuid, LLAssetType::EType type, void (*callback)(const char*, const LLUUID&, void *, S32), void *user_data, BOOL is_priority)
1016{ 1234{
1017 // check for duplicates here, since we're about to fool the normal duplicate checker 1235 // check for duplicates here, since we're about to fool the normal duplicate checker
1018 for (std::list<LLAssetRequest*>::iterator iter = mPendingDownloads.begin(); 1236 for (request_list_t::iterator iter = mPendingDownloads.begin();
1019 iter != mPendingDownloads.end(); ) 1237 iter != mPendingDownloads.end(); )
1020 { 1238 {
1021 LLAssetRequest* tmp = *iter++; 1239 LLAssetRequest* tmp = *iter++;
@@ -1056,12 +1274,12 @@ void LLAssetStorage::legacyGetDataCallback(LLVFS *vfs, const LLUUID &uuid, LLAss
1056 uuid.toString(uuid_str); 1274 uuid.toString(uuid_str);
1057 snprintf(filename,sizeof(filename),"%s.%s",gDirUtilp->getExpandedFilename(LL_PATH_CACHE,uuid_str).c_str(),LLAssetType::lookup(type)); /* Flawfinder: ignore */ 1275 snprintf(filename,sizeof(filename),"%s.%s",gDirUtilp->getExpandedFilename(LL_PATH_CACHE,uuid_str).c_str(),LLAssetType::lookup(type)); /* Flawfinder: ignore */
1058 1276
1059 FILE *fp = LLFile::fopen(filename, "wb"); /* Flawfinder: ignore */ 1277 FILE* fp = LLFile::fopen(filename, "wb"); /* Flawfinder: ignore */
1060 if (fp) 1278 if (fp)
1061 { 1279 {
1062 const S32 buf_size = 65536; 1280 const S32 buf_size = 65536;
1063 U8 copy_buf[buf_size]; 1281 U8 copy_buf[buf_size];
1064 while (file.read(copy_buf, buf_size)) 1282 while (file.read(copy_buf, buf_size)) /* Flawfinder: ignore */
1065 { 1283 {
1066 if (fwrite(copy_buf, file.getLastBytesRead(), 1, fp) < 1) 1284 if (fwrite(copy_buf, file.getLastBytesRead(), 1, fp) < 1)
1067 { 1285 {