public void SendPacket(StreamBuffer buffer, PacketCriterion criterion, EventHandler_Receive dispatcher, Action <StreamBuffer> onSent = null) { if (criterion == null || dispatcher == null) { throw new AegisException(AegisResult.InvalidArgument, "The argument criterion and dispatcher cannot be null."); } try { lock (_session) { if (_session.Socket == null) { return; } // ReadIndex가 OnSocket_Send에서 사용되므로 ReadIndex를 초기화해야 한다. buffer.ResetReadIndex(); SocketAsyncEventArgs saea = new SocketAsyncEventArgs(); saea.Completed += OnComplete_Send; saea.SetBuffer(buffer.Buffer, 0, buffer.WrittenBytes); if (onSent != null) { saea.UserToken = new NetworkSendToken(buffer, onSent); } _responseSelector.Add(criterion, dispatcher); if (_session.Socket.SendAsync(saea) == false) { OnComplete_Receive(null, saea); } } } catch (SocketException) { } catch (Exception e) { Logger.Write(LogType.Err, 1, e.ToString()); } }
public void SendPacket(StreamBuffer buffer, PacketCriterion criterion, EventHandler_Receive dispatcher, Action <StreamBuffer> onSent = null) { if (criterion == null || dispatcher == null) { throw new AegisException(AegisResult.InvalidArgument, "The argument criterion and dispatcher cannot be null."); } try { lock (_session) { _responseSelector.Add(criterion, dispatcher); if (_session.Socket != null) { // ReadIndex가 OnSocket_Send에서 사용되므로 ReadIndex를 초기화해야 한다. buffer.ResetReadIndex(); if (onSent == null) { _session.Socket.BeginSend(buffer.Buffer, 0, buffer.WrittenBytes, SocketFlags.None, OnSocket_Send, null); } else { _session.Socket.BeginSend(buffer.Buffer, 0, buffer.WrittenBytes, SocketFlags.None, OnSocket_Send, new NetworkSendToken(buffer, onSent)); } } } } catch (SocketException) { } catch (Exception e) { Logger.Write(LogType.Err, 1, e.ToString()); } }
public void Add(PacketCriterion criterion, EventHandler_Receive dispatcher) { _listResponseAction.Add(new Data(criterion, dispatcher)); }
public Data(PacketCriterion criterion, EventHandler_Receive dispatcher) { Criterion = criterion; Dispatcher = dispatcher; }
/// <summary> /// 패킷을 전송하고, 특정 패킷이 수신될 경우 dispatcher에 지정된 핸들러를 실행합니다. /// 이 기능은 AwaitableMethod보다는 빠르지만, 동시에 많이 호출될 경우 성능이 저하될 수 있습니다. /// </summary> /// <param name="buffer">전송할 데이터가 담긴 StreamBuffer</param> /// <param name="criterion">dispatcher에 지정된 핸들러를 호출할 것인지 여부를 판단하는 함수를 지정합니다.</param> /// <param name="dispatcher">실행될 함수를 지정합니다.</param> /// <param name="onSent">패킷 전송이 완료된 후 호출할 Action</param> public virtual void SendPacket(StreamBuffer buffer, PacketCriterion criterion, EventHandler_Receive dispatcher, Action <StreamBuffer> onSent = null) { _method.SendPacket(buffer, criterion, dispatcher, onSent); }
public void SendPacket(StreamBuffer buffer, PacketCriterion criterion, EventHandler_Receive dispatcher, Action<StreamBuffer> onSent = null) { if (criterion == null || dispatcher == null) throw new AegisException(AegisResult.InvalidArgument, "The argument criterion and dispatcher cannot be null."); try { lock (_session) { _responseSelector.Add(criterion, dispatcher); if (_session.Socket != null) { // ReadIndex가 OnSocket_Send에서 사용되므로 ReadIndex를 초기화해야 한다. buffer.ResetReadIndex(); if (onSent == null) _session.Socket.BeginSend(buffer.Buffer, 0, buffer.WrittenBytes, SocketFlags.None, OnSocket_Send, null); else _session.Socket.BeginSend(buffer.Buffer, 0, buffer.WrittenBytes, SocketFlags.None, OnSocket_Send, new NetworkSendToken(buffer, onSent)); } } } catch (SocketException) { } catch (Exception e) { Logger.Write(LogType.Err, 1, e.ToString()); } }
/// <summary> /// 패킷을 전송하고, 특정 패킷이 수신될 경우 dispatcher에 지정된 핸들러를 실행합니다. /// 이 기능은 AwaitableMethod보다는 빠르지만, 동시에 많이 호출될 경우 성능이 저하될 수 있습니다. /// </summary> /// <param name="buffer">전송할 데이터가 담긴 StreamBuffer</param> /// <param name="criterion">dispatcher에 지정된 핸들러를 호출할 것인지 여부를 판단하는 함수를 지정합니다.</param> /// <param name="dispatcher">실행될 함수를 지정합니다.</param> /// <param name="onSent">패킷 전송이 완료된 후 호출할 Action</param> public virtual void SendPacket(StreamBuffer buffer, PacketCriterion criterion, EventHandler_Receive dispatcher, Action<StreamBuffer> onSent = null) { _method.SendPacket(buffer, criterion, dispatcher, onSent); }
public void SendPacket(StreamBuffer buffer, PacketCriterion criterion, EventHandler_Receive dispatcher, Action<StreamBuffer> onSent = null) { if (criterion == null || dispatcher == null) throw new AegisException(AegisResult.InvalidArgument, "The argument criterion and dispatcher cannot be null."); try { lock (_session) { if (_session.Socket == null) return; // ReadIndex가 OnSocket_Send에서 사용되므로 ReadIndex를 초기화해야 한다. buffer.ResetReadIndex(); SocketAsyncEventArgs saea = new SocketAsyncEventArgs(); saea.Completed += OnComplete_Send; saea.SetBuffer(buffer.Buffer, 0, buffer.WrittenBytes); if (onSent != null) saea.UserToken = new NetworkSendToken(buffer, onSent); _responseSelector.Add(criterion, dispatcher); if (_session.Socket.SendAsync(saea) == false) OnComplete_Receive(null, saea); } } catch (SocketException) { } catch (Exception e) { Logger.Write(LogType.Err, 1, e.ToString()); } }