Skip to content

Commit 119b7fc

Browse files
committed
Add buffers into TcpConnection
1 parent db8e5da commit 119b7fc

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/tcp.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,12 @@ TcpConnection::TcpConnection(const TcpAddress& first, const TcpAddress& second)
6868

6969
TcpConnection::~TcpConnection() {
7070
}
71+
72+
void
73+
TcpConnection::addPacket(bool isIncoming, const Buffer& buffer) {
74+
if (isIncoming) {
75+
mInBuffer.append(buffer);
76+
} else {
77+
mOutBuffer.append(buffer);
78+
}
79+
}

src/tcp.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <list>
77
#include <string>
88

9+
#include "buffer.h"
10+
911
using namespace std;
1012

1113
typedef u_int32_t tcp_seq;
@@ -59,8 +61,6 @@ typedef struct ether_header RawEtherPacket;
5961
typedef struct nread_ip RawIpPacket;
6062
typedef struct nread_tcp RawTcpPacket;
6163

62-
class Buffer;
63-
6464
class IPv4 {
6565
public:
6666
IPv4(const struct in_addr& addr);
@@ -112,12 +112,14 @@ class TcpConnection {
112112
TcpConnection(const TcpAddress& first, const TcpAddress& second);
113113
virtual ~TcpConnection();
114114

115-
virtual bool addPacket(const Buffer& data) = 0;
115+
virtual void addPacket(bool isIncoming, const Buffer& data);
116116

117117
private:
118118
TcpAddress mFirst;
119119
TcpAddress mSecond;
120120
TcpConnectionState mState;
121+
Buffer mOutBuffer;
122+
Buffer mInBuffer;
121123
};
122124

123125
class TcpConnectionManager {

0 commit comments

Comments
 (0)