Ejemplo n.º 1
0
        // Functionality:
        //    Read a block of data from file and insert it into the sending list.
        // Parameters:
        //    0) [in] ifs: input file stream.
        //    1) [in] len: size of the block.
        // Returned value:
        //    actual size of data added from the file.

        public int addBufferFromFile(Stream ifs, int len)
        {
            int size = len / m_iMSS;
            if ((len % m_iMSS) != 0)
                size++;

            // dynamically increase sender buffer
            while (size + m_iCount >= m_iSize)
                increase();

            Block s = m_pLastBlock;
            int total = 0;
            for (int i = 0; i < size; ++i)
            {
                if (ifs.bad() || ifs.fail() || ifs.eof())
                    break;

                int pktlen = len - i * m_iMSS;
                if (pktlen > m_iMSS)
                    pktlen = m_iMSS;

                ifs.Read(s.m_pcData, 0, pktlen);
                if ((pktlen = ifs.gcount()) <= 0)
                    break;

                s.m_iLength = pktlen;
                s.m_iTTL = -1;
                s = s.m_pNext;

                total += pktlen;
            }
            m_pLastBlock = s;

            lock (m_BufLock)
            {
                m_iCount += size;
            }

            return total;
        }