public bool Send(SegmentOffsetToken segToken, bool waiting = true) { try { if (!segToken.SToken.TokenSocket.Connected) { return(false); } var isWillEvent = true; var segItems = _sendBufferManager.BufferToSegments( segToken.DataSegment.Buffer, segToken.DataSegment.Offset, segToken.DataSegment.Size); foreach (var seg in segItems) { var tArgs = GetSocketAsyncFromSendPool(waiting, segToken.SToken.TokenSocket); if (tArgs == null) { return(false); } tArgs.UserToken = segToken.SToken; if (!_sendBufferManager.WriteBuffer(tArgs, seg.Array, seg.Offset, seg.Count)) { _sendTokenManager.Set(tArgs); throw new Exception(string.Format("发送缓冲区溢出...buffer block max size:{0}", _sendBufferManager.BlockSize)); } if (!segToken.SToken.TokenSocket.Connected) { return(false); } isWillEvent &= segToken.SToken.SendAsync(tArgs); if (!isWillEvent) { ProcessSentCallback(tArgs); } if (_sendTokenManager.Count < (_sendTokenManager.Capacity >> 2)) { Thread.Sleep(5); } } return(isWillEvent); } catch (Exception) { Close(segToken.SToken); throw; } }
public int SendSync(SegmentOffsetToken segToken) { return(segToken.SToken.Send(segToken.DataSegment)); }