- if (rpc->insize > rpc->inpos) {
- memcpy(buf, rpc->inbuf + rpc->inpos, rpc->insize - rpc->inpos);
- rpc->insize -= rpc->inpos;
- rpc->inpos = 0;
+
+ /* read record marker, 4 bytes at the beginning of every pdu */
+ if (rpc->inbuf == NULL) {
+ rpc->insize = 4;
+ rpc->inbuf = malloc(rpc->insize);
+ if (rpc->inbuf == NULL) {
+ rpc_set_error(rpc, "Failed to allocate buffer for record marker, errno:%d. Closing socket.", errno);
+ return -1;
+ }