Vitezslav Samel <vitezslav(a)samel.cz> writes:
There's no need to initialize every struct msghdr member before
every recvmsg(); move this struct to struct pkt_hdr, make it
allocated from heap and move unnecessary initializations
to packet_init().
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/packet.c | 26 +++++++++++++++++---------
src/packet.h | 1 +
2 files changed, 18 insertions(+), 9 deletions(-)
pkt->from = xmallocz(sizeof(*pkt->from));
+ pkt->msg = xmallocz(sizeof(*pkt->msg));
+
+ pkt->msg->msg_name = pkt->from;
+ pkt->msg->msg_namelen = sizeof(*pkt->from);
+ pkt->msg->msg_iov = &pkt->iov;
+ pkt->msg->msg_iovlen = 1;
+ pkt->msg->msg_control = NULL;
return 0; /* all O.K. */
}
void packet_destroy(struct pkt_hdr *pkt)
{
+ if (pkt->msg)
+ free(pkt->msg);
ditto with check and xmallocz
--
Nikola