Ejemplo n.º 1
0
        // Override EntityBase's definition of Dispose to Dispose base class objects, but also the Socket object
        //   that is defined in this class.
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing)
            {
                ConnectionSocket.Close();
                ConnectionSocket.Dispose();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Closes the socket
 /// </summary>
 public void Dispose()
 {
     try
     {
         DataReceived = null;
         Disconnected = null;
         Close();
         if (ConnectionSocket != null)
         {
             ConnectionSocket.Dispose();
             ConnectionSocket = null;
         }
     }
     catch { }
 }
Ejemplo n.º 3
0
        private int AsyncReceive(out byte[] data, int timeout)
        {
            data = new byte[ReceiveBufferSize];

            IAsyncResult receiveResult = ConnectionSocket.BeginReceive(data, 0, ReceiveBufferSize, SocketFlags.None, null, null);

            bool success = false;

            if (timeout > 0)
            {
                success = receiveResult.AsyncWaitHandle.WaitOne(timeout, true);
            }
            else if (timeout == 0)
            {
                success = receiveResult.AsyncWaitHandle.WaitOne();
            }

            if (!success)
            {
                data = null;
                ConnectionSocket.Dispose();
                return(-1);
            }

            int size = ConnectionSocket.EndReceive(receiveResult);

            if (size > 0)
            {
                TrimData(ref data, size);
            }
            else
            {
                data = null;
            }

            return(size);
        }