forked from unpbook/unpv13e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sctp_pdapircv.c
45 lines (41 loc) · 1.17 KB
/
sctp_pdapircv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "unp.h"
static uint8_t *sctp_pdapi_readbuf=NULL;
static int sctp_pdapi_rdbuf_sz=0;
uint8_t *
pdapi_recvmsg(int sock_fd,
int *rdlen,
SA *from,
int *from_len,
struct sctp_sndrcvinfo *sri,
int *msg_flags)
{
int rdsz,left,at_in_buf;
int frmlen=0;
if (sctp_pdapi_readbuf == NULL) {
sctp_pdapi_readbuf = (uint8_t *)Malloc(SCTP_PDAPI_INCR_SZ);
sctp_pdapi_rdbuf_sz = SCTP_PDAPI_INCR_SZ;
}
at_in_buf = Sctp_recvmsg(sock_fd, sctp_pdapi_readbuf, sctp_pdapi_rdbuf_sz,
from, from_len,
sri,msg_flags);
if(at_in_buf < 1){
*rdlen = at_in_buf;
return(NULL);
}
while((*msg_flags & MSG_EOR) == 0) {
left = sctp_pdapi_rdbuf_sz - at_in_buf;
if(left < SCTP_PDAPI_NEED_MORE_THRESHOLD) {
sctp_pdapi_readbuf = realloc(sctp_pdapi_readbuf, sctp_pdapi_rdbuf_sz+SCTP_PDAPI_INCR_SZ);
if(sctp_pdapi_readbuf == NULL) {
err_quit("sctp_pdapi ran out of memory");
}
sctp_pdapi_rdbuf_sz += SCTP_PDAPI_INCR_SZ;
left = sctp_pdapi_rdbuf_sz - at_in_buf;
}
rdsz = Sctp_recvmsg(sock_fd, &sctp_pdapi_readbuf[at_in_buf],
left, NULL, &frmlen, NULL, msg_flags);
at_in_buf += rdsz;
}
*rdlen = at_in_buf;
return(sctp_pdapi_readbuf);
}