static int su_peer_reply_act(su_peer_t *psar, const void *outbuff, int outbytes) { if (psar->nowsynframe == 0) { err_msg("peer %x is no request data"); return -1; } int n; struct iovec iovsend[2] = {{0}}; struct msghdr msgsend = {0}; /* assumed init to 0 */ frames_t *frame = psar->nowsynframe; suhdr_t answerhdr = frame->recvhdr; answerhdr.act = SU_ACK; msgsend.msg_name = (void*)&frame->srcaddr; msgsend.msg_namelen = frame->srclen; msgsend.msg_iov = &iovsend[0]; msgsend.msg_iovlen = 2; iovsend[0].iov_base = &answerhdr; iovsend[0].iov_len = sizeof(suhdr_t); iovsend[1].iov_base = (void*)outbuff; iovsend[1].iov_len = outbytes; if (answerhdr.type == SU_RELIABLE) { if (reliable_ack___save(psar, outbuff, outbytes) < 0) { err_ret("reliable_ack___save error"); return -1; } } n = sendmsg(psar->fd, &msgsend, 0); if (n != sizeof(suhdr_t) + outbytes) { err_ret("sendmsg error"); return(-1); } return(outbytes); }
static int su_serv_reply_act(su_serv_t *psvr, const frames_t *frame, const void *outbuff, int outbytes) { int n; struct iovec iovsend[2] = {{0}}; struct msghdr msgsend = {0}; /* assumed init to 0 */ suhdr_t answerhdr = frame->recvhdr; answerhdr.act = SU_ACK; msgsend.msg_name = (void*)&frame->srcaddr; msgsend.msg_namelen = frame->srclen; msgsend.msg_iov = &iovsend[0]; msgsend.msg_iovlen = 2; iovsend[0].iov_base = &answerhdr; iovsend[0].iov_len = sizeof(suhdr_t); iovsend[1].iov_base = (void*)outbuff; iovsend[1].iov_len = outbytes; if (answerhdr.type == SU_RELIABLE) { pthread_mutex_lock(&psvr->cachelock); if (reliable_ack___save(psvr, frame, outbuff, outbytes) < 0) { pthread_mutex_unlock(&psvr->cachelock); err_ret("reliable_ack___save error"); return -1; } pthread_mutex_unlock(&psvr->cachelock); } n = sendmsg(psvr->fd, &msgsend, 0); if (n != sizeof(suhdr_t) + outbytes) { err_ret("sendmsg error"); return(-1); } return(outbytes); }