public static void c4socket_received(C4Socket *socket, byte[] data)
 {
     fixed(byte *data_ = data)
     {
         NativeRaw.c4socket_received(socket, new C4Slice(data_, (ulong)data.Length));
     }
 }
Exemplo n.º 2
0
 public static void c4socket_gotHTTPResponse(C4Socket *socket, int httpStatus,
                                             IDictionary <string, object> headers)
 {
     using (var headers_ = headers.FLEncode()) {
         c4socket_gotHTTPResponse(socket, httpStatus, (C4Slice)headers_);
     }
 }
        private static void DoOpen(C4Socket *socket, C4Address *address, C4Slice options)
        {
            var builder = new UriBuilder {
                Host   = address->hostname.CreateString(),
                Scheme = address->scheme.CreateString(),
                Port   = address->port,
                Path   = address->path.CreateString()
            };

            Uri uri;

            try {
                uri = builder.Uri;
            } catch (Exception) {
                Native.c4socket_closed(socket, new C4Error(C4ErrorCode.InvalidParameter));
                return;
            }

            if (uri == null)
            {
                Native.c4socket_closed(socket, new C4Error(C4ErrorCode.InvalidParameter));
                return;
            }

            var opts =
                FLSliceExtensions.ToObject(NativeRaw.FLValue_FromTrustedData((FLSlice)options)) as
                Dictionary <string, object>;
            var replicationOptions = new ReplicatorOptionsDictionary(opts);
            var socketWrapper      = new WebSocketWrapper(uri, socket, replicationOptions);
            var id = Interlocked.Increment(ref _NextID);

            socket->nativeHandle = (void *)id;
            Sockets[id]          = socketWrapper;
            socketWrapper.Start();
        }
Exemplo n.º 4
0
 private static void SocketClose(C4Socket *socket)
 {
     try {
         _externalClose?.Invoke(socket);
     } catch (Exception e) {
         _error?.Invoke(socket, new Exception("Error closing socket", e));
     }
 }
Exemplo n.º 5
0
 private static void SocketClosed(C4Socket *socket)
 {
     try {
         _externalClose?.Invoke(socket);
     } catch (Exception) {
         // Log
     }
 }
Exemplo n.º 6
0
 private static void SocketCompletedReceive(C4Socket *socket, UIntPtr byteCount)
 {
     try {
         _externalCompletedReceive?.Invoke(socket, byteCount.ToUInt64());
     } catch (Exception) {
         // Log
     }
 }
        public unsafe WebSocketWrapper(Uri url, C4Socket *socket, [NotNull] ReplicatorOptionsDictionary options)
        {
            _socket  = socket;
            _logic   = new HTTPLogic(url);
            _options = options;

            SetupAuth();
        }
Exemplo n.º 8
0
 private static void SocketRequestClose(C4Socket *socket, int status, FLSlice message)
 {
     try {
         _externalRequestClose?.Invoke(socket, status, message.CreateString());
     } catch (Exception e) {
         _error?.Invoke(socket, new Exception("Error requesting socket close", e));
     }
 }
Exemplo n.º 9
0
 private static void SocketOpened(C4Socket *socket, C4Address *address)
 {
     try {
         _externalOpen?.Invoke(socket, address);
     } catch (Exception) {
         Native.c4socket_closed(socket, new C4Error(LiteCoreError.UnexpectedError));
     }
 }
Exemplo n.º 10
0
 private static void SocketCompletedReceive(C4Socket *socket, UIntPtr byteCount)
 {
     try {
         _externalCompletedReceive?.Invoke(socket, byteCount.ToUInt64());
     } catch (Exception e) {
         _error?.Invoke(socket, new Exception("Error completing receive for socket", e));
         Native.c4socket_closed(socket, new C4Error(C4ErrorCode.UnexpectedError));
     }
 }
Exemplo n.º 11
0
 private static void SocketOpened(C4Socket *socket, C4Address *address, C4Slice options)
 {
     try {
         _externalOpen?.Invoke(socket, address, options);
     } catch (Exception e) {
         _error?.Invoke(socket, new Exception("Error opening to socket", e));
         Native.c4socket_closed(socket, new C4Error(C4ErrorCode.UnexpectedError));
     }
 }
Exemplo n.º 12
0
 private static void SocketWrittenTo(C4Socket *socket, C4SliceResult allocatedData)
 {
     try {
         _externalWrite?.Invoke(socket, ((C4Slice)allocatedData).ToArrayFast());
     } catch (Exception) {
         // Log
     } finally {
         allocatedData.Dispose();
     }
 }
Exemplo n.º 13
0
 private static void SocketWrittenTo(C4Socket *socket, C4SliceResult allocatedData)
 {
     try {
         _externalWrite?.Invoke(socket, ((C4Slice)allocatedData).ToArrayFast());
     } catch (Exception e) {
         _error?.Invoke(socket, new Exception("Error writing to socket", e));
         Native.c4socket_closed(socket, new C4Error(C4ErrorCode.UnexpectedError));
     } finally {
         allocatedData.Dispose();
     }
 }
