- reworked states (removed substate)

- leave handler after every character read
This commit is contained in:
zolliker
2009-02-25 14:44:26 +00:00
parent 2006a2cf7d
commit 2fd07071d9
2 changed files with 81 additions and 80 deletions

43
ascon.i
View File

@ -22,28 +22,23 @@
*/
/**
* A sub-state of the connection. Only states with sub-state AsconStart may
* be set by the caller, and only when the sub-state is not AsconOnTheWay
*/
typedef enum { AsconOnTheWay=0, AsconStart=1, AsconFinished=2, AsconFailed=3 } AsconMode;
/**
* The state of the connection. The sub-state is state % 4.
* The state of the connection.
*/
typedef enum {
AsconNotConnected=0+AsconFinished,
AsconConnecting=4+AsconOnTheWay,
AsconConnectStart=AsconConnecting+AsconStart,
AsconConnectDone=AsconConnecting+AsconFinished,
AsconConnectFailed=AsconConnecting+AsconFailed,
AsconWriting=8+AsconOnTheWay,
AsconWriteStart=AsconWriting+AsconStart,
AsconWriteDone=AsconWriting+AsconFinished,
AsconReading=12+AsconOnTheWay,
AsconReadStart=AsconReading+AsconStart,
AsconReadDone=AsconReading+AsconFinished,
AsconIdle=16+AsconFinished,
AsconTimeout=20 + AsconFailed
AsconNotConnected, /**< unconnected, not to be connected automatically */
AsconConnectStart, /**< after initialisation or after AsconFailed */
AsconConnecting, /**< after AsconConnectStart or AsconConnecting */
AsconConnectDone, /**< after AsconConnecting */
AsconWriteStart, /**< set by the AsconWrite function */
AsconWriting, /**< after AsconWriteStart or AsconWriting */
AsconWriteDone, /**< after AsconWriting */
AsconReadStart, /**< after AsconWriteDone */
AsconReading, /**< after AsconReadStart or AsconReading */
AsconReadDone, /**< after AsconReading */
AsconIdle, /**< after AsconWriteDone, AsconReadDone, AsconTimeout, AsconIdle */
AsconFailed, /**< after any state */
AsconTimeout, /**< after AsconReading */
AsconMaxState /**< number of states */
} AsconState;
/** \brief the task handler function prototype
@ -74,6 +69,7 @@ struct Ascon {
int responseValid; /**< a valid response is ready */
AsconHandler handler; /**< handler function */
double reconnectInterval; /**< reconnect interval */
double lastReconnect; /**< last reconnect try */
};
#define ASCON_SELECT_ERROR -1
@ -83,7 +79,10 @@ struct Ascon {
/** \brief the standard handler routine.
* \param a the connection
* \return 0 when task has finished (connection to be closed), 1 when active
* \return 0 when it makes sense to call the handler again immediately
* (for example while reading, after a character was read, as
* there may be more chars in the buffer)
* 1 else
*
* In most cases a custom handler may be a wrapper around AsconStdHandler
*/
@ -155,7 +154,7 @@ int AsconWriteChars(int fd, char *data, int length);
* \param a The asynchronous I/O structure to store the
* error with
* \param msg The error message
* \param errorno The error number
* \param errorno The error number or 0 for a custom error
*/
void AsconError(Ascon *a, char *msg, int errorno);