MCPcopy Create free account
hub / github.com/Tencent/phxpaxos / SendFile

Method SendFile

src/algorithm/checkpoint_sender.cpp:235–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233}
234
235int CheckpointSender :: SendFile(const StateMachine * poSM, const std::string & sDirPath, const std::string & sFilePath)
236{
237 PLGHead("START smid %d dirpath %s filepath %s", poSM->SMID(), sDirPath.c_str(), sFilePath.c_str());
238
239 string sPath = sDirPath + sFilePath;
240
241 if (m_mapAlreadySendedFile.find(sPath) != end(m_mapAlreadySendedFile))
242 {
243 PLGErr("file already send, filepath %s", sPath.c_str());
244 return 0;
245 }
246
247 int iFD = open(sPath.c_str(), O_RDWR, S_IREAD);
248
249 if (iFD == -1)
250 {
251 PLGErr("Open file fail, filepath %s", sPath.c_str());
252 return -1;
253 }
254
255 ssize_t iReadLen = 0;
256 size_t llOffset = 0;
257 while (true)
258 {
259 iReadLen = read(iFD, m_sTmpBuffer, sizeof(m_sTmpBuffer));
260 if (iReadLen == 0)
261 {
262 break;
263 }
264
265 if (iReadLen < 0)
266 {
267 close(iFD);
268 return -1;
269 }
270
271 int ret = SendBuffer(poSM->SMID(), poSM->GetCheckpointInstanceID(m_poConfig->GetMyGroupIdx()),
272 sFilePath, llOffset, string(m_sTmpBuffer, iReadLen));
273 if (ret != 0)
274 {
275 close(iFD);
276 return ret;
277 }
278
279 PLGDebug("Send ok, offset %zu readlen %d", llOffset, iReadLen);
280
281 if (iReadLen < (ssize_t)sizeof(m_sTmpBuffer))
282 {
283 break;
284 }
285
286 llOffset += iReadLen;
287 }
288
289 m_mapAlreadySendedFile[sPath] = true;
290
291 close(iFD);
292 PLGImp("END");

Callers

nothing calls this directly

Calls 2

SMIDMethod · 0.45

Tested by

no test coverage detected