[csmaild-cvs] csmaild/src/Imap/NetworkManager Connection.cs,1.4,1.5
Brought to you by:
tamc
From: <ta...@us...> - 2003-07-25 03:39:16
|
Update of /cvsroot/csmaild/csmaild/src/Imap/NetworkManager In directory sc8-pr-cvs1:/tmp/cvs-serv31506/src/Imap/NetworkManager Modified Files: Connection.cs Log Message: Long time, no commit. Upgraded to VS.NET 2003 Lots of code changes, still pre-pre-pre-alpha, so who's keeping track Removed LOGINDISABLED from CAPABILITY response as well, it's not disabled Index: Connection.cs =================================================================== RCS file: /cvsroot/csmaild/csmaild/src/Imap/NetworkManager/Connection.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Connection.cs 24 Jul 2003 04:32:14 -0000 1.4 --- Connection.cs 25 Jul 2003 03:39:13 -0000 1.5 *************** *** 1,6 **** --- 1,8 ---- using System; + using System.Collections; using System.IO; using System.Net; using System.Net.Sockets; + using System.Threading; using System.Text; *************** *** 20,24 **** private Socket mClient; // the communication socket private NetworkStream mSocketStream; // a stream wrapping the communication socket ! private byte[] mReceiveLineBuffer; // a small storage place for receiving bytes for the line private string mLineString; // used to store the line the client sends --- 22,26 ---- private Socket mClient; // the communication socket private NetworkStream mSocketStream; // a stream wrapping the communication socket ! private byte[] mReceiveLineBuffer; // a small storage place for receiving bytes for the line private string mLineString; // used to store the line the client sends *************** *** 28,31 **** --- 30,36 ---- private int mReceiveBlockSize; // the number of bytes left to read into the receive block buffer + private Queue mWriteQueue = Queue.Synchronized(new Queue()); // the queue for writes (so we do them in order) + private bool mCurrentlyWriting; + private Listener mListener; // the listener that created us #endregion *************** *** 109,112 **** --- 114,120 ---- mListener = listener; + mWriteQueue = Queue.Synchronized(new Queue()); // the queue for writes (so we do them in order) + mCurrentlyWriting = false; + mSocketStream = new NetworkStream(mClient, true); mReceiveLineBuffer = new byte[8192]; *************** *** 115,122 **** #region Public methods public void Write(string msg) { ! byte[] b = Encoding.ASCII.GetBytes(msg); ! mSocketStream.BeginWrite(b, 0, b.Length, new AsyncCallback(SendCallback), msg); } --- 123,143 ---- #region Public methods + /// <summary> + /// Writes the message to the socket asynchronously + /// </summary> + /// <param name="msg">The message to write</param> public void Write(string msg) { ! Monitor.Enter(mWriteQueue); ! if(mCurrentlyWriting) ! mWriteQueue.Enqueue(msg); ! else ! { ! byte[] b = Encoding.ASCII.GetBytes(msg); ! if(mClient.Connected) ! mSocketStream.BeginWrite(b, 0, b.Length, new AsyncCallback(SendCallback), msg); ! mCurrentlyWriting = true; ! } ! Monitor.Exit(mWriteQueue); } *************** *** 124,128 **** /// Writes the message to the socket asynchronosously /// </summary> ! /// <param name="msg">The message to write</param> public void WriteLine(string msg) { --- 145,149 ---- /// Writes the message to the socket asynchronosously /// </summary> ! /// <param name="msg">The message to write (it will be suffixed with a CRLF)</param> public void WriteLine(string msg) { *************** *** 140,144 **** public void ReadLine(ReceivedLineDelegate callback) { ! mSocketStream.BeginRead(mReceiveLineBuffer, 0, mReceiveLineBuffer.Length, new AsyncCallback(ReceiveLineCallback), callback); } --- 161,166 ---- public void ReadLine(ReceivedLineDelegate callback) { ! if(mClient.Connected) ! mSocketStream.BeginRead(mReceiveLineBuffer, 0, mReceiveLineBuffer.Length, new AsyncCallback(ReceiveLineCallback), callback); } *************** *** 206,210 **** private void ReadBlock(ReceivedBlockDelegate callback) { ! mSocketStream.BeginRead(mReceiveBlockBuffer, mReceiveBlockOffset, mReceiveBlockSize, new AsyncCallback(ReceiveBlockCallback), callback); } --- 228,233 ---- private void ReadBlock(ReceivedBlockDelegate callback) { ! if(mClient.Connected) ! mSocketStream.BeginRead(mReceiveBlockBuffer, mReceiveBlockOffset, mReceiveBlockSize, new AsyncCallback(ReceiveBlockCallback), callback); } *************** *** 213,218 **** --- 236,253 ---- mSocketStream.EndWrite(result); + Monitor.Enter(mWriteQueue); + mCurrentlyWriting = false; + if(mWriteQueue.Count != 0) + { + string msg = (string)mWriteQueue.Dequeue(); + byte[] b = Encoding.ASCII.GetBytes(msg); + if(mClient.Connected) + mSocketStream.BeginWrite(b, 0, b.Length, new AsyncCallback(SendCallback), msg); + mCurrentlyWriting = true; + } System.Diagnostics.Trace.Write(ToString() + " <- " + (string)result.AsyncState); + Monitor.Exit(mWriteQueue); + // spill event OnSent(); *************** *** 242,246 **** mLineString = mLineString.Substring(idx+2); ! System.Diagnostics.Trace.WriteLine(ToString() + " -> " + (string)line); // spill event --- 277,282 ---- mLineString = mLineString.Substring(idx+2); ! if(line != string.Empty) ! System.Diagnostics.Trace.WriteLine(ToString() + " -> " + (string)line); // spill event *************** *** 271,275 **** --- 307,315 ---- if(mReceiveBlockSize == 0) + { + System.Diagnostics.Trace.WriteLine(ToString() + " -> " + System.Text.Encoding.ASCII.GetString(mReceiveBlockBuffer)); + FireReadBlockDelegate(mReceiveBlockBuffer, (ReceivedBlockDelegate)result.AsyncState); + } else ReadBlock((ReceivedBlockDelegate)result.AsyncState); |