Skip to content

[C#] 发送的消息应该保证顺序 #5

@chentmin

Description

@chentmin

现在在C#端, 就算调用方是单线程在调用发送, 底下会把发送放到个线程池中, 短时间内发送多条消息时, 更容易发生消息的顺序改变的情况.

这样的话, 就要求使用snet的项目对C#发过来的消息的顺序不能有要求, 甚至可能在逻辑上会有问题, 比如客户端是先跳再放的技能, 服务器先收到了放技能的消息.

		public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback callback, object state)
		{
			AsyncResult ar1 = new AsyncResult (callback, state);
			ThreadPool.QueueUserWorkItem ((object ar2) => {
				AsyncResult ar3 = (AsyncResult)ar2;
				try {
					Write(buffer, offset, count);
				} catch(Exception ex) {
					ar3.Error = ex;
				}
				ar3.IsCompleted = true;
				((ManualResetEvent)ar3.AsyncWaitHandle).Set();
				if (ar3.Callback != null)
					ar3.Callback(ar3);
			}, ar1);
			return ar1;
		}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions