aboutsummaryrefslogtreecommitdiff
path: root/Emby.Common.Implementations/Net/SocketFactory.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2017-05-25 09:00:55 -0400
committerGitHub <noreply@github.com>2017-05-25 09:00:55 -0400
commit40bc3b7b2205d7bc0802cf81bf199c655b81efd7 (patch)
treece7efa462a2620c3d2eddeaec41464ac3959f50c /Emby.Common.Implementations/Net/SocketFactory.cs
parent2715db6ad794588614a2585a51d1cfde6d8e2941 (diff)
parentb527e56ec3b7d644245b2a2b6bd39c1e2a375c83 (diff)
Merge pull request #2664 from MediaBrowser/dev
Dev
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);
+ }
+ }
+
}