Esempio n. 1
0
	    internal bool Send(Protocol protocol)
	    {
            bool osempty = (os.Count == 0);
		    lock(ilock)
		    {
			    OctetsStream o = new OctetsStream();
			    protocol.Encode(o);
			    if (protocol.SizePolicy(o.size()))
			    {
					//增加低延迟模式的处理
					if(obuffer.size () == 0 && os.Count == 0 && Output(o))
					{
						if(assoc_io != null && assoc_io.channel != null)
						{
							//直接发送数据
                            try
                            {
                                int sentcount = assoc_io.channel.Send(obuffer.buffer(), obuffer.size(), SocketFlags.None);
                                if (sentcount > 0)
                                {
                                    obuffer.erase(0, sentcount);
                                    return true;
                                }
                            }
                            catch (Exception e)
                            {
                                obuffer.clear();
                                UnityEngine.Debug.LogWarning(e.StackTrace);
                                UnityEngine.Debug.LogWarning(e.Message);
                            }
						}
					}
					else
					{
					    os.AddLast(o);
	                    if (osempty)
	                    {
	                        osempty = false;
	                    }
					    need_wakeup = true;
					}


				    return true;
			    }                
		    }
		    return false;
	    }