Circles with text inside are states. The text describes what a state is.
The dashed arrow indicates the initial state.
, . , . - , . - . - ( ).
, , .
, , . - , - -, .
- , C ( , , ):
enum State { WaitFor0Call, WaitForAck0, WaitForCall1, WaitForAck1 }
int main() {
State state = WaitFor0Call;
while (1) {
switch (state) {
case WaitFor0Call:
if (rdt_rcv(rcvpkt)) continue;
if (rdt_send(data)) {
state = WaitForAck0;
sndpkt = make_pkt(0, data, checksum);
udt_send(sndpkt);
start_timer();
}
break;
case WaitForAck0:
break;
case WaitForCall1:
break;
case WaitForAck1:
break;
}
}
}
, , if (rdt_rcv(rcvpkt)) whatever; , rdt_send, . , FSM , , , .. , , :)
, - ( ), if (there_is_ready_for_consuming_packet_in_the_input_queue) continue; if (data_was_put_to_outgoing_stream_successfully) ...;