Peek option for conn_q_recv_packet.
FossilOrigin-Name: 07b2fd4eeb2a5d3858567a1c2168efdc1e4b3e782b7ce10153cb7773bb093ac1
This commit is contained in:
parent
0066114eda
commit
be69873d1c
@ -22,11 +22,10 @@
|
|||||||
|
|
||||||
#include "conn.h"
|
#include "conn.h"
|
||||||
|
|
||||||
int conn_q_recv_packet(struct conn * conn, uint8_t * buffer,int len)
|
static int conn_q_recv_packet_(struct conn * conn, uint8_t * buffer,int len,int peek)
|
||||||
{
|
{
|
||||||
if ( !conn->cur_packet)
|
if ( !conn->cur_packet)
|
||||||
{
|
{
|
||||||
/* while ((conn->cur_packet = conn_q_get_packet(conn)) == 0){*/
|
|
||||||
if ((conn->cur_packet = conn_q_get_packet(conn)) == 0){
|
if ((conn->cur_packet = conn_q_get_packet(conn)) == 0){
|
||||||
errno = EAGAIN;
|
errno = EAGAIN;
|
||||||
return -1;
|
return -1;
|
||||||
@ -38,14 +37,35 @@ int conn_q_recv_packet(struct conn * conn, uint8_t * buffer,int len)
|
|||||||
if (conn->cur_packet_len > len )
|
if (conn->cur_packet_len > len )
|
||||||
{
|
{
|
||||||
memcpy(buffer,conn->cur_packet+conn->cur_packet_pos,len);
|
memcpy(buffer,conn->cur_packet+conn->cur_packet_pos,len);
|
||||||
|
if (peek)
|
||||||
|
return len;
|
||||||
|
|
||||||
conn->cur_packet_pos+=len;
|
conn->cur_packet_pos+=len;
|
||||||
conn->cur_packet_len-=len;
|
conn->cur_packet_len-=len;
|
||||||
|
if (conn->cur_packet_len==0){
|
||||||
|
free(conn->cur_packet);
|
||||||
|
conn->cur_packet=0;
|
||||||
|
}
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buffer,conn->cur_packet+conn->cur_packet_pos,conn->cur_packet_len);
|
memcpy(buffer,conn->cur_packet+conn->cur_packet_pos,conn->cur_packet_len);
|
||||||
|
if (peek)
|
||||||
|
return conn->cur_packet_len;
|
||||||
|
|
||||||
free (conn->cur_packet);
|
free (conn->cur_packet);
|
||||||
conn->cur_packet=0;
|
conn->cur_packet=0;
|
||||||
return conn->cur_packet_len;
|
return conn->cur_packet_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int conn_q_recv_packet(struct conn * conn, uint8_t * buffer,int len)
|
||||||
|
{
|
||||||
|
return conn_q_recv_packet_(conn,buffer,len,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int conn_q_recv_packet_peek(struct conn * conn, uint8_t * buffer,int len)
|
||||||
|
{
|
||||||
|
return conn_q_recv_packet_(conn,buffer,len,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user