Skip to content

Instantly share code, notes, and snippets.

@lukasz-pyrzyk
Last active March 17, 2016 17:36
Show Gist options
  • Save lukasz-pyrzyk/a0bce458ce1926f6969a to your computer and use it in GitHub Desktop.
Save lukasz-pyrzyk/a0bce458ce1926f6969a to your computer and use it in GitHub Desktop.
using System.Net;
using System.Net.Sockets;
namespace XGain.Sockets
{
internal class XGainSocket : ISocket
{
public int BufferSize => 65535;
public bool Connected => _socket.Connected;
public Socket InternalSocket => _socket;
public EndPoint LocalEndPoint => _socket.LocalEndPoint;
public EndPoint RemoteEndPoint => _socket.RemoteEndPoint;
private readonly Socket _socket;
public XGainSocket(
AddressFamily addressFamily,
SocketType socketType = SocketType.Stream,
ProtocolType protocolType = ProtocolType.Tcp,
bool noDelay = true,
int? buffer = null)
{
_socket = new Socket(addressFamily, socketType, protocolType)
{
SendBufferSize = buffer ?? BufferSize,
ReceiveBufferSize = buffer ?? BufferSize,
NoDelay = noDelay
};
}
public XGainSocket(Socket socket)
{
_socket = socket;
}
public ISocket Accept()
{
Socket client = _socket.Accept();
return new XGainSocket(client);
}
public void Bind(IPEndPoint localEndPoint)
{
_socket.Bind(localEndPoint);
}
public void Connect(IPEndPoint remoteEndPoint)
{
_socket.Connect(remoteEndPoint);
}
[...]
public void Dispose()
{
_socket.Dispose();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment