Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/network/NetFileTransfer.h
/* Copyright (C) 2016 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#ifndef NETFILETRANSFER_H | #ifndef NETFILETRANSFER_H | ||||
#define NETFILETRANSFER_H | #define NETFILETRANSFER_H | ||||
#include <map> | #include <map> | ||||
class CNetMessage; | class CNetMessage; | ||||
class CFileTransferResponseMessage; | |||||
class CFileTransferDataMessage; | |||||
class CFileTransferAckMessage; | |||||
class CNetClientSession; | class CNetClientSession; | ||||
class CNetServerSession; | class CNetServerSession; | ||||
class INetSession; | class INetSession; | ||||
// Assume this is sufficiently less than MTU that packets won't get | // Assume this is sufficiently less than MTU that packets won't get | ||||
// fragmented or dropped. | // fragmented or dropped. | ||||
static const size_t DEFAULT_FILE_TRANSFER_PACKET_SIZE = 1024; | static const size_t DEFAULT_FILE_TRANSFER_PACKET_SIZE = 1024; | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
/** | /** | ||||
* Should be called when a message is received from the network. | * Should be called when a message is received from the network. | ||||
* Returns INFO::SKIPPED if the message is not one that this class handles. | * Returns INFO::SKIPPED if the message is not one that this class handles. | ||||
* Returns INFO::OK if the message is handled successfully, | * Returns INFO::OK if the message is handled successfully, | ||||
* or ERR::FAIL if handled unsuccessfully. | * or ERR::FAIL if handled unsuccessfully. | ||||
*/ | */ | ||||
Status HandleMessageReceive(const CNetMessage* message); | Status HandleMessageReceive(const CNetMessage& message); | ||||
/** | /** | ||||
* Registers a file-receiving task. | * Registers a file-receiving task. | ||||
*/ | */ | ||||
void StartTask(const shared_ptr<CNetFileReceiveTask>& task); | void StartTask(const shared_ptr<CNetFileReceiveTask>& task); | ||||
/** | /** | ||||
* Registers data to be sent in response to a request. | * Registers data to be sent in response to a request. | ||||
* (Callers are expected to have their own mechanism for receiving | * (Callers are expected to have their own mechanism for receiving | ||||
* requests and deciding what to respond with.) | * requests and deciding what to respond with.) | ||||
*/ | */ | ||||
void StartResponse(u32 requestID, const std::string& data); | void StartResponse(u32 requestID, const std::string& data); | ||||
/** | /** | ||||
* Call frequently (e.g. once per frame) to trigger any necessary | * Call frequently (e.g. once per frame) to trigger any necessary | ||||
* packet processing. | * packet processing. | ||||
*/ | */ | ||||
void Poll(); | void Poll(); | ||||
private: | private: | ||||
Status OnFileTransferResponse(const CFileTransferResponseMessage& message); | |||||
Status OnFileTransferData(const CFileTransferDataMessage& message); | |||||
Status OnFileTransferAck(const CFileTransferAckMessage& message); | |||||
/** | /** | ||||
* Asynchronous file-sending task. | * Asynchronous file-sending task. | ||||
*/ | */ | ||||
struct CNetFileSendTask | struct CNetFileSendTask | ||||
{ | { | ||||
u32 requestID; | u32 requestID; | ||||
std::string buffer; | std::string buffer; | ||||
size_t offset; | size_t offset; | ||||
size_t maxWindowSize; | size_t maxWindowSize; | ||||
size_t packetsInFlight; | size_t packetsInFlight; | ||||
}; | }; | ||||
INetSession* m_Session; | INetSession* m_Session; | ||||
u32 m_NextRequestID; | u32 m_NextRequestID; | ||||
typedef std::map<u32, shared_ptr<CNetFileReceiveTask>> FileReceiveTasksMap; | using FileReceiveTasksMap = std::map<u32, shared_ptr<CNetFileReceiveTask> >; | ||||
FileReceiveTasksMap m_FileReceiveTasks; | FileReceiveTasksMap m_FileReceiveTasks; | ||||
typedef std::map<u32, CNetFileSendTask> FileSendTasksMap; | using FileSendTasksMap = std::map<u32, CNetFileSendTask>; | ||||
FileSendTasksMap m_FileSendTasks; | FileSendTasksMap m_FileSendTasks; | ||||
double m_LastProgressReportTime; | double m_LastProgressReportTime; | ||||
}; | }; | ||||
#endif // NETFILETRANSFER_H | #endif // NETFILETRANSFER_H |
Wildfire Games · Phabricator