| 1641 | } |
| 1642 | |
| 1643 | bool REMOTE_deflate(RemoteXdr* xdrs, ProtoWrite* proto_write, PacketSend* packet_send, bool flush) |
| 1644 | { |
| 1645 | rem_port* port = xdrs->x_public; |
| 1646 | port->bumpLogBytes(rem_port::SEND, xdrs->x_private - xdrs->x_base); |
| 1647 | |
| 1648 | #ifdef WIRE_COMPRESS_SUPPORT |
| 1649 | if (!(port->port_compressed && (port->port_flags & PORT_compressed))) |
| 1650 | return proto_write(xdrs); |
| 1651 | |
| 1652 | z_stream& strm = port->port_send_stream; |
| 1653 | strm.avail_in = xdrs->x_private - xdrs->x_base; |
| 1654 | strm.next_in = (Bytef*) xdrs->x_base; |
| 1655 | |
| 1656 | if (!strm.next_out) |
| 1657 | { |
| 1658 | strm.avail_out = port->port_buff_size; |
| 1659 | strm.next_out = (Bytef*) &port->port_compressed[REM_SEND_OFFSET(port->port_buff_size)]; |
| 1660 | } |
| 1661 | |
| 1662 | bool expectMoreOut = flush; |
| 1663 | |
| 1664 | while (strm.avail_in || expectMoreOut) |
| 1665 | { |
| 1666 | #ifdef COMPRESS_DEBUG |
| 1667 | fprintf(stderr, "Data to deflate %d port %p\n", strm.avail_in, port); |
| 1668 | #if COMPRESS_DEBUG>1 |
| 1669 | for (unsigned n = 0; n < strm.avail_in; ++n) fprintf(stderr, "%02x ", strm.next_in[n]); |
| 1670 | fprintf(stderr, "\n"); |
| 1671 | #endif |
| 1672 | #endif |
| 1673 | int ret = zlib().deflate(&strm, flush ? Z_SYNC_FLUSH : Z_NO_FLUSH); |
| 1674 | if (ret == Z_BUF_ERROR) |
| 1675 | ret = 0; |
| 1676 | if (ret != 0) |
| 1677 | { |
| 1678 | #ifdef COMPRESS_DEBUG |
| 1679 | fprintf(stderr, "Deflate error %d\n", ret); |
| 1680 | #endif |
| 1681 | return false; |
| 1682 | } |
| 1683 | |
| 1684 | #ifdef COMPRESS_DEBUG |
| 1685 | fprintf(stderr, "Deflated data %d\n", port->port_buff_size - strm.avail_out); |
| 1686 | #if COMPRESS_DEBUG>1 |
| 1687 | for (unsigned n = 0; n < port->port_buff_size - strm.avail_out; ++n) |
| 1688 | fprintf(stderr, "%02x ", port->port_compressed[REM_SEND_OFFSET(port->port_buff_size) + n]); |
| 1689 | fprintf(stderr, "\n"); |
| 1690 | #endif |
| 1691 | #endif |
| 1692 | |
| 1693 | expectMoreOut = !strm.avail_out; |
| 1694 | if ((port->port_buff_size != strm.avail_out) && (flush || !strm.avail_out)) |
| 1695 | { |
| 1696 | #if COMPRESS_DEBUG > 1 |
| 1697 | fprintf(stderr, "Send packet %d bytes size\n", port->port_buff_size - strm.avail_out); |
| 1698 | #endif |
| 1699 | if (!packet_send(port, (SCHAR*) &port->port_compressed[REM_SEND_OFFSET(port->port_buff_size)], |
| 1700 | (SSHORT) (port->port_buff_size - strm.avail_out))) |
no test coverage detected