2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "conn.h"
|
|
|
|
#include "cwrmsg.h"
|
|
|
|
|
2014-08-22 08:21:38 +02:00
|
|
|
struct args{
|
|
|
|
struct conn * conn;
|
|
|
|
struct cwrmsg * cwrmsg;
|
|
|
|
};
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2014-08-22 08:21:38 +02:00
|
|
|
static int pmessage(void *p, struct cwrmsg * cwrmsg)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2014-08-22 08:21:38 +02:00
|
|
|
struct args * args = (struct args*)p;
|
|
|
|
struct conn * conn = args->conn;
|
|
|
|
|
2014-08-18 07:30:21 +02:00
|
|
|
|
2014-08-22 08:21:38 +02:00
|
|
|
|
|
|
|
memcpy(&conn->cwrmsg,cwrmsg,sizeof(struct cwrmsg));
|
|
|
|
memcpy(conn->cwrmsg_buffer,cwrmsg->msgelems,cwrmsg->msgelems_len);
|
|
|
|
conn->cwrmsg.msgelems=conn->cwrmsg_buffer;
|
|
|
|
args->cwrmsg = &conn->cwrmsg;
|
2014-07-11 22:12:11 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct cwrmsg * conn_get_message(struct conn * conn)
|
|
|
|
{
|
2014-08-22 08:21:38 +02:00
|
|
|
struct args args;
|
|
|
|
args.cwrmsg=0;
|
|
|
|
args.conn=conn;
|
|
|
|
uint8_t buf[2024];
|
|
|
|
int len=2024;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2014-08-16 10:01:15 +02:00
|
|
|
int n = conn->read(conn,buf,len);
|
|
|
|
if (n>0)
|
2014-08-22 08:21:38 +02:00
|
|
|
conn_process_packet(conn,buf,n,pmessage,&args);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2014-08-22 08:21:38 +02:00
|
|
|
return args.cwrmsg;
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|