public override void Start() { var sessionLogConfiguration = new SessionLogEntry.TConfiguration() { FileLength = -1, Filename = m_Filename, IsUpload = false, LocalEndPoint = m_LocalEndPoint, RemoteEndPoint = m_RemoteEndPoint, StartTime = DateTime.Now, WindowSize = m_WindowSize }; try { lock (m_Lock) { try { m_Stream = m_Parent.GetReadStream(m_Filename); m_Length = m_Stream.Length; sessionLogConfiguration.FileLength = m_Length; m_Position = 0; } catch (Exception e) { TFTPServer.SendError(m_Socket, m_RemoteEndPoint, TFTPServer.ErrorCode.FileNotFound, e.Message); throw; } finally { m_SessionLog = m_Parent.SessionLog.CreateSession(sessionLogConfiguration); } // handle tsize option if (m_RequestedOptions.ContainsKey(TFTPServer.Option_TransferSize)) { if (m_Length >= 0) { m_AcceptedOptions.Add(TFTPServer.Option_TransferSize, m_Length.ToString()); } } if (m_AcceptedOptions.Count > 0) { m_BlockNumber = 0; SendOptionsAck(); } else { m_BlockNumber = 1; SendData(); } } } catch (Exception e) { Stop(true, e); } }
public ISession CreateSession(SessionLogEntry.TConfiguration args) { lock (m_Sessions) { var result = new Slot(this, Interlocked.Increment(ref IDCounter), args); m_SessionQueue.Enqueue(result); m_Sessions.Add(result); Purge(); return(result); } }
public Slot(SessionLog parent, long id, SessionLogEntry.TConfiguration sessionInfo) { m_Id = id; m_Parent = parent; m_Configuration = sessionInfo; m_State = SessionLogEntry.TState.Busy; m_Exception = null; m_Transferred = 0; m_Speed = 0.0; m_StartTime = m_Parent.ElapsedSeconds; m_LastSpeedCalculation = m_StartTime; }
public override void Start() { var sessionLogConfiguration = new SessionLogEntry.TConfiguration() { FileLength = -1, Filename = m_Filename, IsUpload = true, LocalEndPoint = m_LocalEndPoint, RemoteEndPoint = m_RemoteEndPoint, StartTime = DateTime.Now, WindowSize = 1 }; try { lock (m_Lock) { try { m_Length = m_RequestedOptions.ContainsKey(TFTPServer.Option_TransferSize) ? Int64.Parse(m_RequestedOptions[TFTPServer.Option_TransferSize]) : -1; sessionLogConfiguration.FileLength = m_Length; m_Stream = m_Parent.GetWriteStream(m_Filename, m_Length); m_Position = 0; } catch (Exception e) { TFTPServer.SendError(m_Socket, m_RemoteEndPoint, TFTPServer.ErrorCode.FileNotFound, e.Message); throw; } finally { // always create a SessionLog (even if the file couldn't be opened), so Stop() will have somewhere to store its errors m_SessionLog = m_Parent.SessionLog.CreateSession(sessionLogConfiguration); } // handle tsize option if (m_RequestedOptions.ContainsKey(TFTPServer.Option_TransferSize)) { // rfc2349: in Write Request packets, the size of the file, in octets, is specified in the // request and echoed back in the OACK m_AcceptedOptions.Add(TFTPServer.Option_TransferSize, m_RequestedOptions[TFTPServer.Option_TransferSize]); } if (m_AcceptedOptions.Count > 0) { // send options ack, client will respond with block number 1 m_Window = TFTPServer.GetOptionsAckPacket(m_AcceptedOptions); } else { // send ack for current block, client will respond with next block m_Window = TFTPServer.GetDataAckPacket(m_BlockNumber); } TFTPServer.Send(m_Socket, m_RemoteEndPoint, m_Window); m_BlockRetry = 0; StartTimer(); } } catch (Exception e) { Stop(true, e); } }