Skip to content

Commit 34741f2

Browse files
committedDec 23, 2016
Add basic TCP three-way handshake.
1 parent 086308d commit 34741f2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
 

Diff for: ‎src/socket/tcp.rs

+19
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ impl<'a> TcpSocket<'a> {
246246
Ok(())
247247
}
248248

249+
(State::SynReceived, TcpRepr {
250+
control: TcpControl::None, ack_number: Some(ack_number), ..
251+
}) => {
252+
if ack_number != self.local_seq_no + 1 { return Err(Error::Rejected) }
253+
self.set_state(State::Established);
254+
255+
// FIXME: queue data from ACK
256+
// FIXME: update sequence numbers
257+
self.retransmit.reset();
258+
Ok(())
259+
}
260+
249261
_ => {
250262
// This will cause the interface to reply with an RST.
251263
Err(Error::Rejected)
@@ -274,6 +286,7 @@ impl<'a> TcpSocket<'a> {
274286
State::Listen => {
275287
return Err(Error::Exhausted)
276288
}
289+
277290
State::SynReceived => {
278291
if !self.retransmit.check() { return Err(Error::Exhausted) }
279292
repr.control = TcpControl::Syn;
@@ -282,6 +295,12 @@ impl<'a> TcpSocket<'a> {
282295
net_trace!("tcp:{}:{}: SYN sent",
283296
self.local_end, self.remote_end);
284297
}
298+
299+
State::Established => {
300+
// FIXME: transmit something
301+
return Err(Error::Exhausted)
302+
}
303+
285304
_ => unreachable!()
286305
}
287306

0 commit comments

Comments
 (0)
Please sign in to comment.