示例#1
0
文件: NN.cs 项目: Wolfium/NNanomsg
        public static int GetSockOpt(int s, SocketOption option, out int val)
        {
            int optvallen = sizeof(int);
            int optval = 0;

            int rc = Interop.nn_getsockopt(s, Constants.NN_SOL_SOCKET, (int)option, ref optval, ref optvallen);

            val = optval;

            return rc;
        }
 public static TimeSpan? GetTimespan(int socket, SocketOptionLevel level, SocketOption opts)
 {
     int value = 0, size = sizeof(int);
     int result = Interop.nn_getsockopt(socket, (int)level, (int)opts, ref value, ref size);
     if (result != 0)
         throw new NanomsgException(string.Format("nn_getsockopt {0}", opts));
     return value < 0 ? (TimeSpan?)null : TimeSpan.FromMilliseconds(value);
 }
 public static void SetString(int socket, SocketOptionLevel level, SocketOption opts, string value)
 {
     var bs = Encoding.UTF8.GetBytes(value);
     SetBytes(socket, level, opts, bs);
 }
示例#4
0
        /// <summary>
        /// Gets socket option value.
        /// </summary>
        /// <param name="option">Option to get.</param>
        /// <returns></returns>
        public dynamic GetOption( SocketOption option )
        {
            switch( option )
            {
                case SocketOption.SocketIdentity:
                    return GetOptionString( (int)option );

                case SocketOption.HighWaterMark:
                case SocketOption.ThreadAffinity:
                case SocketOption.SendBuffer:
                case SocketOption.ReceiveBuffer:
                    return GetOptionUInt64( (int)option );

                case SocketOption.SwapSize:
                case SocketOption.MoreToFollow:
                    return GetOptionInt64( (int)option );

                case SocketOption.SocketType:
                case SocketOption.Linger:
                case SocketOption.ReconnectInterval:
                case SocketOption.ReconnectIntervalMax:
                case SocketOption.ConnectionBacklog:
                    return GetOptionInt32( (int)option );

                default:
                    throw new NotImplementedException( "Unknown option: " + option );
            }
        }
示例#5
0
        /// <summary>
        /// Sets socket options.
        /// </summary>
        /// <param name="option">Option to set.</param>
        /// <param name="value">Value to set the option to.</param>
        public void SetOption( SocketOption option, ulong value )
        {
            Contract.Requires( !Disposed );
            Contract.Requires( option == SocketOption.HighWaterMark
                            || option == SocketOption.ThreadAffinity
                            || option == SocketOption.SendBuffer
                            || option == SocketOption.ReceiveBuffer );

            if( C.zmq_setsockopt( m_sock, (int)option, ref value, new C.size_t( Marshal.SizeOf( value ) ) ) != 0 )
            {
                throw ZeroMQException.CurrentError();
            }
        }
示例#6
0
        /// <summary>
        /// Sets socket options.
        /// </summary>
        /// <param name="option">Option to set.</param>
        /// <param name="value">Value to set the option to.</param>
        public void SetOption( SocketOption option, byte[] value )
        {
            Contract.Requires( !Disposed );
            Contract.Requires( option == SocketOption.SocketIdentity
                            || option == SocketOption.Subscribe
                            || option == SocketOption.Unsubscribe );
            Contract.Requires( value != null );
            Contract.Requires( option != SocketOption.SocketIdentity || ( value.Length <= 255 && value.Length > 0 ) );

            //Automatic marshalling of the byte array doesn't quite seem to work.

            IntPtr valuePtr = Marshal.AllocHGlobal( value.Length );

            try
            {
                Marshal.Copy( value, 0, valuePtr, value.Length );

                if( C.zmq_setsockopt( m_sock, (int)option, valuePtr, new C.size_t( value.Length ) ) != 0 )
                {
                    throw ZeroMQException.CurrentError();
                }
            }
            finally
            {
                Marshal.FreeHGlobal( valuePtr );
            }
        }
示例#7
0
文件: ZmqSocket.cs 项目: jgoz/netzmq
        internal byte[] GetSocketOptionBytes(SocketOption option)
        {
            this.EnsureNotDisposed();

            byte[] value;

            this.HandleProxyResult(this.proxy.GetSocketOption((int)option, out value));

            return value;
        }
