diff options
| author | Luke <luke.pulverenti@gmail.com> | 2016-11-08 14:55:32 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-08 14:55:32 -0500 |
| commit | 82c46a84e4ce7419a92e6c5674de92d69b6ae11a (patch) | |
| tree | c7263a8e6aaf43680a2de2d3ae00be15be6cd1ad /Emby.Common.Implementations/Net/NetSocket.cs | |
| parent | a86e9fa73dd159db89efd2ae3e206f45a53c784c (diff) | |
| parent | e8c70da2b6044243d8352af8358dd701afe570e5 (diff) | |
Merge pull request #2277 from MediaBrowser/dev
Dev
Diffstat (limited to 'Emby.Common.Implementations/Net/NetSocket.cs')
| -rw-r--r-- | Emby.Common.Implementations/Net/NetSocket.cs | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/Emby.Common.Implementations/Net/NetSocket.cs b/Emby.Common.Implementations/Net/NetSocket.cs new file mode 100644 index 000000000..72faa41a9 --- /dev/null +++ b/Emby.Common.Implementations/Net/NetSocket.cs @@ -0,0 +1,85 @@ +using System; +using System.Net; +using System.Net.Sockets; +using System.Threading; +using Emby.Common.Implementations.Networking; +using MediaBrowser.Model.Net; +using MediaBrowser.Model.Logging; + +namespace Emby.Common.Implementations.Net +{ + public class NetSocket : ISocket + { + public Socket Socket { get; private set; } + private readonly ILogger _logger; + + public NetSocket(Socket socket, ILogger logger) + { + Socket = socket; + _logger = logger; + } + + public IpEndPointInfo LocalEndPoint + { + get + { + return BaseNetworkManager.ToIpEndPointInfo((IPEndPoint)Socket.LocalEndPoint); + } + } + + public IpEndPointInfo RemoteEndPoint + { + get + { + return BaseNetworkManager.ToIpEndPointInfo((IPEndPoint)Socket.RemoteEndPoint); + } + } + + public void Close() + { +#if NET46 + Socket.Close(); +#else + Socket.Dispose(); +#endif + } + + public void Shutdown(bool both) + { + if (both) + { + Socket.Shutdown(SocketShutdown.Both); + } + else + { + // Change interface if ever needed + throw new NotImplementedException(); + } + } + + public void Listen(int backlog) + { + Socket.Listen(backlog); + } + + public void Bind(IpEndPointInfo endpoint) + { + var nativeEndpoint = BaseNetworkManager.ToIPEndPoint(endpoint); + + Socket.Bind(nativeEndpoint); + } + + private SocketAcceptor _acceptor; + public void StartAccept(Action<ISocket> onAccept, Func<bool> isClosed) + { + _acceptor = new SocketAcceptor(_logger, Socket, onAccept, isClosed); + + _acceptor.StartAccept(); + } + + public void Dispose() + { + Socket.Dispose(); + } + } +} |
