2 Three pieces of state need to be kept for each side of each option.
3 (You need the localside, sending WILL/WONT & receiving DO/DONT, and
4 the remoteside, sending DO/DONT and receiving WILL/WONT)
6 MY_STATE: What state am I in?
7 WANT_STATE: What state do I want?
8 WANT_RESP: How many requests have I initiated?
11 MY_STATE = WANT_STATE = DONT
14 The local setup will change based on the state of the Telnet
15 variables. When we are the originator, we can either make the
16 local setup changes at option request time (in which case if
17 the option is denied we need to change things back) or when
18 the option is acknowledged.
20 To initiate a switch to NEW_STATE:
22 if ((WANT_RESP == 0 && NEW_STATE == MY_STATE) ||
23 WANT_STATE == NEW_STATE) {
27 * This is where the logic goes to change the local setup
28 * if we are doing so at request initiation
30 WANT_STATE = NEW_STATE;
35 When receiving NEW_STATE:
39 if (WANT_RESP && (NEW_STATE == MY_STATE))
43 if (NEW_STATE != WANT_STATE) {
45 * This is where the logic goes to decide if it is ok
46 * to switch to NEW_STATE, and if so, do any necessary
47 * local setup changes.
49 if (ok_to_switch_to NEW_STATE)
50 WANT_STATE = NEW_STATE;
53 * if (MY_STATE != WANT_STATE)
54 reply with WANT_STATE;
57 * This is where the logic goes to change the local setup
58 * if we are doing so at request acknowledgment
64 * This if() line is not needed, it should be ok to always do the
65 "reply with WANT_STATE". With the if() line, asking to turn on
66 an option that the other side doesn't understand is:
69 Without the if() line, it is:
73 If the other side does not expect to receive the latter case,
74 but generates the latter case, then there is a potential for
75 option negotiation loops. An implementation that does not expect
76 to get the second case should not generate it, an implementation
77 that does expect to get it may or may not generate it, and things
78 will still work. Being conservative in what we send, we have the
79 if() statement in, but we expect the other side to generate the