[PATCH] fix timeout when transfering large SMS folders
Stefan Fiedler <stefan.fiedler <at> student.tuwien.ac.at>
2013-04-19 11:21:02 GMT
Hello everyone,
here is a small patch I wrote which fixes the hard-coded timeouts when
copying SMS folders with many files. With the patch applied, gnokii will
only time-out if there is no activity for a predefined period, but will
update a keepalive timer whenever data is sent or received.
The patch applies to the latest revision in the git repository. I tested
it with a 2610 mobile phone and a third-party CA-45 USB cable (Daipu
brand). If you have any questions or comments please feel free to write
me on this mailing list to which I am currently subscribed.
With best regards,
Stefan Fiedler
diff -dur gnokii.orig/common/gsm-statemachine.c gnokii/common/gsm-statemachine.c
--- gnokii.orig/common/gsm-statemachine.c 2013-04-07 16:31:27.929885641 +0200
+++ gnokii/common/gsm-statemachine.c 2013-04-08 04:29:48.405936104 +0200
<at> <at> -27,6 +27,9 <at> <at>
state->waiting_for_number = 0;
state->received_number = 0;
+ state->keepalive.tv_sec = 0;
+ state->keepalive.tv_usec = 0;
+
return GN_ERR_NONE;
}
<at> <at> -42,12 +45,29 <at> <at>
state->last_msg = message;
state->current_state = GN_SM_MessageSent;
- /* FIXME - clear KeepAlive timer */
+ state->keepalive.tv_sec = 0;
+ state->keepalive.tv_usec = 0;
+
return state->link.send_message(messagesize, messagetype, message, state);
}
else return GN_ERR_NOTREADY;
}
+void sm_keepalive(struct gn_statemachine *state)
+{
+ gettimeofday(&(state->keepalive), NULL);
+}
+
+int sm_is_alive(struct timeval *timeout, struct gn_statemachine *state)
+{
+ struct timeval t, now;
+
+ timeradd(&(state->keepalive), timeout, &t);
+ gettimeofday(&now, NULL);
+
+ return timercmp(&t, &now, >);
+}
+
GNOKII_API gn_state gn_sm_loop(int timeout, struct gn_statemachine *state)
{
struct timeval loop_timeout;
<at> <at> -67,7 +87,8 <at> <at>
state->link.loop(&loop_timeout, state);
}
- /* FIXME - add calling a KeepAlive function here */
+ sm_keepalive(state);
+
return state->current_state;
}
<at> <at> -80,6 +101,9 <at> <at>
state->received_number = 0;
if (state->link.reset)
state->link.reset(state);
+
+ state->keepalive.tv_sec = 0;
+ state->keepalive.tv_usec = 0;
}
}
<at> <at> -234,7 +258,8 <at> <at>
do {
s = gn_sm_loop(1, state); /* Timeout=100ms */
gettimeofday(&now, NULL);
- } while (timercmp(&next, &now, >) && (s == GN_SM_MessageSent));
+ } while ((timercmp(&next, &now, >) || sm_is_alive(&timeout, state))
+ && (s == GN_SM_MessageSent));
if (s == GN_SM_WaitingForResponse || s == GN_SM_ResponseReceived) break;
if (state->config.sm_retry) {
<at> <at> -257,7 +282,8 <at> <at>
do {
s = gn_sm_loop(1, state); /* Timeout=100ms */
gettimeofday(&now, NULL);
- } while (timercmp(&next, &now, >) && (s != GN_SM_ResponseReceived));
+ } while ((timercmp(&next, &now, >) || sm_is_alive(&timeout, state))
+ && (s != GN_SM_ResponseReceived));
if (s == GN_SM_ResponseReceived)
return sm_error_get(waitfor, state);
diff -dur gnokii.orig/include/gnokii/statemachine.h gnokii/include/gnokii/statemachine.h
--- gnokii.orig/include/gnokii/statemachine.h 2013-04-07 16:31:27.957885764 +0200
+++ gnokii/include/gnokii/statemachine.h 2013-04-08 04:26:38.220993018 +0200
<at> <at> -79,6 +79,9 <at> <at>
union {
gn_phonebook_entry pb_entry;
} u;
+
+ /* Store time of the last call to sm_keepalive() */
+ struct timeval keepalive;
};
GNOKII_API gn_state gn_sm_loop(int timeout, struct gn_statemachine *state);
_______________________________________________
gnokii-users mailing list
gnokii-users <at> nongnu.org
https://lists.nongnu.org/mailman/listinfo/gnokii-users