src/Azos/Glue/Native/MpxBinding.cs
/// <summary>
/// Fetches available existing chunk from cache or creates a new one.
/// Called by new sockets by incipient connections
/// </summary>
Fetches available existing chunk from cache or creates a new one.
Called by new sockets by incipient connections
Fetches available existing chunk from cache or creates a new one . Called by new sockets by incipient connections
internal MemChunk MakeOrReuseChunk()
          {
            var chunks = m_Chunks;
            MemChunk chunk = null;
            if (chunks!=null)
            {
              var now = App.TimeSource.UTCNow;
              lock(m_Chunks)
              {
                 for(var i=0; i<m_Chunks.Count; i++)
                 {
                    chunk = m_Chunks[i];
                    if (chunk.Acquired) continue;
                    if ((now - chunk._LastReleaseUtc).TotalSeconds >= CHUNK_DORMANT_PERIOD_SEC) 
                    {                                                                           
                      chunk.Acquired = true;
                      return chunk;
                    }
                 }
              }
            }
            chunk =  new MemChunk(Consts.DEFAULT_SERIALIZER_STREAM_CAPACITY);
            return chunk;
          }
internal MemChunk MakeOrReuseChunk ( ) { var chunks = m_Chunks ; MemChunk chunk = null ; if ( chunks != null ) { var now = App . TimeSource . UTCNow ; lock ( m_Chunks ) { for ( var i = 0 ; i < m_Chunks . Count ; i ++ ) { chunk = m_Chunks [ i ] ; if ( chunk . Acquired ) continue ; if ( ( now - chunk . _LastReleaseUtc ) . TotalSeconds >= CHUNK_DORMANT_PERIOD_SEC ) { chunk . Acquired = true ; return chunk ; } } } } chunk = new MemChunk ( Consts . DEFAULT_SERIALIZER_STREAM_CAPACITY ) ; return chunk ; }
Fetches available existing chunk from cache or creates a new one.
Fetches available existing chunk from cache or creates a new one .
//since this method is called on new socket creation, it is OK to lock for short time //is already taken by some socket //chunk must be in the pool for the specified minimum 'rest' time // this is needed so all pending async socket operations timeout //otherwise create new chunk, no need to add it to pool here. The release will do it later (if ever called)