gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

statemachine flaws/weaknesses


From: Ladislav Michl
Subject: statemachine flaws/weaknesses
Date: Mon, 24 Feb 2003 10:28:39 +0100
User-agent: Mutt/1.5.3i

1) sm_block_no_retry _does_ resending of last message
2) __sm_block_timeout will block at _most_ timeout amount of time.
   select is used to see if a read will not block. this condition is
   true when at least one character is waiting in input buffer...

what about (first itteration)?

/* t is in miliseconds */
gn_error sm_block_no_retry_timeout(int waitfor, int t, gn_data *data, struct 
gn_statemachine *state)
{
        gn_error error;
        long sec, usec;
        struct timeval now, next, timeout;

        error = sm_wait_for(waitfor, data, state);
        if (error) 
                return error;
        
        sec = t / 1000;
        usec = (t % 1000) * 1000;
        timeout.tv_sec = sec;
        timeout.tv_usec = usec;
        gettimeofday(&now, NULL);
        timeradd(&now, &timeout, &next);
        do {
                state->link.loop(&timeout, state);
                /* Some select() implementations will modify the timeval 
structure */
                timeout.tv_sec = sec;
                timeout.tv_usec = usec;
        } while (timercmp(&next, &now, >) && state->current_state != 
GN_SM_ResponseReceived);

        if (state->current_state == GN_SM_ResponseReceived)
                return sm_error_get(waitfor, state);
        return GN_ERR_TIMEOUT;
}

gn_error sm_block_timeout(int waitfor, int t, gn_data *data, struct 
gn_statemachine *state)
{
        int retry;
        gn_error err;

        for (retry = 0; retry < 3; retry++) {
                err = sm_block_no_retry(waitfor, t, data, state);
                if (err == GN_ERR_NONE || err != GN_ERR_TIMEOUT) return err;
                if (retry < 2) {
                        sm_reset(state);
                        sm_message_send(state->last_msg_size, 
state->last_msg_type, state->last_msg, state);
                }
        }
        return GN_ERR_TIMEOUT;
}

this way timeout is always what it ought to be. well, perhaps i missed
some tweaks around GN_SM_ResponseReceived and GN_SM_WaitingForResponse,
but above basically does the job. objections?

also i'd like to see non timeout functions to die. suitable timeout is
certainly different for mbus connection (9600), fbus (115200), atbus
(19200) and is also phone specific. therefore timeout should me adjusted
in driver code.

        ladis




reply via email to

[Prev in Thread] Current Thread [Next in Thread]