public bool Send(string msg) { bool result = false; bool overflow = false; byte[] msgBytes = null; //检测是否sock是否连接中 if (SUCCESS(IsClosed)) { goto Exit1; } msgBytes = Encoding.UTF8.GetBytes(msg.ToCharArray()); if (LOG_ERROR(msgBytes != null)) { goto Exit0; } if (SendBuf.GetTotalWritableLen() < msgBytes.Length) { overflow = true; } else { result = SendBuf.Write(msgBytes, 0, msgBytes.Length); if (LOG_ERROR(result)) { goto Exit0; } } if (overflow) { Close(ESockerCloseType.SendBufOverflow, 1, false); if (LOG_ERROR(false)) { goto Exit0; } } Exit1: return(true); Exit0: return(false); }
public bool Send(byte[] data, int startIndex, int length) { bool result = false; bool overflow = false; //检测是否sock是否连接中 if (SUCCESS(IsClosed)) { goto Exit1; } if (SendBuf.GetTotalWritableLen() < length) { overflow = true; } else { result = SendBuf.Write(data, startIndex, length); if (LOG_ERROR(result)) { goto Exit0; } } if (overflow) { Close(ESockerCloseType.SendBufOverflow, 1, false); if (LOG_ERROR(false)) { goto Exit0; } } Exit1: return(true); Exit0: return(false); }