Exemplo n.º 1
0
        public byte[] Recv(bool noWait = false)
        {
            EnsureNotDisposed();

            using (var frame = new MsgFrame())
            {
                var flags = noWait ? Native.Socket.DONTWAIT : 0;

again:
                var res = Native.MsgFrame.zmq_msg_recv(frame._msgPtr, this.SocketPtr, flags);

                if (res == Native.ErrorCode)
                {
                    var error = Native.LastError();

                    if (error == ZmqErrorCode.EAGAIN || error == ZmqErrorCode.EINTR)
                    {
                        goto again;
                    }

                    if (LogAdapter.LogEnabled)
                    {
                        LogAdapter.LogError("Socket", "Recv interrupted with " + error + " - " + Native.LastErrorString(error));
                    }

                    Native.ThrowZmqError(error, "Recv");
                }
                else
                {
                    return(frame.ToBytes());
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        public void Send(byte[] buffer, bool hasMoreToSend = false, bool noWait = false)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            EnsureNotDisposed();

            var flags = hasMoreToSend ? Native.Socket.SNDMORE : 0;

            flags += noWait ? Native.Socket.DONTWAIT : 0;

            var len = buffer.Length;

again:
            var res = Native.Socket.zmq_send(this.SocketPtr, buffer, len, flags);

            // for now we're treating EAGAIN as error.
            // not sure that's OK
            if (res == Native.ErrorCode)
            {
                var error = Native.LastError();
                if (error == ZmqErrorCode.EINTR || error == ZmqErrorCode.EAGAIN)
                {
                    goto again;
                }

                if (LogAdapter.LogEnabled)
                {
                    LogAdapter.LogError("Socket", "Send interrupted with " + error + " - " + Native.LastErrorString(error));
                }

                Native.ThrowZmqError("Send");
            }
        }
Exemplo n.º 3
0
        public void Connect(string endpoint)
        {
            if (string.IsNullOrEmpty(endpoint))
            {
                throw new ArgumentNullException("endpoint");
            }
            EnsureNotDisposed();

            var res = Native.Socket.zmq_connect(this.SocketPtr, endpoint);

            if (res == Native.ErrorCode)
            {
                if (Native.LastError() == 128)
                {
                    System.Diagnostics.Debugger.Break();
                }
                Native.ThrowZmqError("Connecting " + endpoint);
            }
        }