diff --git a/src/ZeroMQ/Interop/SocketProxy.cs b/src/ZeroMQ/Interop/SocketProxy.cs index b9ba970..5662925 100644 --- a/src/ZeroMQ/Interop/SocketProxy.cs +++ b/src/ZeroMQ/Interop/SocketProxy.cs @@ -156,13 +156,13 @@ public byte[] Receive(byte[] buffer, int flags, out int size) return buffer; } - public int Send(byte[] buffer, int size, int flags) + public int Send(byte[] buffer, int offset, int size, int flags) { // Use zmq_buffer_send method if appropriate -> results in fewer P/Invoke calls if (buffer.Length <= MaxBufferSize && LibZmq.zmq_buffer_send != null) { int sizeToSend = Math.Min(size, MaxBufferSize); - Marshal.Copy(buffer, 0, _buffer, sizeToSend); + Marshal.Copy(buffer, offset, _buffer, sizeToSend); return Retry.IfInterrupted(LibZmq.zmq_buffer_send.Invoke, SocketHandle, _buffer, sizeToSend, flags); } @@ -174,7 +174,7 @@ public int Send(byte[] buffer, int size, int flags) if (size > 0) { - Marshal.Copy(buffer, 0, _msg.Data(), size); + Marshal.Copy(buffer, offset, _msg.Data(), size); } int bytesSent = Retry.IfInterrupted(LibZmq.zmq_msg_send.Invoke, _msg.Ptr, SocketHandle, flags); diff --git a/src/ZeroMQ/ZmqSocket.cs b/src/ZeroMQ/ZmqSocket.cs index d846b92..2e14f34 100644 --- a/src/ZeroMQ/ZmqSocket.cs +++ b/src/ZeroMQ/ZmqSocket.cs @@ -713,6 +713,7 @@ public virtual byte[] Receive(byte[] buffer, SocketFlags flags, out int size) /// P/Invoke calls required to send the message buffer. /// /// A array that contains the message to be sent. + /// The offset in buffer /// The size of the message to send. /// A combination of values to use when sending. /// The number of bytes sent by the socket. @@ -721,7 +722,7 @@ public virtual byte[] Receive(byte[] buffer, SocketFlags flags, out int size) /// An error occurred sending data to a remote endpoint. /// The has been closed. /// The current socket type does not support Send operations. - public virtual int Send(byte[] buffer, int size, SocketFlags flags) + public virtual int Send(byte[] buffer, int offset, int size, SocketFlags flags) { EnsureNotDisposed(); @@ -735,7 +736,7 @@ public virtual int Send(byte[] buffer, int size, SocketFlags flags) throw new ArgumentOutOfRangeException("size", "Expected a non-negative value less than or equal to the buffer length."); } - int sentBytes = _socketProxy.Send(buffer, size, (int)flags); + int sentBytes = _socketProxy.Send(buffer, offset, size, (int)flags); if (sentBytes >= 0) { @@ -758,6 +759,28 @@ public virtual int Send(byte[] buffer, int size, SocketFlags flags) throw new ZmqSocketException(ErrorProxy.GetLastError()); } + /// + /// Queue a message buffer to be sent by the socket in blocking mode. + /// + /// + /// Performance tip: To increase send performance, especially on low-powered devices, restrict the + /// size of to . This will reduce the number of + /// P/Invoke calls required to send the message buffer. + /// + /// A array that contains the message to be sent. + /// The size of the message to send. + /// A combination of values to use when sending. + /// The number of bytes sent by the socket. + /// is null. + /// is a negative value or is larger than the length of . + /// An error occurred sending data to a remote endpoint. + /// The has been closed. + /// The current socket type does not support Send operations. + public virtual int Send(byte[] buffer, int size, SocketFlags flags) + { + return Send(buffer, 0, size, flags); + } + /// /// Queue a message buffer to be sent by the socket in non-blocking mode with a specified timeout. ///