Beispiel #1
0
        public async Task <object> Send(CrossSocket client, Request request, bool nowait)
        {
            int taskid = this.taskid++;

            if (nowait)
            {
                request.taskid = -1;
                this.taskid--;
            }
            else
            {
                request.taskid = taskid;
            }

            string content = JsonConvert.SerializeObject(request);

            byte[] data = Encoding.UTF8.GetBytes(content + "\n");
            await client.SendAsync(data);

            if (!nowait)
            {
                SocketStore store = GetStoreForSocket(client, true);
                store.tasks[taskid] = new TaskCompletionSource <object>();
                return(await store.tasks[taskid].Task);
            }
            return(null);
        }
Beispiel #2
0
        public SocketStore GetStoreForSocket(CrossSocket client, bool create)
        {
            var         value = socketStore[client];
            SocketStore store = null;

            if (value != null)
            {
                store = (SocketStore)value;
            }
            else if (create)
            {
                store = new SocketStore();
                socketStore[client] = store;
            }
            return(store);
        }