-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sender.h
139 lines (80 loc) · 2.34 KB
/
Sender.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* Sender.h
*
*/
#ifndef _SENDER_H_
#define _SENDER_H_
#define kMaxPacketSize 1200
#include <iostream>
#include <fstream>
#include "Mutex.h"
#include "Thread.h"
#include "Transmission.h"
#include "TransmissionTimer.h"
using namespace std;
enum SenderState
{
SEND_NO_CONN,
SEND_DATA,
SEND_FIN
};
class Mutex;
/*! \class Sender
\brief The main class of the sending application.
Parses command line and opens a connection to the receiver. Starts
worker threads for sending and receiving data, as well as handling timeouts
*/
class Sender {
public:
Sender(char fileName[], struct sockaddr_in* recv);
virtual ~Sender();
void Start();
private:
static void* _StartSend(void *);
static void* _StartTimer(void *);
void _StartListen();
void _SendPacket(uint32_t, bool);
ssize_t _ReceivePacket();
int32_t _ConfigureSocket();
uint32_t _BuildSynPacket();
uint32_t _BuildDataPacket(char buffer[], unsigned short dataSize);
uint32_t _BuildFinPacket();
void _ParseAck();
void _Retransmit();
void _UpdateRTT(bool flag);
void _SendCurrent();
void _SendSyn();
void _SendData();
//void _SendFin();
static void _TimeOutCallBack(void* caller);
sockaddr_in *mRecv;
fstream mFile;
uint64_t mFileSize;
//uint64_t mSeqNum; // Stores the current file offset.
uint64_t mLastAck;
uint32_t mWindowSize; // Stores currenet window size, which is min(mCongWin, mRecvWin)
string mFileName;
int32_t mSock;
bool mConnected;
char mMFBOut[1200];
char mMFBIn[14];
Mutex mSendLock;
Thread mSendThread;
Thread mTimerThread;
TransmissionTimer* mTransTimer;
uint32_t mEstRTT;
int mEstDEV;
bool mRetransmit;
struct timeval mBegTimestamp;
struct timeval mEndTimestamp;
struct timeval mConnStartTime;
struct timeval mConnEndTime;
SenderState mCurrentState;
uint64_t mSeqNumBase;
uint64_t mFinSeqNum;
uint32_t mCongWin;
uint32_t mRecvWin;
uint32_t mTheTimeout;
streampos mFileOffset;
};
#endif