示例#8
0
文件: ZmqSocket.cs 项目: jgoz/netzmq
        internal int GetSocketOptionInt32(SocketOption option)
        {
            this.EnsureNotDisposed();

            int value;

            this.HandleProxyResult(this.proxy.GetSocketOption((int)option, out value));

            return value;
        }
 public abstract T GetOption(SocketOption <T> name);
        /// <exception cref="IllegalArgumentException">                {@inheritDoc} </exception>
        /// <exception cref="ClosedChannelException">                  {@inheritDoc} </exception>
        /// <exception cref="IOException">                             {@inheritDoc} </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public abstract <T> AsynchronousServerSocketChannel setOption(java.net.SocketOption<T> name, T value) throws java.io.IOException;
        public abstract AsynchronousServerSocketChannel setOption <T>(SocketOption <T> name, T value);
示例#11
0
        public static void SetString(int socket, SocketOptionLevel level, SocketOption opts, string value)
        {
            var bs = Encoding.UTF8.GetBytes(value);

            SetBytes(socket, level, opts, bs);
        }
示例#12
0
 /// <summary>
 /// Convinience constructor
 /// </summary>
 public GetOptRequest(SocketOption option)
 {
     Option = option;
 }
 public BluetoothClient(Socket socket)
 {
     _socket = socket;
     option  = new SocketOption(socket);
 }
 public BluetoothClient()
 {
     _socket = new BluetoothSocket();
     option  = new SocketOption(Socket);
 }
        /// <exception cref="UnsupportedOperationException">           {@inheritDoc} </exception>
        /// <exception cref="IllegalArgumentException">                {@inheritDoc} </exception>
        /// <exception cref="ClosedChannelException">                  {@inheritDoc} </exception>
        /// <exception cref="IOException">                             {@inheritDoc}
        ///
        /// @since 1.7 </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public abstract <T> ServerSocketChannel setOption(java.net.SocketOption<T> name, T value) throws java.io.IOException;
        public abstract ServerSocketChannel setOption <T>(SocketOption <T> name, T value);
示例#16
0
 public static void SetString(int socket, SocketOptionLevel level, SocketOption opts, string value)
 {
     string v = value;
     int size = value.Length;
     int result = Interop.nn_setsockopt_string(socket, (int)level, (int)opts, v, size);
     if (result != 0)
         throw new NanomsgException(string.Format("nn_setsockopt {0}", opts));
 }
示例#17
0
        /// <exception cref="UnsupportedOperationException">           {@inheritDoc} </exception>
        /// <exception cref="IllegalArgumentException">                {@inheritDoc} </exception>
        /// <exception cref="ClosedChannelException">                  {@inheritDoc} </exception>
        /// <exception cref="IOException">                             {@inheritDoc}
        ///
        /// @since 1.7 </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public abstract <T> DatagramChannel setOption(java.net.SocketOption<T> name, T value) throws java.io.IOException;
        public abstract DatagramChannel setOption <T>(SocketOption <T> name, T value);
示例#18
0
 public SocketOptionBuilder()
 {
     _socketOption = new SocketOption();
 }
示例#19
0
文件: ZmqSocket.cs 项目: jgoz/netzmq
        internal ulong GetSocketOptionUInt64(SocketOption option)
        {
            this.EnsureNotDisposed();

            ulong value;

            this.HandleProxyResult(this.proxy.GetSocketOption((int)option, out value));

            return value;
        }
示例#20
0
文件: NN.cs 项目: kwpatrick/NNanomsg
 public static int SetSockOpt(int s, SocketOption option, string val)
 {
     return Interop.nn_setsockopt_string(s, Constants.NN_SOL_SOCKET, (int)option, val, val.Length);
 }
示例#21
0
        /// <summary>
        /// Sets socket options.
        /// </summary>
        /// <param name="option">Option to set.</param>
        /// <param name="value">Value to set the option to.</param>
        /// <param name="encoding">Encoding to use for the string value.</param>
        public void SetOption( SocketOption option, string value, Encoding encoding )
        {
            Contract.Requires( !Disposed );
            Contract.Requires( option == SocketOption.SocketIdentity
                            || option == SocketOption.Subscribe
                            || option == SocketOption.Unsubscribe );
            Contract.Requires( value != null );
            Contract.Requires( option != SocketOption.SocketIdentity || value.Length <= 255 );

            SetOption( option, encoding.GetBytes( value ) );
        }
示例#22
0
文件: NN.cs 项目: kwpatrick/NNanomsg
 public static int SetSockOpt(int s, SocketOption option, int val)
 {
     return Interop.nn_setsockopt_int(s, Constants.NN_SOL_SOCKET, (int)option, ref val, sizeof(int));
 }
示例#23
0
        /// <summary>
        /// Sets socket options.
        /// </summary>
        /// <param name="option">Option to set.</param>
        /// <param name="value">Value to set the option to.</param>
        public void SetOption( SocketOption option, long value )
        {
            Contract.Requires( !Disposed );
            Contract.Requires( option == SocketOption.SwapSize );

            if( C.zmq_setsockopt( m_sock, (int)option, ref value, new C.size_t( Marshal.SizeOf( value ) ) ) != 0 )
            {
                throw ZeroMQException.CurrentError();
            }
        }
示例#24
0
文件: NN.cs 项目: Wolfium/NNanomsg
 public static int SetSockOpt(int s, SocketOptionLevel level, SocketOption option, string val)
 {
     unsafe
     {
         var bs = Encoding.UTF8.GetBytes(val);
         fixed (byte* pBs = bs)
         {
             return Interop.nn_setsockopt(s, (int)level, (int)option, new IntPtr(pBs), bs.Length);
         }
     }
 }
示例#25
0
        /// <summary>
        /// Sets socket options.
        /// </summary>
        /// <param name="option">Option to set.</param>
        /// <param name="value">Value to set the option to.</param>
        public void SetOption( SocketOption option, int value )
        {
            Contract.Requires( !Disposed );
            Contract.Requires( option == SocketOption.Linger
                            || option == SocketOption.ReconnectInterval
                            || option == SocketOption.ConnectionBacklog
                            || option == SocketOption.ReconnectIntervalMax );

            if( C.zmq_setsockopt( m_sock, (int)option, ref value, new C.size_t( Marshal.SizeOf( value ) ) ) != 0 )
            {
                throw ZeroMQException.CurrentError();
            }
        }
示例#26
0
文件: NN.cs 项目: Wolfium/NNanomsg
 public static int SetSockOpt(int s, SocketOption option, int val)
 {
     unsafe
     {
         return Interop.nn_setsockopt(s, Constants.NN_SOL_SOCKET, (int) option, new IntPtr(&val), sizeof (int));
     }
 }
 public static void SetBytes(int socket, SocketOptionLevel level, SocketOption opts, byte[] bs)
 {
     unsafe
     {
         fixed (byte* pBs = bs)
         {
             int result = Interop.nn_setsockopt(socket, (int)level, (int)opts, new IntPtr(pBs), bs.Length);
             if (result != 0)
                 throw new NanomsgException(string.Format("nn_setsockopt {0}", opts));
         }
     }
 }
示例#28
0
文件: NN.cs 项目: Wolfium/NNanomsg
 public static int SetSockOpt(int s, SocketOptionLevel level, SocketOption option, int val)
 {
     unsafe
     {
         return Interop.nn_setsockopt(s, (int)level, (int)option, new IntPtr(&val), sizeof(int));
     }
 }
示例#29
0
 public static string GetString(int socket, SocketOptionLevel level, SocketOption opts)
 {
     string value = null;
     int size = 0;
     int result = Interop.nn_getsockopt(socket, (int)level, (int)opts, ref value, ref size);
     if (result != 0)
         throw new NanomsgException(string.Format("nn_getsockopt {0}", opts));
     return value;
 }
示例#30
0
文件: ZmqSocket.cs 项目: jgoz/netzmq
        internal void SetSocketOption(SocketOption option, ulong value)
        {
            this.EnsureNotDisposed();

            this.HandleProxyResult(this.proxy.SetSocketOption((int)option, value));
        }
示例#31
0
 public static void SetInt(int socket, SocketOptionLevel level, SocketOption opts, int value)
 {
     int v = value, size = sizeof(int);
     int result = Interop.nn_setsockopt_int(socket, (int)level, (int)opts, ref v, size);
     if (result != 0)
         throw new NanomsgException(string.Format("nn_setsockopt {0}", opts));
 }
示例#32
0
文件: ZmqSocket.cs 项目: jgoz/netzmq
        internal void SetSocketOption(SocketOption option, byte[] value)
        {
            this.EnsureNotDisposed();

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            this.HandleProxyResult(this.proxy.SetSocketOption((int)option, value));
        }
示例#33
0
 public static void SetTimespan(int socket, SocketOptionLevel level, SocketOption opts, TimeSpan? value)
 {
     int v = value.HasValue ? (int)value.Value.TotalMilliseconds : -1, size = sizeof(int);
     int result = Interop.nn_setsockopt_int(socket, (int)level, (int)opts, ref v, size);
     if (result != 0)
         throw new NanomsgException(string.Format("nn_setsockopt {0}", opts));
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="option"></param>
 /// <param name="value"></param>
 public SocketOptionValue(SocketOption option, ulong value)
 {
     Option = option;
     Value  = value;
 }