protected void SendBase(byte[] buffer, Socket socket, OpCode code) { var toSend = PrepareSending(buffer, code); var length = GetLength(toSend); log.LogInformation("Sending {0} bytes", length); lock (this) { if (closed == false && socket != null) { SocketError error; if (socket.Send(toSend, SocketFlags.None, out error) != length) { closed = true; } else { closed = error != SocketError.Success; } } if (closed) { throw new InvalidOperationException("Cache Communication Broken"); } } }
public void SendMessage(byte[] buffer) { var dup = new byte[buffer.Length + localIdentifier.Length]; Buffer.BlockCopy(localIdentifier, 0, dup, 0, localIdentifier.Length); Buffer.BlockCopy(buffer, 0, dup, localIdentifier.Length, buffer.Length); log.LogInformation("Sending {0} bytes", dup.Length); lock (this) { if (socket.Send(dup, dup.Length, SocketFlags.None) != dup.Length) { throw new InvalidOperationException("Socket did not send all bytes."); } } }