Пример #1
0
        public int Forward(IntPtr destinationHandle)
        {
            if (_msg.Init() == -1)
            {
                return(-1);
            }

            int receiveMore;
            int bytesSent;

            do
            {
                if (LibZmq.zmq_msg_recv(_msg, SocketHandle, 0) == -1)
                {
                    return(-1);
                }

                if (GetReceiveMore(out receiveMore) == -1)
                {
                    return(-1);
                }

                if ((bytesSent = LibZmq.zmq_msg_send(_msg, destinationHandle, receiveMore == 1 ? (int)SocketFlags.SendMore : 0)) == -1)
                {
                    return(-1);
                }
            }while (receiveMore == 1);

            if (_msg.Close() == -1)
            {
                return(-1);
            }

            return(bytesSent);
        }
Пример #2
0
        public int Close()
        {
            int rc = LibZmq.zmq_msg_close(_ptr);

            _initialized = false;

            return(rc);
        }
Пример #3
0
        public int Init(int size)
        {
            int rc = LibZmq.zmq_msg_init_size(_ptr, size);

            _initialized = true;

            return(rc);
        }
Пример #4
0
        public int Init()
        {
            int rc = LibZmq.zmq_msg_init(_ptr);

            _initialized = true;

            return(rc);
        }
Пример #5
0
        public static int IfInterrupted <T1, T2, T3>(Func <T1, T2, T3, int> operation, T1 arg1, T2 arg2, T3 arg3)
        {
            int rc;

            do
            {
                rc = operation(arg1, arg2, arg3);
            }while (rc == -1 && LibZmq.zmq_errno() == ErrorCode.EINTR);

            return(rc);
        }
Пример #6
0
        public int Close()
        {
            // Allow Close to be called repeatedly without failure
            if (SocketHandle == IntPtr.Zero)
            {
                return(0);
            }

            int rc = LibZmq.zmq_close(SocketHandle);

            SocketHandle = IntPtr.Zero;

            return(rc);
        }
Пример #7
0
        public static ErrorDetails GetLastError()
        {
            int errorCode = GetErrorCode();

            if (KnownErrors.ContainsKey(errorCode))
            {
                return(KnownErrors[errorCode]);
            }

            string message = Marshal.PtrToStringAnsi(LibZmq.zmq_strerror(errorCode));

            var errorDetails = new ErrorDetails(errorCode, message);

            KnownErrors[errorCode] = errorDetails;

            return(errorDetails);
        }
Пример #8
0
        public void Terminate()
        {
            if (ContextHandle == IntPtr.Zero)
            {
                return;
            }

            while (LibZmq.zmq_ctx_destroy(ContextHandle) != 0)
            {
                int errorCode = ErrorProxy.GetErrorCode();

                // If zmq_ctx_destroy fails, valid return codes are EFAULT or EINTR. If EINTR is set, termination
                // was interrupted by a signal and may be safely retried.
                if (errorCode == ErrorCode.EFAULT)
                {
                    // This indicates an invalid context was passed in. There's nothing we can do about it here.
                    // It's arguably not a fatal error, so throwing an exception would be bad seeing as this may
                    // run inside a finalizer.
                    break;
                }
            }

            ContextHandle = IntPtr.Zero;
        }
Пример #9
0
 public IntPtr CreateSocket(int socketType)
 {
     return(LibZmq.zmq_socket(ContextHandle, socketType));
 }
Пример #10
0
        public int Initialize()
        {
            ContextHandle = LibZmq.zmq_ctx_new();

            return(ContextHandle == IntPtr.Zero ? -1 : 0);
        }
Пример #11
0
 public int Monitor(string endpoint, int events)
 {
     return(LibZmq.zmq_socket_monitor(SocketHandle, endpoint, events));
 }
Пример #12
0
 public int Disconnect(string endpoint)
 {
     return(LibZmq.zmq_disconnect(SocketHandle, endpoint));
 }
Пример #13
0
 public IntPtr Data()
 {
     return(LibZmq.zmq_msg_data(_ptr));
 }
Пример #14
0
 public int Size()
 {
     return(LibZmq.zmq_msg_size(_ptr));
 }
Пример #15
0
 public int GetContextOption(int option)
 {
     return(LibZmq.zmq_ctx_get(ContextHandle, option));
 }
Пример #16
0
 public int Unbind(string endpoint)
 {
     return(LibZmq.zmq_unbind(SocketHandle, endpoint));
 }
Пример #17
0
 public int SetContextOption(int option, int value)
 {
     return(LibZmq.zmq_ctx_set(ContextHandle, option, value));
 }
Пример #18
0
 public static int GetErrorCode()
 {
     return(LibZmq.zmq_errno());
 }