Exemplo n.º 1
0
        void startRcv()
        {
            Association me = this;

            _rcv = new Thread(() =>
            {
                try
                {
                    byte[] buf = new byte[_transp.GetReceiveLimit()];
                    while (_rcv != null)
                    {
                        try
                        {
                            int length = _transp.Receive(buf, 0, buf.Length, TICK);
                            if (length == DtlsSrtpTransport.DTLS_RECEIVE_ERROR_CODE)
                            {
                                // The DTLS transport has been closed or i no longer available.
                                break;
                            }
                            //logger.LogDebug("SCTP message received: " + Packet.getHex(buf, 0, length));
                            ByteBuffer pbb = new ByteBuffer(buf);
                            pbb.Limit      = length;
                            Packet rec     = new Packet(pbb);
                            deal(rec);
                        }
                        catch (SocketException e)
                        {
                            // ignore. it should be a timeout.
                            switch (e.SocketErrorCode)
                            {
                            case SocketError.TimedOut:
                                logger.LogDebug("tick time out");
                                break;

                            default:
                                throw e;
                            }
                        }
                    }
                    logger.LogDebug("SCTP message receive was empty, closing association listener.");

                    _transp.Close();
                }
                catch (EndOfStreamException eof)
                {
                    unexpectedClose(eof);
                    logger.LogDebug(eof.ToString());
                }
                catch (Exception ex)
                {
                    logger.LogDebug("Association receive failed " + ex.GetType().Name + " " + ex.ToString());
                }
            });
            _rcv.Priority = ThreadPriority.AboveNormal;
            _rcv.Name     = "AssocRcv" + __assocNo;
            _rcv.Start();
        }
Exemplo n.º 2
0
        void startRcv()
        {
            Association me = this;

            _rcv = new Thread(() => {
                try {
                    byte[] buf = new byte[_transp.GetReceiveLimit()];
                    while (_rcv != null)
                    {
                        try {
                            int length = _transp.Receive(buf, 0, buf.Length, TICK);
                            if (length == -1)
                            {
                                Logger.Trace("Probably tick time out");
                                continue;
                            }
                            Logger.Trace("DTLS message received\n" + Packet.getHex(buf, 0, length));
                            ByteBuffer pbb = new ByteBuffer(buf);
                            pbb.Limit      = length;
                            Packet rec     = new Packet(pbb);
                            Logger.Debug("SCTP message parsed\n" + rec.ToString());
                            deal(rec);
                        }
                        catch (SocketException e) {
                            // ignore. it should be a timeout.
                            switch (e.SocketErrorCode)
                            {
                            case SocketError.TimedOut:
                                Logger.Trace("tick time out");
                                break;

                            default:
                                throw e;
                            }
                        }
                    }
                    Logger.Trace("SCTP message recv null\n Shutting down.");

                    _transp.Close();
                }
                catch (EndOfStreamException eof) {
                    unexpectedClose(eof);
                    Logger.Debug(eof.ToString());
                }
                catch (Exception ex) {
                    Logger.Debug("Association rcv failed " + ex.GetType().Name + " " + ex.ToString());
                }
            });
            _rcv.Priority = ThreadPriority.AboveNormal;
            _rcv.Name     = "AssocRcv" + __assocNo;
            _rcv.Start();
        }
Exemplo n.º 3
0
        private void CloseTransport()
        {
            if (!mClosed)
            {
                /*
                 * RFC 5246 7.2.1. Unless some other fatal alert has been transmitted, each party is
                 * required to send a close_notify alert before closing the write side of the
                 * connection. The other party MUST respond with a close_notify alert of its own and
                 * close down the connection immediately, discarding any pending writes.
                 */

                try
                {
                    if (!mFailed)
                    {
                        Warn(AlertDescription.close_notify, null);
                    }
                    mTransport.Close();
                }
                catch (Exception)
                {
                    // Ignore
                }

                mClosed = true;
            }
        }
Exemplo n.º 4
0
 private void CloseTransport()
 {
     if (mClosed)
     {
         return;
     }
     try
     {
         if (!mFailed)
         {
             Warn(0, null);
         }
         mTransport.Close();
     }
     catch (global::System.Exception)
     {
     }
     mClosed = true;
 }
Exemplo n.º 5
0
 public virtual void Close()
 {
     transport.Close();
 }