/// <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> /// 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, System.Threading.CancellationToken cancelToken) { uint total_sent = 0; try { if (AvailableData == 0) { ReadRaw(); } while (AvailableData > 0 && !cancelToken.IsCancellationRequested) { 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)); }
/// <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); }
/// <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> /// Transfer data from the socket to the specified packet handler with Async Mode /// This is Just For A SSL Tunneling /// </summary> /// <returns>The number of bytes sent</returns> public IAsyncResult TunnelDataAsyncTo(HttpSocket dest) { byte[] buffer = new byte[4096]; IAsyncResult Result = LowLevelSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback((ar) => { try { int Ret = (int)ar.AsyncState; Ret = LowLevelSocket.EndReceive(ar); if (Ret > 0) { dest.WriteBinary(buffer, 0, (uint)Ret); } else { CloseSocket(); } } catch { } }), new int()); return Result; }