/// <summary> /// Called when an authentication reply has been received. /// </summary> /// <param name="ar">Stores state information for this asynchronous operation as well as any user-defined data.</param> private void OnAuthReceive(IAsyncResult ar) { try { Received += Server.EndReceive(ar); if (Received <= 0) { throw new SocketException(); } } catch (Exception e) { ProtocolComplete(e); return; } try { if (Received < 2) { Server.BeginReceive(Buffer, Received, Buffer.Length - Received, SocketFlags.None, OnAuthReceive, Server); } else { AuthMethod authenticate; switch (Buffer[1]) { case 0: authenticate = new AuthNone(Server); break; case 2: authenticate = new AuthUserPass(Server, Username, Password); break; default: ProtocolComplete(new SocketException()); return; } authenticate.BeginAuthenticate(OnAuthenticated); } } catch (Exception e) { ProtocolComplete(e); } }
/// <summary> /// Called when an authentication reply has been received. /// </summary> /// <param name="ar">Stores state information for this asynchronous operation as well as any user-defined data.</param> private void OnAuthReceive(IAsyncResult ar) { try { HandleEndReceive(ar); } catch (Exception e) { OnProtocolComplete(e); return; } try { if (Received < BufferCount) { Server.BeginReceive(Buffer, Received, BufferCount - Received, SocketFlags.None, this.OnAuthReceive, Server); } else { AuthMethod authenticate; switch (Buffer[1]) { case 0: authenticate = new AuthNone(Server); break; case 2: authenticate = new AuthUserPass(Server, Username, Password); break; default: OnProtocolComplete(new SocketException()); return; } authenticate.BeginAuthenticate(this.OnAuthenticated); } } catch (Exception e) { OnProtocolComplete(e); } }