/// <summary> /// Creates a new AsyncSocket. You must call Start() after creating the AsyncSocket /// in order to begin receive data. /// </summary> internal AsyncTcpSocket(Socket socket, IPEndPoint remoteEndpoint, IPEndPoint localEndpoint, Action <byte[], int> onReceive, Action <Exception> onError) { Socket = socket; OnReceive = onReceive; OnError = onError; RemoteEndPoint = remoteEndpoint; LocalEndPoint = localEndpoint; _sendLock = new Lock(); _readLock = new Lock(); _callbackLock = new Lock(); _sendBuffer = new Shared <BufferQueue>(new BufferQueue()); _syncLock = new LockReadWrite(); _receivedBuffer = new Shared <BufferQueue>(new BufferQueue()); _onReceive = new ActionSequence(); _callbacks = new Queue <Teple <int, IAction> >(); _sendSocketArgs = SocketEventArgsCache.AllocateForSend(OnSocketSend); _sendSocketArgs.SendPacketsFlags = TransmitFileOptions.UseKernelApc | TransmitFileOptions.UseSystemThread; _sendSocketArgs.RemoteEndPoint = RemoteEndPoint; _disposing = false; }
/// <summary> /// Creates a new AsyncSocket. You must call Start() after creating the AsyncSocket /// in order to begin receive data. /// </summary> internal AsyncUdpSocket(Socket socket, IPEndPoint localEndpoint, Action <IPEndPoint, byte[], int> onReceive, Action <Exception> onError) { Socket = socket; OnReceive = onReceive; OnError = onError; LocalEndPoint = localEndpoint; RemoteEndPoint = new IPEndPoint(IPAddress.Any, 0); TargetEndPoint = RemoteEndPoint; _sendLock = new Lock(); _readLock = new Lock(); _enqueueBuffer = new BufferQueue(); _sendQueue = new Shared <ArrayRig <QueuedBuffer> >(new ArrayRig <QueuedBuffer>()); _syncLock = new LockReadWrite(); _onReceive = new ActionSequence(); _receiveBuffer = BufferCache.Get(); _receivedChunks = new Dictionary <int, ChunkedGram>(); _disposing = false; }