Esempio n. 1
0
        public void MarkDataSent(string filename, CCBP2PFileDataEnvelope data)
        {
            lock (m_outbox)
            {
                CCBP2PFile fileToSend = m_outbox[filename];

                if (null != fileToSend)
                {
                    fileToSend.MarkDataSent(data);
                }
            }
        }
Esempio n. 2
0
        public int RetrieveDataToSend(string filename, ref CCBP2PFileDataEnvelope data)
        {
            lock (m_outbox)
            {
                CCBP2PFile fileToSend = m_outbox[filename];

                if (null != fileToSend)
                {
                    return(fileToSend.RetrieveDataToSend(ref data));
                }
            }
            return(0);
        }
Esempio n. 3
0
        public int RetrieveDataToSend(ref CCBP2PFileDataEnvelope data)
        {
            try
            {
                if (m_bytesSent < m_offsetCur)
                {
                    int dataSize = (int)(m_offsetCur - m_bytesSent);

                    data = new CCBP2PFileDataEnvelope(m_bytesSent, dataSize, m_filesize,
                                                      m_recipient, m_localFile, m_remoteFile);
                    data.Put(m_data, dataSize);
                    return(dataSize);
                }
            }
            catch (Exception unex)
            {
                CCBLogConfig.GetLogger().Error("Unexpected exception in RetrieveDataToSend: {0}", unex.Message);
            }
            return(0);
        }
Esempio n. 4
0
        public void Listener()
        {
            WaitHandle[] waitors = new WaitHandle[3] {
                m_closeSignal, m_cmdSignal, m_filexferSignal
            };

            if (null == m_host)
            {
                m_host = new ServiceHost(this);
                m_host.Open();
            }
            while (m_working)
            {
                int ixSig = WaitHandle.WaitAny(waitors);

                if (0 == ixSig)
                {
                    break;
                }
                else if (1 == ixSig)
                {
                    ExecuteNextCommand();
                }
                else if ((2 == ixSig) && (null != m_clientChannel))
                {
                    CCBP2PFileWorker fileWorker = GetFileWorker();
                    string           fileToSend = fileWorker.HasUploadWork();

                    if (null != fileToSend)
                    {
                        CCBP2PFileDataEnvelope dataTosend = null;
                        int    cb        = fileWorker.RetrieveDataToSend(fileToSend, ref dataTosend);
                        byte[] hash      = null;
                        string recipient = null;

                        if ((0 != cb) && (null != dataTosend))
                        {
                            try
                            {
                                Debug(string.Format("Sending {0} bytes from {1}", cb, dataTosend.m_localFileName));
                                m_clientChannel.SendFileData(m_uid, dataTosend.m_recipient, dataTosend.m_localFileName, dataTosend.m_start, dataTosend.m_bytes);
                                fileWorker.MarkDataSent(fileToSend, dataTosend);
                                if (fileWorker.IsSent(fileToSend, ref hash, ref recipient))
                                {
                                    m_clientChannel.OnFileComplete(m_uid, recipient, dataTosend.m_localFileName, hash);
                                    fileWorker.FileFinalized(fileToSend);
                                }
                            }
                            catch (CommunicationException commEx)
                            {
                                Error("Exception sending file data: " + commEx.Message);
                                fileWorker.FileOnError(fileToSend);
                            }
                            catch (Exception ex)
                            {
                                Error("Exception sending file data: " + ex.Message);
                                fileWorker.FileOnError(fileToSend);
                            }
                        }
                        else if (fileWorker.IsSent(fileToSend, ref hash, ref recipient))
                        {
                            m_clientChannel.OnFileComplete(m_uid, recipient, fileToSend, hash);
                            fileWorker.FileFinalized(fileToSend);
                        }
                    }
                    if (fileWorker.HasWork())
                    {
                        if (m_closeSignal.WaitOne(73))
                        {
                            break;
                        }
                        while (CheckFileWorkerForErrors(fileWorker))
                        {
                            if (m_closeSignal.WaitOne(0))
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        m_filexferSignal.Reset();
                    }
                }
                else
                {
                    Fatal(string.Format("Error return waiting for handles in networker: {0}", ixSig));
                }
            }
            Close();
            m_peer.OnDisconnected();
            Debug("Chat listener thread exiting.");
        }
Esempio n. 5
0
 public void MarkDataSent(CCBP2PFileDataEnvelope data)
 {
     m_bytesSent += data.Size;
     m_tick       = DateTime.Now;
 }