1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#ifndef FILETRANSFERMGR_H
#define FILETRANSFERMGR_H
#ifdef _WIN32
#pragma once
#endif
#include "inetchannel.h"
typedef int FileTransferID_t;
abstract_class CFileTransferMgr
{
public:
CFileTransferMgr();
virtual ~CFileTransferMgr();
// Start transmitting a file.
// The user data is sent in the header and can include the filename, its ID, or whatever.
FileTransferID_t StartSending(
INetChannel *pDest,
const void *pUserData,
int userDataLength,
const char *pFileData,
int fileLength,
int bytesPerSecond );
// Kill all file transfers on this channel.
void HandleClientDisconnect( INetChannel *pChannel );
// Call this when data comes in.
void HandleReceivedData( INetChannel *pChannel, const void *pData, int len );
// Iterate the list of files being downloaded.
int FirstIncoming() const;
int NextIncoming( int i ) const;
int InvalidIncoming() const;
void GetIncomingUserData( int i, const void* &pData, int &dataLen );
// Overridables.
public:
// Send outgoing data for a file (reliably).
// Returns false if it was unable to send the chunk. If this happens, the file transfer manager
// will retry the chunk a few times, and eventually cancel the file transfer if the problem keeps happening.
virtual bool SendChunk( INetChannel *pDest, const void *pData, int len ) = 0;
// Had to stop sending because there was a problem sending a chunk, or
// the net channel went away.
virtual void OnSendCancelled( FileTransferID_t id ) = 0;
// Called when it's done transmitting a file.
virtual void OnFinishedSending(
INetChannel *pDest,
const void *pUserData,
int userDataLen,
FileTransferID_t id ) = 0;
// Called when a file is received.
virtual void OnFileReceived(
INetChannel *pChan,
const void *pUserData,
int userDataLength,
const char *pFileData,
int fileLength ) = 0;
};
#endif // FILETRANSFERMGR_H
|