sctp_pdapircv.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "unp.h"
  2. static uint8_t *sctp_pdapi_readbuf=NULL;
  3. static int sctp_pdapi_rdbuf_sz=0;
  4. uint8_t *
  5. pdapi_recvmsg(int sock_fd,
  6. int *rdlen,
  7. SA *from,
  8. int *from_len,
  9. struct sctp_sndrcvinfo *sri,
  10. int *msg_flags)
  11. {
  12. int rdsz,left,at_in_buf;
  13. int frmlen=0;
  14. if (sctp_pdapi_readbuf == NULL) {
  15. sctp_pdapi_readbuf = (uint8_t *)Malloc(SCTP_PDAPI_INCR_SZ);
  16. sctp_pdapi_rdbuf_sz = SCTP_PDAPI_INCR_SZ;
  17. }
  18. at_in_buf = Sctp_recvmsg(sock_fd, sctp_pdapi_readbuf, sctp_pdapi_rdbuf_sz,
  19. from, from_len,
  20. sri,msg_flags);
  21. if(at_in_buf < 1){
  22. *rdlen = at_in_buf;
  23. return(NULL);
  24. }
  25. while((*msg_flags & MSG_EOR) == 0) {
  26. left = sctp_pdapi_rdbuf_sz - at_in_buf;
  27. if(left < SCTP_PDAPI_NEED_MORE_THRESHOLD) {
  28. sctp_pdapi_readbuf = realloc(sctp_pdapi_readbuf, sctp_pdapi_rdbuf_sz+SCTP_PDAPI_INCR_SZ);
  29. if(sctp_pdapi_readbuf == NULL) {
  30. err_quit("sctp_pdapi ran out of memory");
  31. }
  32. sctp_pdapi_rdbuf_sz += SCTP_PDAPI_INCR_SZ;
  33. left = sctp_pdapi_rdbuf_sz - at_in_buf;
  34. }
  35. rdsz = Sctp_recvmsg(sock_fd, &sctp_pdapi_readbuf[at_in_buf],
  36. left, NULL, &frmlen, NULL, msg_flags);
  37. at_in_buf += rdsz;
  38. }
  39. *rdlen = at_in_buf;
  40. return(sctp_pdapi_readbuf);
  41. }