- minor fixes and improvements
This commit is contained in:
24
ascon.c
24
ascon.c
@ -57,7 +57,7 @@ double DoubleTime(void) {
|
|||||||
return now.tv_sec + now.tv_usec / 1e6;
|
return now.tv_sec + now.tv_usec / 1e6;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AsconError(AsconPtr a, char *msg, int errorno) {
|
static void AsconError(Ascon *a, char *msg, int errorno) {
|
||||||
static char *stateText[]={
|
static char *stateText[]={
|
||||||
"state 0", "kill", "state 2", "notConnected",
|
"state 0", "kill", "state 2", "notConnected",
|
||||||
"connect", "start connect", "connect finished", "connect failed",
|
"connect", "start connect", "connect finished", "connect failed",
|
||||||
@ -80,7 +80,7 @@ static void AsconError(AsconPtr a, char *msg, int errorno) {
|
|||||||
a->state |= AsconFailed;
|
a->state |= AsconFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AsconConnect(AsconPtr a) {
|
static void AsconConnect(Ascon *a) {
|
||||||
/* input state: AsconConnectStart
|
/* input state: AsconConnectStart
|
||||||
output state: AsconFailed or AsconConnecting */
|
output state: AsconFailed or AsconConnecting */
|
||||||
int ret;
|
int ret;
|
||||||
@ -124,7 +124,7 @@ static void AsconConnect(AsconPtr a) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsconStdInit(AsconPtr a, char *hostport) {
|
void AsconStdInit(Ascon *a, char *hostport) {
|
||||||
a->fd = -1;
|
a->fd = -1;
|
||||||
a->state = AsconConnectStart;
|
a->state = AsconConnectStart;
|
||||||
a->timeout = 2.0; /* sec */
|
a->timeout = 2.0; /* sec */
|
||||||
@ -245,7 +245,7 @@ int AsconWriteChars(int fd, char *data, int length) {
|
|||||||
|
|
||||||
static double lastCall = 0;
|
static double lastCall = 0;
|
||||||
|
|
||||||
int AsconStdHandler(AsconPtr a) {
|
int AsconStdHandler(Ascon *a) {
|
||||||
int ret;
|
int ret;
|
||||||
int l;
|
int l;
|
||||||
char chr;
|
char chr;
|
||||||
@ -354,7 +354,7 @@ void AsconInsertProtocol(AsconProtocol *protocol) {
|
|||||||
AsconProtocolAdd(&protocols, protocol);
|
AsconProtocolAdd(&protocols, protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
AsconHandler AsconSetHandler(AsconPtr a, int argc, char *argv[]) {
|
AsconHandler AsconSetHandler(Ascon *a, int argc, char *argv[]) {
|
||||||
AsconProtocol *p;
|
AsconProtocol *p;
|
||||||
|
|
||||||
if (argc < 1) return NULL;
|
if (argc < 1) return NULL;
|
||||||
@ -378,8 +378,8 @@ char *ConcatArgs(int argc, char *argv[]) {
|
|||||||
return Arg2Tcl(argc, argv, NULL, -1);
|
return Arg2Tcl(argc, argv, NULL, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
AsconPtr AsconMake(SConnection *con, int argc, char *argv[]) {
|
Ascon *AsconMake(SConnection *con, int argc, char *argv[]) {
|
||||||
AsconPtr a;
|
Ascon *a;
|
||||||
char *args;
|
char *args;
|
||||||
|
|
||||||
a = calloc(1, sizeof(*a));
|
a = calloc(1, sizeof(*a));
|
||||||
@ -402,7 +402,7 @@ AsconPtr AsconMake(SConnection *con, int argc, char *argv[]) {
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsconKill(AsconPtr a) {
|
void AsconKill(Ascon *a) {
|
||||||
a->state = AsconKillMe;
|
a->state = AsconKillMe;
|
||||||
a->handler(a);
|
a->handler(a);
|
||||||
if (a->fd > 0) {
|
if (a->fd > 0) {
|
||||||
@ -416,7 +416,7 @@ void AsconKill(AsconPtr a) {
|
|||||||
free(a);
|
free(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
AsconStatus AsconTask(AsconPtr a) {
|
AsconStatus AsconTask(Ascon *a) {
|
||||||
a->handler(a);
|
a->handler(a);
|
||||||
while (1) {
|
while (1) {
|
||||||
switch (a->state) {
|
switch (a->state) {
|
||||||
@ -462,7 +462,7 @@ AsconStatus AsconTask(AsconPtr a) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int AsconWrite(AsconPtr a, char *command, int noResponse) {
|
int AsconWrite(Ascon *a, char *command, int noResponse) {
|
||||||
if (a->state <= AsconConnectFailed || a->state % 4 < AsconFinished) return 0;
|
if (a->state <= AsconConnectFailed || a->state % 4 < AsconFinished) return 0;
|
||||||
DynStringCopy(a->wrBuffer, command);
|
DynStringCopy(a->wrBuffer, command);
|
||||||
a->noResponse = noResponse;
|
a->noResponse = noResponse;
|
||||||
@ -472,7 +472,7 @@ int AsconWrite(AsconPtr a, char *command, int noResponse) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *AsconRead(AsconPtr a) {
|
char *AsconRead(Ascon *a) {
|
||||||
if (a->noResponse) {
|
if (a->noResponse) {
|
||||||
a->noResponse=0;
|
a->noResponse=0;
|
||||||
return "";
|
return "";
|
||||||
@ -488,6 +488,6 @@ char *AsconRead(AsconPtr a) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrMsgList *AsconGetErrList(AsconPtr a) {
|
ErrMsgList *AsconGetErrList(Ascon *a) {
|
||||||
return &a->errList;
|
return &a->errList;
|
||||||
}
|
}
|
||||||
|
14
ascon.h
14
ascon.h
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
/** \brief the asynchronous connection
|
/** \brief the asynchronous connection
|
||||||
*/
|
*/
|
||||||
typedef struct Ascon *AsconPtr;
|
typedef struct Ascon Ascon;
|
||||||
|
|
||||||
/** \brief the possible results of AsconTask
|
/** \brief the possible results of AsconTask
|
||||||
*/
|
*/
|
||||||
@ -29,18 +29,18 @@ typedef enum {
|
|||||||
* are protocol specific, but argv[1] is usually host::port
|
* are protocol specific, but argv[1] is usually host::port
|
||||||
* \return the created connection or NULL on failure
|
* \return the created connection or NULL on failure
|
||||||
*/
|
*/
|
||||||
AsconPtr AsconMake(SConnection *con, int argc, char *argv[]);
|
Ascon *AsconMake(SConnection *con, int argc, char *argv[]);
|
||||||
|
|
||||||
/** \brief kill function
|
/** \brief kill function
|
||||||
* \param a the connection to be killed
|
* \param a the connection to be killed
|
||||||
*/
|
*/
|
||||||
void AsconKill(AsconPtr a);
|
void AsconKill(Ascon *a);
|
||||||
|
|
||||||
/** \brief the task handler. To be called repeatedly.
|
/** \brief the task handler. To be called repeatedly.
|
||||||
* \param a the connection
|
* \param a the connection
|
||||||
* \return the state of the connection
|
* \return the state of the connection
|
||||||
*/
|
*/
|
||||||
AsconStatus AsconTask(AsconPtr a);
|
AsconStatus AsconTask(Ascon *a);
|
||||||
|
|
||||||
/** \brief write to the connection. allowed only when the state is ascon_ready
|
/** \brief write to the connection. allowed only when the state is ascon_ready
|
||||||
* \param a the connection
|
* \param a the connection
|
||||||
@ -48,7 +48,7 @@ AsconStatus AsconTask(AsconPtr a);
|
|||||||
* \param noResponse 0 normally, 1 if no reponse is expected
|
* \param noResponse 0 normally, 1 if no reponse is expected
|
||||||
* \return 1 on success, 0 when not ready
|
* \return 1 on success, 0 when not ready
|
||||||
*/
|
*/
|
||||||
int AsconWrite(AsconPtr a, char *command, int noResponse);
|
int AsconWrite(Ascon *a, char *command, int noResponse);
|
||||||
|
|
||||||
/** \brief read from the connection. allowed only when a response is available
|
/** \brief read from the connection. allowed only when a response is available
|
||||||
* \param a the connection
|
* \param a the connection
|
||||||
@ -58,12 +58,12 @@ int AsconWrite(AsconPtr a, char *command, int noResponse);
|
|||||||
* The result is only valid until the next call to other AsconXxx functions
|
* The result is only valid until the next call to other AsconXxx functions
|
||||||
* and has to be duplicated if needed later.
|
* and has to be duplicated if needed later.
|
||||||
*/
|
*/
|
||||||
char *AsconRead(AsconPtr a);
|
char *AsconRead(Ascon *a);
|
||||||
|
|
||||||
/** \brief get the connections error list
|
/** \brief get the connections error list
|
||||||
* \return the error list
|
* \return the error list
|
||||||
*/
|
*/
|
||||||
ErrMsgList *AsconGetErrList(AsconPtr a);
|
ErrMsgList *AsconGetErrList(Ascon *a);
|
||||||
|
|
||||||
/** \brief a helper function
|
/** \brief a helper function
|
||||||
* \param argc the number of args
|
* \param argc the number of args
|
||||||
|
12
ascon.i
12
ascon.i
@ -50,12 +50,12 @@ typedef enum {
|
|||||||
*
|
*
|
||||||
* custom handlers must have this prototype
|
* custom handlers must have this prototype
|
||||||
*/
|
*/
|
||||||
typedef int (* AsconHandler)(AsconPtr connection);
|
typedef int (* AsconHandler)(Ascon *connection);
|
||||||
|
|
||||||
/** Ascon struct
|
/** Ascon struct
|
||||||
* all members are public, allowing access by handler wrappers
|
* all members are public, allowing access by handler wrappers
|
||||||
*/
|
*/
|
||||||
typedef struct Ascon {
|
struct Ascon {
|
||||||
AsconState state; /**< the current state */
|
AsconState state; /**< the current state */
|
||||||
int fd; /**< socket */
|
int fd; /**< socket */
|
||||||
int readState; /**< default implementation: 'was cr' */
|
int readState; /**< default implementation: 'was cr' */
|
||||||
@ -70,7 +70,7 @@ typedef struct Ascon {
|
|||||||
int noResponse; /**< no response expected */
|
int noResponse; /**< no response expected */
|
||||||
int responseValid; /**< a valid response is ready */
|
int responseValid; /**< a valid response is ready */
|
||||||
AsconHandler handler; /**< handler function */
|
AsconHandler handler; /**< handler function */
|
||||||
} Ascon;
|
};
|
||||||
|
|
||||||
#define ASCON_SELECT_ERROR -1
|
#define ASCON_SELECT_ERROR -1
|
||||||
#define ASCON_RECV_ERROR -2
|
#define ASCON_RECV_ERROR -2
|
||||||
@ -83,7 +83,7 @@ typedef struct Ascon {
|
|||||||
*
|
*
|
||||||
* In most cases a custom handler may be a wrapper around AsconStdHandler
|
* In most cases a custom handler may be a wrapper around AsconStdHandler
|
||||||
*/
|
*/
|
||||||
int AsconStdHandler(AsconPtr a);
|
int AsconStdHandler(Ascon *a);
|
||||||
|
|
||||||
/** \brief initialize a standard connection
|
/** \brief initialize a standard connection
|
||||||
* \param a the connection
|
* \param a the connection
|
||||||
@ -91,7 +91,7 @@ int AsconStdHandler(AsconPtr a);
|
|||||||
*
|
*
|
||||||
* In most cases a custom init function may be a wrapper around AsconStdInit
|
* In most cases a custom init function may be a wrapper around AsconStdInit
|
||||||
*/
|
*/
|
||||||
void AsconStdInit(AsconPtr a, char *hostport);
|
void AsconStdInit(Ascon *a, char *hostport);
|
||||||
|
|
||||||
/** The Ascon Protocol
|
/** The Ascon Protocol
|
||||||
*/
|
*/
|
||||||
@ -111,7 +111,7 @@ void AsconInsertProtocol(AsconProtocol *protocol);
|
|||||||
* \param a the connection to be closed
|
* \param a the connection to be closed
|
||||||
* remark: the connection struct itself has to be freed manually
|
* remark: the connection struct itself has to be freed manually
|
||||||
*/
|
*/
|
||||||
void AsconClose(AsconPtr a);
|
void AsconClose(Ascon *a);
|
||||||
|
|
||||||
/** \brief swallow garbage (utility function)
|
/** \brief swallow garbage (utility function)
|
||||||
* \param fd the socket
|
* \param fd the socket
|
||||||
|
5
conman.c
5
conman.c
@ -1040,6 +1040,11 @@ pDynString SCEndBuffering(SConnection *pCon)
|
|||||||
SICSLogWrite(pBueffel,eInternal);
|
SICSLogWrite(pBueffel,eInternal);
|
||||||
SICSLogWrite(buffer,iOut);
|
SICSLogWrite(buffer,iOut);
|
||||||
|
|
||||||
|
/* put it into the interpreter if present */
|
||||||
|
if(SCinMacro(self))
|
||||||
|
{
|
||||||
|
InterpWrite(pServ->pSics,buffer);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
|
738
scriptcontext.c
738
scriptcontext.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user