network programming - How to read a FSM diagram -


fms

how take diagram , translate useable program. i'm not sure how read diagram. if kind of walk me through, maybe show example of code , how relates diagram, great.

thanks!

circles text inside states. text describes state is.

dashed arrow points starting state.

outgoing arrows determine state change. beside of arrow text divided line upper part , lower part. lower part actions should take place when arrow transition executed. upper part conditions. when true - transition executed (and lower part).

lambda symbol means should nothing except changing current state when transition takes place.

so lower parts have coarse corresponding functions. , upper parts points should wait conditions - polling or async waiting pending i/o packets, whatever.

here pseudo-code similar c (i've written here not assume works or compiles):

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:             // ...similar code...             break;          case waitforcall1:             // ...similar code...             break;          case waitforack1:             // ...similar code...             break;       }    } } 

you should take account receive , send functions blocking, code if (rdt_rcv(rcvpkt)) whatever; technically incorrect don't check rdt_send until returns control. fsm communicates logical flow, not technical aspects of how should organized, thread management etc. , code doesn't show aspects because decently complicated depending on needs , because didn't give enough details make informed advices on these sort of things :)

my guess have sort of bi-directed stream (for input , output respectively) , conditions if (there_is_ready_for_consuming_packet_in_the_input_queue) continue; , if (data_was_put_to_outgoing_stream_successfully) ...;


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -