Ejemplo n.º 1
0
 public AsyncContext(NngSocket nngSocket)
 {
     _nngSocket = nngSocket;
     _callback  = OnCompleted;
     NativeMethods.nng_aio_alloc(out _nngAio, _callback, IntPtr.Zero).ThrowIfError();
     Options = new AsyncOptions(_nngAio);
 }
Ejemplo n.º 2
0
 public static string GetStringValue(NngSocket socket, string name)
 {
     NativeMethods.nng_socket_get_string(socket, name, out var valuePtr).ThrowIfError();
     try
     {
         return(Marshal.PtrToStringAnsi(valuePtr));
     }
     finally
     {
         NativeMethods.nng_strfree(valuePtr);
     }
 }
Ejemplo n.º 3
0
        public void Dispose()
        {
            var errorCode = NativeMethods.nng_close(_nngSocket);

            if (errorCode == NngErrorCode.Success)
            {
                _nngSocket = default;
                _listeners.Clear(); // Listeners are implicitly closed when the socket they are associated with is closed
                _dialers.Clear();   // Dialers are implicitly closed when the socket they are associated with is closed
                return;
            }
            // todo: log error?

            _asyncSender.Dispose();
            _asyncReceiver.Dispose();
        }
Ejemplo n.º 4
0
 public SocketReceiveBehavior(NngSocket nngSocket)
 {
     _nngSocket = nngSocket;
 }
Ejemplo n.º 5
0
 public SocketReceiveAsyncBehavior(NngSocket nngSocket)
 {
     _asyncContext = new AsyncContext(nngSocket);
 }
Ejemplo n.º 6
0
 public SocketSendAsyncBehavior(NngSocket nngSocket)
 {
     _asyncContext = new AsyncContext(nngSocket);
 }
Ejemplo n.º 7
0
 public SocketSendBehavior(NngSocket nngSocket)
 {
     _nngSocket = nngSocket;
 }
Ejemplo n.º 8
0
 public SocketOptions(NngSocket socket, AsyncOptions asyncSendOptions, AsyncOptions asyncReceiveOptions)
 {
     _socket              = socket;
     _asyncSendOptions    = asyncSendOptions;
     _asyncReceiveOptions = asyncReceiveOptions;
 }
Ejemplo n.º 9
0
 internal static bool GetBoolValue(NngSocket socket, string name)
 {
     NativeMethods.nng_socket_get_bool(socket, name, out var value).ThrowIfError();
     return(value);
 }
Ejemplo n.º 10
0
 public static void SetTimeSpanValue(NngSocket socket, string name, in TimeSpan value)
Ejemplo n.º 11
0
 public static TimeSpan GetTimeSpanValue(NngSocket socket, string name)
 {
     NativeMethods.nng_socket_get_ms(socket, name, out var value).ThrowIfError();
     return(value.AsTimeSpan());
 }
Ejemplo n.º 12
0
 public static void SetStringValue(NngSocket socket, string name, string value)
 {
     NativeMethods.nng_socket_set_string(socket, name, value).ThrowIfError();
 }
Ejemplo n.º 13
0
 public static void SetInt32Value(NngSocket socket, string name, int value)
 {
     NativeMethods.nng_socket_set_int(socket, name, value).ThrowIfError();
 }
Ejemplo n.º 14
0
 public static int GetInt32Value(NngSocket socket, string name)
 {
     NativeMethods.nng_socket_get_int(socket, name, out var value).ThrowIfError();
     return(value);
 }