aboutsummaryrefslogtreecommitdiff
path: root/Emby.Common.Implementations/Net/SocketFactory.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2017-05-25 09:00:14 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2017-05-25 09:00:14 -0400
commit28988b056ccc8efad54905b6f10ff0b9532c7130 (patch)
treee5ef1b92cf28b884bb03bbfd67112a25e48a4fe7 /Emby.Common.Implementations/Net/SocketFactory.cs
parentd035d7eaec937b1ad43af6a95f723070c1e847ea (diff)
update stream copying
Diffstat (limited to 'Emby.Common.Implementations/Net/SocketFactory.cs')
-rw-r--r--Emby.Common.Implementations/Net/SocketFactory.cs85
1 files changed, 85 insertions, 0 deletions
diff --git a/Emby.Common.Implementations/Net/SocketFactory.cs b/Emby.Common.Implementations/Net/SocketFactory.cs
index 3562a8644..0a1232a40 100644
--- a/Emby.Common.Implementations/Net/SocketFactory.cs
+++ b/Emby.Common.Implementations/Net/SocketFactory.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
@@ -208,5 +209,89 @@ namespace Emby.Common.Implementations.Net
throw;
}
}
+
+ public Stream CreateNetworkStream(ISocket socket, bool ownsSocket)
+ {
+ var netSocket = (UdpSocket)socket;
+
+ return new SocketStream(netSocket.Socket, ownsSocket);
+ }
}
+
+ public class SocketStream : Stream
+ {
+ private readonly Socket _socket;
+
+ public SocketStream(Socket socket, bool ownsSocket)
+ {
+ _socket = socket;
+ }
+
+ public override void Flush()
+ {
+ }
+
+ public override bool CanRead
+ {
+ get { return true; }
+ }
+ public override bool CanSeek
+ {
+ get { return false; }
+ }
+ public override bool CanWrite
+ {
+ get { return true; }
+ }
+ public override long Length
+ {
+ get { throw new NotImplementedException(); }
+ }
+ public override long Position
+ {
+ get { throw new NotImplementedException(); }
+ set { throw new NotImplementedException(); }
+ }
+
+ public override void Write(byte[] buffer, int offset, int count)
+ {
+ _socket.Send(buffer, offset, count, SocketFlags.None);
+ }
+
+ public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
+ {
+ return _socket.BeginSend(buffer, offset, count, SocketFlags.None, callback, state);
+ }
+
+ public override void EndWrite(IAsyncResult asyncResult)
+ {
+ _socket.EndSend(asyncResult);
+ }
+
+ public override void SetLength(long value)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override long Seek(long offset, SeekOrigin origin)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override int Read(byte[] buffer, int offset, int count)
+ {
+ return _socket.Receive(buffer, offset, count, SocketFlags.None);
+ }
+
+ public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
+ {
+ return _socket.BeginReceive(buffer, offset, count, SocketFlags.None, callback, state);
+ }
+
+ public override int EndRead(IAsyncResult asyncResult)
+ {
+ return _socket.EndReceive(asyncResult);
+ }
+ }
+
}