Exemplo n.º 1
0
        //BeginReceive (msgcls.byteLinShi,0,msgcls.byteLinShi.Length,0,new AsyncCallback(ReceiveSorket),msgcls)
        public IAsyncResult BeginReceive(byte[] buf, int index, int len, int nouse, AsyncCallback requestCallback, object state)
        {
#if NETFX_CORE
            var task = ReadFromInputStreamAsyncInner(len);

            TaskStateAsyncResult res = new TaskStateAsyncResult(task, state);

            task.ContinueWith((t) =>
            {
                if (t.Result == null)
                {
                    return;
                }

                t.Result.CopyTo(buf, index);

                res.len = t.Result.Length;
                requestCallback(res);
            });

            return(res);
#else
            throw new PlatformNotSupportedException();
#endif
        }
Exemplo n.º 2
0
        public IAsyncResult BeginConnect(string host, int port, AsyncCallback requestCallback, object state)
        {
#if NETFX_CORE
            var task = EnsureSocket(host, port);
            TaskStateAsyncResult res = new TaskStateAsyncResult(task, state);

            task.ContinueWith((t) =>
            {
                requestCallback(res);
            });

            return(res);
#else
            throw new PlatformNotSupportedException();
#endif
        }
Exemplo n.º 3
0
        public IAsyncResult BeginSend(byte[] buf, int index, int len, int nouse, AsyncCallback requestCallback, object state)
        {
#if NETFX_CORE
            byte[] sendbuf = new byte[len];
            Array.Copy(buf, index, sendbuf, 0, len);
            var task = WriteToOutputStreamAsyncInner(sendbuf);

            TaskStateAsyncResult res = new TaskStateAsyncResult(task, state);

            task.ContinueWith((t) =>
            {
                res.len = len;
                requestCallback(res);
            });

            return(res);
#else
            throw new PlatformNotSupportedException();
#endif
        }
Exemplo n.º 4
0
        public int EndSend(IAsyncResult ret)
        {
            TaskStateAsyncResult res = (TaskStateAsyncResult)(ret);

            return(res.len);
        }