Working an message handling ...

FossilOrigin-Name: 0003352d0d85b794da58c08fffb0df1066a808b63b060b28cff74b4c87ca675b
This commit is contained in:
7u83@mail.ru 2014-08-22 06:21:38 +00:00
parent 8c77dec5a3
commit b68642eec4
4 changed files with 44 additions and 27 deletions

View File

@ -36,6 +36,11 @@
#define CLIENT_IP (sock_addrtostr((struct sockaddr*)&wtpman->conn->addr, (char[64]){0},64)) #define CLIENT_IP (sock_addrtostr((struct sockaddr*)&wtpman->conn->addr, (char[64]){0},64))
void conn_handle_echo_request(struct conn * conn)
{
struct cwrmsg * cwrmsg = &conn->cwrmsg;
cwsend_echo_response(conn,cwrmsg->seqnum,0);
}
static struct cwrmsg * conn_wait_for_message(struct conn * conn, time_t timer) static struct cwrmsg * conn_wait_for_message(struct conn * conn, time_t timer)
@ -45,10 +50,7 @@ static struct cwrmsg * conn_wait_for_message(struct conn * conn, time_t timer)
cwrmsg = conn_get_message(conn); cwrmsg = conn_get_message(conn);
if (cwrmsg){ if (cwrmsg){
if (cwrmsg->type == CWMSG_ECHO_REQUEST){ if (cwrmsg->type == CWMSG_ECHO_REQUEST){
printf("Echo reponse\n"); conn_handle_echo_request(conn);
cwsend_echo_response(conn,cwrmsg->seqnum,0);
printf("continue\n");
cwrmsg=0;
continue; continue;
} }
} }
@ -61,7 +63,6 @@ static struct cwrmsg * conn_wait_for_message(struct conn * conn, time_t timer)
}while(!cwrmsg); }while(!cwrmsg);
printf("Nw here\n");
cw_dbg(DBG_CW_MSG,"Received message from %s, type=%d - %s" cw_dbg(DBG_CW_MSG,"Received message from %s, type=%d - %s"
,sock_addr2str(&conn->addr),cwrmsg->type,cw_msgtostr(cwrmsg->type)); ,sock_addr2str(&conn->addr),cwrmsg->type,cw_msgtostr(cwrmsg->type));
@ -203,6 +204,19 @@ static void wtpman_run_discovery(void *arg)
} }
static void wtpman_run_run(void *arg)
{
struct wtpman * wtpman = (struct wtpman *)arg;
while(1){
time_t t = cw_timer_start(10);
conn_wait_for_message(wtpman->conn,t);
}
}
static void wtpman_run(void *arg) static void wtpman_run(void *arg)
{ {
struct wtpman * wtpman = (struct wtpman *)arg; struct wtpman * wtpman = (struct wtpman *)arg;
@ -330,11 +344,12 @@ static void wtpman_run(void *arg)
if (cwrmsg){ if (cwrmsg){
if (cwrmsg->type == CWMSG_CHANGE_STATE_EVENT_REQUEST){ if (cwrmsg->type == CWMSG_CHANGE_STATE_EVENT_REQUEST){
int rc = cwread_change_state_event_request(&wtpman->wtpinfo,cwrmsg->msgelems,cwrmsg->msgelems_len); int rc = cwread_change_state_event_request(&wtpman->wtpinfo,cwrmsg->msgelems,cwrmsg->msgelems_len);
printf("Change state RC: %d\n",rc);
} }
} }
wtpman_run_run(wtpman);
exit(0); exit(0);

View File

@ -53,6 +53,9 @@ struct conn{
// int last_response_seqnum; // int last_response_seqnum;
// int last_response_rid; // int last_response_rid;
struct cwrmsg cwrmsg;
uint8_t cwrmsg_buffer[65536];
struct cwmsg req_msg; struct cwmsg req_msg;
struct cwmsg resp_msg; struct cwmsg resp_msg;

View File

@ -7,17 +7,22 @@
#include "conn.h" #include "conn.h"
#include "cwrmsg.h" #include "cwrmsg.h"
struct args{
struct conn * conn;
struct cwrmsg * cwrmsg;
};
static int pmessage(void *p, struct cwrmsg * cwrmsg)
static int pmessage(void *w, struct cwrmsg * cwrmsg)
{ {
uint8_t * buffer; struct args * args = (struct args*)p;
buffer = malloc( sizeof (struct cwrmsg) + cwrmsg->msgelems_len); struct conn * conn = args->conn;
memcpy(buffer,cwrmsg,sizeof(struct cwrmsg));
memcpy(buffer+sizeof(struct cwrmsg),cwrmsg->msgelems,cwrmsg->msgelems_len);
((struct cwrmsg*)(buffer))->msgelems=buffer+sizeof(struct cwrmsg); memcpy(&conn->cwrmsg,cwrmsg,sizeof(struct cwrmsg));
*((void**)w) = (void*)buffer; memcpy(conn->cwrmsg_buffer,cwrmsg->msgelems,cwrmsg->msgelems_len);
conn->cwrmsg.msgelems=conn->cwrmsg_buffer;
args->cwrmsg = &conn->cwrmsg;
return 0; return 0;
} }
@ -26,15 +31,16 @@ static int pmessage(void *w, struct cwrmsg * cwrmsg)
struct cwrmsg * conn_get_message(struct conn * conn) struct cwrmsg * conn_get_message(struct conn * conn)
{ {
struct cwrmsg * cwrmsg=0; struct args args;
args.cwrmsg=0;
uint8_t buf[2048]; args.conn=conn;
int len=2048; uint8_t buf[2024];
int len=2024;
int n = conn->read(conn,buf,len); int n = conn->read(conn,buf,len);
if (n>0) if (n>0)
conn_process_packet(conn,buf,n,pmessage,&cwrmsg); conn_process_packet(conn,buf,n,pmessage,&args);
return cwrmsg; return args.cwrmsg;
} }

View File

@ -4,7 +4,6 @@
#include "sock.h" #include "sock.h"
#include "cw_util.h" #include "cw_util.h"
#include <stdio.h>
struct cwrmsg * conn_get_response(struct conn * conn) struct cwrmsg * conn_get_response(struct conn * conn)
{ {
@ -14,11 +13,6 @@ struct cwrmsg * conn_get_response(struct conn * conn)
int type = cwmsg->type+1; int type = cwmsg->type+1;
printf ("Awaiting response message for type=%d\n",type);
struct cwrmsg * cwrmsg; struct cwrmsg * cwrmsg;
int i; int i;
@ -32,7 +26,6 @@ struct cwrmsg * conn_get_response(struct conn * conn)
cw_dbg(DBG_CW_MSG,"Received message from %s, type=%d - %s" cw_dbg(DBG_CW_MSG,"Received message from %s, type=%d - %s"
,sock_addr2str(&conn->addr),cwrmsg->type,cw_msgtostr(cwrmsg->type)); ,sock_addr2str(&conn->addr),cwrmsg->type,cw_msgtostr(cwrmsg->type));
if (cwrmsg->type == type){ if (cwrmsg->type == type){
printf("Jea!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11\n");
return cwrmsg; return cwrmsg;
} }