/// <summary> /// 结束发送 /// </summary> /// <param name="asyncResult">异步结果</param> /// <returns>发送是否成功</returns> public bool EndSend(IAsyncResult asyncResult) { //判断异步操作状态是否属于当前处理程序 if (!StateSet.ContainsKey(asyncResult)) { throw new ArgumentException("无法识别的asyncResult。"); } SocketHandlerState state = StateSet[asyncResult]; lock (StateSet) StateSet.Remove(asyncResult); return(state.Completed); }
/// <summary> /// 结束接收 /// </summary> /// <param name="asyncResult">异步结果</param> /// <returns>接收到的数据</returns> public byte[] EndReceive(IAsyncResult asyncResult) { //判断异步操作状态是否属于当前处理程序 if (!StateSet.ContainsKey(asyncResult)) { throw new ArgumentException("无法识别的asyncResult。"); } SocketHandlerState state = StateSet[asyncResult]; lock (StateSet) StateSet.Remove(asyncResult); return(state.Data); }