// a bit dirty. only used by WorldClientCollection public void Send(SegmentStream stream) { if (Socket == null || !Connected) { stream.Dispose(); return; } var args = ObjectPoolMgr.ObtainObject <PoolableSocketArgs>(); try { args.Completed += OnSendCompleted; args.SetBuffer(stream.Segment.Buffer.Array, stream.Segment.Offset, (int)(stream.Position)); args.UserToken = stream; if (!Socket.SendAsync(args)) { args.Completed -= OnSendCompleted; stream.Dispose(); ObjectPoolMgr.ReleaseObject(args); } } catch { args.Dispose(); stream.Dispose(); // args could be disposed if an error occured throw; } }
public static void ReleaseSocketArg(SocketAsyncEventArgs arg) { //Interlocked.Increment(ref s_ReleasedArgs); //Interlocked.Decrement(ref s_OutstandingArgs); //Console.WriteLine("Releasing SocketAsyncEventArg {0}:{1}", s_OutstandingArgs, s_ReleasedArgs); ObjectPoolMgr.ReleaseObject <SocketAsyncEventArgs>(arg); }
private static void OnSendCompleted(object sender, SocketAsyncEventArgs args) { args.Completed -= OnSendCompleted; var stream = args.UserToken as SegmentStream; if (stream != null) { stream.Dispose(); } ObjectPoolMgr.ReleaseObject((PoolableSocketArgs)args); }
public void Send(SegmentStream stream) { if (this.Socket != null && this.Connected) { SocketAsyncEventArgs socketAsyncEventArgs = ObjectPoolMgr.ObtainObject <SocketAsyncEventArgs>(); socketAsyncEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(this.OnSendCompleted); socketAsyncEventArgs.SetBuffer(stream.Segment.Buffer.Array, stream.Segment.Offset, (int)stream.Position); socketAsyncEventArgs.UserToken = stream; if (!this.Socket.SendAsync(socketAsyncEventArgs)) { socketAsyncEventArgs.Completed -= new EventHandler <SocketAsyncEventArgs>(this.OnSendCompleted); stream.Dispose(); ObjectPoolMgr.ReleaseObject <SocketAsyncEventArgs>(socketAsyncEventArgs); } this.LastActivity = DateTime.Now; } }
public void PushSocketArg(PoolableSocketArgs args) { ObjectPoolMgr.ReleaseObject(args); }
public static void ReleaseSocketArg(SocketAsyncEventArgs arg) { ObjectPoolMgr.ReleaseObject(arg); }
public void PushSocketArg(SocketAsyncEventArgs args) { ObjectPoolMgr.ReleaseObject <SocketAsyncEventArgs>(args); }
private void OnSendCompleted(object sender, SocketAsyncEventArgs e) { e.Completed -= new EventHandler <SocketAsyncEventArgs>(this.OnSendCompleted); ((SegmentStream)e.UserToken).Dispose(); ObjectPoolMgr.ReleaseObject <SocketAsyncEventArgs>(e); }