/* send response in two parts 1) ProxyHeader 2) Response or error status This function should be called with marshaled response send_response constructs header part and error part only. send response sends {ProxyHeader,Response} if the request was success otherwise sends {ProxyHeader,error status}  */
static int send_response(int sock, struct iovec *iovec, int size)
/* send response in two parts 1) ProxyHeader 2) Response or error status This function should be called with marshaled response send_response constructs header part and error part only. send response sends {ProxyHeader,Response} if the request was success otherwise sends {ProxyHeader,error status}  */
static int send_response(int sock, struct iovec *iovec, int size)
{
    int retval;
    ProxyHeader header;
    if (size > PROXY_MAX_IO_SZ) {
        size = -ENOBUFS;
    }
    if (size < 0) {
        header.type = T_ERROR;
        header.size = sizeof(size);
        proxy_marshal(iovec, PROXY_HDR_SZ, "d", size);
    } else {
        header.type = T_SUCCESS;
        header.size = size;
    }
    proxy_marshal(iovec, 0, "dd", header.type, header.size);
    retval = socket_write(sock, iovec->iov_base, header.size + PROXY_HDR_SZ);
    if (retval < 0) {
        return retval;
    }
    return 0;
}