コード例 #1
0
ファイル: TcpClient.cs プロジェクト: zhengfujun/Encyclopedia
        //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
        }
コード例 #2
0
ファイル: TcpClient.cs プロジェクト: zhengfujun/Encyclopedia
        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
        }
コード例 #3
0
ファイル: TcpClient.cs プロジェクト: zhengfujun/Encyclopedia
        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
        }
コード例 #4
0
ファイル: TcpClient.cs プロジェクト: zhengfujun/Encyclopedia
        public int EndSend(IAsyncResult ret)
        {
            TaskStateAsyncResult res = (TaskStateAsyncResult)(ret);

            return(res.len);
        }