Exemplo n.º 14
0
        public unsafe WebSocketWrapper(Uri url, C4Socket *socket, [NotNull] ReplicatorOptionsDictionary options)
        {
            _socket  = socket;
            _logic   = new HTTPLogic(url);
            _options = options;
            _reachability.StatusChanged += ReachabilityChanged;
            _reachability.Url            = url;
            _reachability.Start();

            SetupAuth();
        }
        private static void DoClose(C4Socket *socket)
        {
            var id = (int)socket->nativeHandle;

            if (Sockets.TryGetValue(id, out var socketWrapper))
            {
                socketWrapper.CloseSocket();
            }
            else
            {
                Log.To.Sync.W(Tag, "Invalid call to DoClose; socket does not exist (or was disposed)");
            }
        }
        private static void DoCompleteReceive(C4Socket *socket, ulong bytecount)
        {
            var id = (int)socket->nativeHandle;

            if (Sockets.TryGetValue(id, out var socketWrapper))
            {
                socketWrapper.CompletedReceive(bytecount);
            }
            else
            {
                Log.To.Sync.W(Tag, "Invalid call to DoCompleteReceive; socket does not exist (or was closed)");
            }
        }
        private static void DoWrite(C4Socket *socket, byte[] data)
        {
            var id = (int)socket->nativeHandle;

            if (Sockets.TryGetValue(id, out var socketWrapper))
            {
                socketWrapper.Write(data);
            }
            else
            {
                Log.To.Sync.W(Tag, "Invalid call to DoWrite; socket does not exist (or was closed)");
            }
        }
        private static void DoCompleteReceive(C4Socket *socket, ulong bytecount)
        {
            var id = (int)socket->nativeHandle;

            if (id == 0)
            {
                // This one is not an error, it happens normally during connection close
                // but log it anyway just in case
                Log.To.Sync.V(Tag, "DoCompletedReceive reached after close, ignoring...");
                return;
            }

            if (Sockets.TryGetValue(id, out var socketWrapper))
            {
                socketWrapper.CompletedReceive(bytecount);
            }
            else
            {
                Log.To.Sync.E(Tag, "Invalid call to DoCompleteReceive; socket does not exist (or was disposed)");
            }
        }
        private static void DoClose(C4Socket *socket)
        {
            var id = (int)socket->nativeHandle;

            socket->nativeHandle = (void *)0;
            if (id == 0)
            {
                Log.To.Sync.E(Tag, "DoClose reached after close");
                return;
            }

            if (Sockets.TryGetValue(id, out var socketWrapper))
            {
                socketWrapper.CloseSocket();
                Sockets.Remove(id);
            }
            else
            {
                Log.To.Sync.E(Tag, "Invalid call to DoClose; socket does not exist (or was disposed)");
            }
        }
        private static void DoOpen(C4Socket *socket, C4Address *address, FLSlice options, void *context)
        {
            var builder = new UriBuilder {
                Host   = address->hostname.CreateString(),
                Scheme = address->scheme.CreateString(),
                Port   = address->port,
                Path   = address->path.CreateString()
            };

            Uri uri;

            try {
                uri = builder.Uri;
            } catch (Exception) {
                Native.c4socket_closed(socket, new C4Error(C4ErrorCode.InvalidParameter));
                return;
            }

            if (uri == null)
            {
                Native.c4socket_closed(socket, new C4Error(C4ErrorCode.InvalidParameter));
                return;
            }

            var opts =
                FLSliceExtensions.ToObject(NativeRaw.FLValue_FromData((FLSlice)options, FLTrust.Trusted)) as
                Dictionary <string, object>;
            var replicationOptions = new ReplicatorOptionsDictionary(opts);

            var id = Interlocked.Increment(ref _NextID);

            Native.c4Socket_setNativeHandle(socket, (void *)id);
            var socketWrapper = new WebSocketWrapper(uri, socket, replicationOptions);
            var replicator    = GCHandle.FromIntPtr((IntPtr)context).Target as Replicator;

            replicator?.WatchForCertificate(socketWrapper);
            replicator?.CheckForCookiesToSet(socketWrapper);
            Sockets.AddOrUpdate(id, socketWrapper, (k, v) => socketWrapper);
            socketWrapper.Start();
        }
 public static extern C4Replicator *c4repl_newWithSocket(C4Database *db, C4Socket *openSocket, C4ReplicatorParameters @params, C4Error *outError);
Exemplo n.º 22
0
 public static void c4socket_closeRequested(C4Socket *socket, int status, string message)
 {
     using (var message_ = new C4String(message)) {
         NativeRaw.c4socket_closeRequested(socket, status, message_.AsFLSlice());
     }
 }
 private static void DoError(C4Socket *socket, Exception e)
 {
     Log.To.Sync.E(Tag, "Websocket Error", e);
 }
        private static void DoDispose(C4Socket *socket)
        {
            var id = (int)socket->nativeHandle;

            Sockets.Remove(id);
        }
 public static extern void c4socket_opened(C4Socket *socket);
 public static extern void c4socket_closed(C4Socket *socket, C4Error errorIfAny);
 public static extern void c4socket_received(C4Socket *socket, C4Slice data);
 public static extern void c4socket_completedWrite(C4Socket *socket, UIntPtr byteCount);
Exemplo n.º 29
0
 public static extern void c4socket_closeRequested(C4Socket *socket, int status, FLSlice message);
 public static void c4socket_completedWrite(C4Socket *socket, ulong byteCount)
 {
     NativeRaw.c4socket_completedWrite(socket, (UIntPtr)byteCount);
 }