/// <summary> /// Transfer data from this socket to the destination socket /// until this socket closes /// </summary> /// <returns>The number of bytes sent</returns> public uint TunnelDataTo(HttpSocket dest) { uint total_sent = 0; try { if (AvailableData == 0) { ReadRaw(); } while (AvailableData > 0) { uint sent = dest.WriteBinary(Buffer, BufferPosition, AvailableData); if (sent < AvailableData) { throw new IoBroken(); } total_sent += sent; ReadRaw(); } } catch (SocketException) { /* ignore */ } return(total_sent); }
/// <summary> /// Tunnel a HTTP-chunked blob of data /// </summary> /// <param name="dest">The destination socket</param> /// <remarks> /// The tunneling stops when the last chunk, identified by a /// size of 0, arrives. The optional trailing entities are also /// transmitted (but otherwise ignored). /// </remarks> public void TunnelChunkedDataTo(HttpSocket dest) { TunnelChunkedDataTo(dest, (byte[] b, uint o, uint s) => { if (dest.WriteBinary(b, o, s) < s) { throw new IoBroken(); } }); }
/// <summary> /// Read <c>nb_bytes</c> bytes from the socket, /// and send it to the destination socket /// </summary> /// <returns>The number of bytes sent</returns> public uint TunnelDataTo(HttpSocket dest, uint nb_bytes) { return(TunnelDataTo((byte[] b, uint o, uint s) => { if (dest.WriteBinary(b, o, s) < s) { throw new IoBroken(); } }, nb_bytes)); }