/// <summary> /// Reads bytes off the connection until the authentication object says we've got enough. /// </summary> /// <param name="connection"></param> /// <param name="authentication"></param> /// <returns></returns> private byte[] GetAuthenticationResponse(SocketConnection connection, IConnectorAuthentication authentication) { var result = new byte[0]; var readBuffer = new byte[512]; var finished = false; while (!finished) { var socket = connection.Socket; var bytesRead = socket == null ? 0 : socket.Receive(readBuffer); finished = bytesRead == 0; if (!finished) { var offset = result.Length; Array.Resize(ref result, result.Length + bytesRead); finished = result.Length > authentication.MaximumResponseLength; if (!finished) { Array.ConstrainedCopy(readBuffer, 0, result, offset, bytesRead); finished = authentication.GetResponseIsComplete(result); } } } return(result); }
/// <summary> /// Send the bytes over the connection. /// </summary> /// <param name="connection"></param> /// <param name="authentication"></param> private void SendAuthentication(SocketConnection connection, IConnectorAuthentication authentication) { var bytes = authentication.SendAuthentication(); var socket = connection.Socket; if (socket != null) { socket.Send(bytes); } }
/// <summary> /// Send the bytes over the connection. /// </summary> /// <param name="connection"></param> /// <param name="authentication"></param> private void SendAuthentication(SocketConnection connection, IConnectorAuthentication authentication) { var bytes = authentication.SendAuthentication(); connection.Socket.Send(bytes); }