Donate Share

ILKMail

Tracker: Bugs

5 BeginRead at wrong position - ID: 1757377
Last Update: Tracker Item Submitted ( liuhongbo1974 )

public void StartHandler(Socket Client, bool ForceSSL)
{
try
{
//Setup the async socket
_asyncSocket = new AsyncSocket(Client);
_asyncSocket.OnReceive += new
AsyncSocket.OnReceiveEvent(asyncSocket_OnReceive);
_asyncSocket.OnSendComplete += new
AsyncSocket.OnSendCompleteEvent(asyncSocket_OnSendComplete);
_asyncSocket.OnDisconnect += new
AsyncSocket.OnDisconnectEvent(asyncSocket_OnDisconnect);
_asyncSocket.OnException += new
AsyncSocket.OnExceptionEvent(asyncSocket_OnException);
_asyncSocket.OnSecure += new
AsyncSocket.OnSecureEvent(_asyncSocket_OnSecure);

if (ForceSSL)
{

_asyncSocket.SecureSocketAsServer(Settings.CertificateData.Certificate,
false, System.Security.Authentication.SslProtocols.Tls, false);
}
else
{
//Tell the derived handler that we have started.
HandlerStarted();
}
}
catch
{
//If an error occured here, we won't get very far. Just
shutdown
Dispose();
}
}


public AsyncSocket(Socket Connection)
{
//Setup the vars
Reset();
_lastActivity = DateTime.Now;
_timer = new Timer(new TimerCallback(TimerCallback), null,
1000, 1000);
_socket = Connection;

//Get the stream and wait for data
NetworkStream ns = new NetworkStream(_socket);
_stream = (Stream)ns;
_stream.BeginRead(_buffer, 0, _buffer.Length, new
AsyncCallback(ReadCallback), null);
}


problem:
you can not call BeginRead here before you hook up the events. because you
might receive the data after you call BeginRead, so, you might lost some
data.


liuhongbo ( liuhongbo1974 ) - 2007-07-20 08:35

5

Open

None

Nobody/Anonymous

Server

None

Public


Comments




Log in to comment.

No follow-up comments have been posted.

Attached File

No Files Currently Attached

Change

No changes have been made to this artifact.