aboutsummaryrefslogtreecommitdiffstats
path: root/agni.c
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2017-05-02 17:27:02 +0100
committerFreeArtMan <dos21h@gmail.com>2017-05-02 17:27:02 +0100
commit8933fc1b3890fe892737c1f3e85cc77585f67993 (patch)
tree328b2c0e10c48dae1d9ac0c607d0b8ca419ea047 /agni.c
parentfc91eba3845a9e9c741da41ba467c042cbb4ca85 (diff)
downloadagni-8933fc1b3890fe892737c1f3e85cc77585f67993.tar.gz
agni-8933fc1b3890fe892737c1f3e85cc77585f67993.zip
Commands are now removed from command queue if they are there too long. Commands removed if response for command is recieved
Diffstat (limited to 'agni.c')
-rw-r--r--agni.c134
1 files changed, 16 insertions, 118 deletions
diff --git a/agni.c b/agni.c
index 4f8b220..1bf6799 100644
--- a/agni.c
+++ b/agni.c
@@ -143,119 +143,7 @@ tble_cmd_resp* cllbk_wrapper( void *(*call)(void *), tble_cmd_param *param)
return unique ID, with atomic counter should work in all cases
*/
_Atomic int _glbl_id=0;
-/*
-int uniq_id()
-{
- int ret=-1,id;
-
- //what possible could go wrong?
- // sry emilsp this is not important for now
- id = atomic_load(&_glbl_id);
- ret = id;
- id += 1;
- atomic_store(&_glbl_id, id);
- return ret;
-
-}
-*/
-
-
-/*
-int send_mq_cmd(mq_ntf_mdt *mq,
- int io,
- int cmd_id,
- char *cmd,
- size_t cmd_sz,
- char *param,
- size_t param_sz)
-{
- int err = 0;
- mq_cmd *cmd_send = NULL;
- cmd_send = mq_cmd_create(cmd_id,cmd,cmd_sz,param,param_sz);
- if (cmd_send == NULL)
- {
- printf("Cant create command\n");
- return -1;
- }
-
- err = -1;
- if (io == MQ_OUT)
- {
- err = mq_ntf_write(mq, MQ_OUT, cmd_send->buf, cmd_send->sz);
- } else if (io == MQ_IN)
- {
- err = mq_ntf_write(mq, MQ_IN, cmd_send->buf, cmd_send->sz);
- } else
- {
- printf("Unknown direction");
- return -1;
- }
-
- if (err == -1)
- {
- printf("Couldnt recieve command\n");
- mq_cmd_free(cmd_send);
- return -1;
- }
-
- mq_cmd_free(cmd_send);
-
- return 0;
-}
-
-int recv_mq_cmd(mq_ntf_mdt *mq,
- int io,
- mq_cmd **cmd) //return back recieved command
-{
- int err = 0;
- mq_cmd *cmd_recv = NULL;
- int recv_sz=-1;
- char *in_buf=NULL;
-
- in_buf = malloc(MQ_MSG_SIZE);
- if (in_buf == NULL)
- {
- ENL();
- return -1;
- }
-
- err = -1;
- if (io == MQ_OUT)
- {
- err = mq_ntf_read(mq, MQ_OUT, in_buf, MQ_MSG_SIZE);
- } else if (io == MQ_IN)
- {
- err = mq_ntf_read(mq, MQ_IN, in_buf, MQ_MSG_SIZE);
- } else
- {
- printf("Unknown direction");
- return -1;
- }
-
- if (err == -1)
- {
- printf("Couldnt recieve command\n");
- free(in_buf);
- return -1;
- }
- recv_sz = err;
-
- //in err should be still the size of recieved buffer
- cmd_recv = mq_cmd_creates(in_buf, recv_sz, 0);
- if (cmd_recv == NULL)
- {
- printf("Cannot create cmd\n");
- free(in_buf);
- return -1;
- }
-
- *cmd = cmd_recv;
- free(in_buf);
-
- return 0;
-}
-*/
#define SEND_CMD_IN(MQ,ID,CMD,PARAM) \
send_mq_cmd(MQ,MQ_IN,ID,CMD,strlen(CMD),PARAM,strlen(PARAM));
#define SEND_CMD_OUT(MQ,ID,CMD,PARAM) \
@@ -460,7 +348,7 @@ int th_start_client(void *data)
char *paramPtr;
size_t paramSz;
mq_cmd_param(recv_cmd, &paramPtr, &paramSz);
- printf("ID:%d Recieved response [%s]%d\n",mq_cmd_id(recv_cmd), paramPtr,paramSz);
+ printf("ID:%d Recieved response [%s]%zu\n",mq_cmd_id(recv_cmd), paramPtr, paramSz);
//wrong
tble_cmd_resp *match_resp = malloc(sizeof(tble_cmd_resp));
@@ -476,10 +364,11 @@ int th_start_client(void *data)
int cmd_id = tbl_qcmd_resp(qtbl, match_resp);
if (cmd_id > 0)
{
-
tble_qcmd *cmd = tbl_qcmd_match_id(qtbl, cmd_id);
if (cmd != NULL)
{
+
+ PRINT("Found ID in qcmd table %d\n", cmd_id);
char *resp_user = token_new_str(cmd->tok,0);
char *dest_user = token_new_str(cmd->tok,2);
char *sep = strchr(resp_user,'!');
@@ -505,8 +394,15 @@ int th_start_client(void *data)
write(conn, cmd_buf, fret);
}
- free(dest_user);
- free(resp_user);
+ free(dest_user); dest_user = NULL;
+ free(resp_user); resp_user = NULL;
+
+ //remove command by id
+ //for now just remove command without checkings its state
+ tbl_qcmd_del_by_id(qtbl, cmd_id); //no error check
+
+ //should be added proper command state check and so on
+ tbl_qcmd_mng_states(qtbl); // This should be runed regulary
}
}
@@ -527,7 +423,7 @@ int th_start_client(void *data)
}
- //recieve irc commands and pass to MQ
+ //recieve irc commands and pass to MQ, save command to table
//fix this by allowing drain just chunks, not whole buffer
//memset(conn_buf, 0, TH_CONN_BUF_SZ);
if((cret = read(conn,conn_buf, 256))>0)
@@ -605,7 +501,7 @@ int th_start_client(void *data)
//printf("FORMATED [%s]",cmd_buf);
//fret = write(conn,cmd_buf,fret2);
- //create cmd table command and set into table
+ //create cmd table command and add to table
qcmd = tbl_qcmd_cmd_c();
if (qcmd != NULL)
{
@@ -613,7 +509,9 @@ int th_start_client(void *data)
qcmd->state = QCMD_NONE;
qcmd->cmd = alloc_new_str("PRIVMSG");
qcmd->param = alloc_new_str(msg);
+ qcmd->timestamp = time(NULL);
tbl_qcmd_add_tok(qcmd, itok);
+ //HOW? add commands that are in execution list, dont process all messages
tbl_qcmd_add(qtbl, qcmd);
tbl_qcmd_print_tbl(qtbl,TBL_PF_QCMD_ID
|TBL_PF_QCMD_CID