The overload of Socket.BeginAccept that we use does not work correctly with MONO.
Their implementation ignores the socket we give it and creates its own internally. This creates a leak. We don't really need to use that overload, regardless of the platform. Socket pooling was completely removed as well.
This commit is contained in:
parent
73cc162dbb
commit
98e26b7208
5 changed files with 3 additions and 119 deletions
|
|
@ -25,7 +25,6 @@ namespace Server
|
||||||
public static void Initialize()
|
public static void Initialize()
|
||||||
{
|
{
|
||||||
SendQueue.CoalesceBufferSize = CoalesceBufferSize;
|
SendQueue.CoalesceBufferSize = CoalesceBufferSize;
|
||||||
SocketPool.InitialCapacity = PooledSockets;
|
|
||||||
|
|
||||||
EventSink.SocketConnect += new SocketConnectEventHandler( EventSink_SocketConnect );
|
EventSink.SocketConnect += new SocketConnectEventHandler( EventSink_SocketConnect );
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -242,9 +242,6 @@ namespace Server
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( SocketPool.Created )
|
|
||||||
SocketPool.Destroy();
|
|
||||||
|
|
||||||
if ( m_Service ) {
|
if ( m_Service ) {
|
||||||
Console.WriteLine( "This exception is fatal." );
|
Console.WriteLine( "This exception is fatal." );
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -342,9 +339,6 @@ namespace Server
|
||||||
if( !m_Crashed )
|
if( !m_Crashed )
|
||||||
EventSink.InvokeShutdown( new ShutdownEventArgs() );
|
EventSink.InvokeShutdown( new ShutdownEventArgs() );
|
||||||
|
|
||||||
if( SocketPool.Created )
|
|
||||||
SocketPool.Destroy();
|
|
||||||
|
|
||||||
Timer.TimerThread.Set();
|
Timer.TimerThread.Set();
|
||||||
|
|
||||||
Console.WriteLine( "done" );
|
Console.WriteLine( "done" );
|
||||||
|
|
@ -455,8 +449,6 @@ namespace Server
|
||||||
|
|
||||||
ScriptCompiler.Invoke( "Initialize" );
|
ScriptCompiler.Invoke( "Initialize" );
|
||||||
|
|
||||||
SocketPool.Create();
|
|
||||||
|
|
||||||
MessagePump ms = m_MessagePump = new MessagePump();
|
MessagePump ms = m_MessagePump = new MessagePump();
|
||||||
|
|
||||||
timerThread.Start();
|
timerThread.Start();
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ namespace Server.Network
|
||||||
|
|
||||||
private Socket Bind( IPEndPoint ipep )
|
private Socket Bind( IPEndPoint ipep )
|
||||||
{
|
{
|
||||||
Socket s = SocketPool.AcquireSocket();
|
Socket s = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp )
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -98,7 +98,7 @@ namespace Server.Network
|
||||||
Console.WriteLine( "Listening: {0}:{1}", ipep.Address, ipep.Port );
|
Console.WriteLine( "Listening: {0}:{1}", ipep.Address, ipep.Port );
|
||||||
}
|
}
|
||||||
|
|
||||||
IAsyncResult res = s.BeginAccept( SocketPool.AcquireSocket(), 0, m_OnAccept, s );
|
IAsyncResult res = s.BeginAccept( m_OnAccept, s );
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
@ -145,7 +145,7 @@ namespace Server.Network
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
listener.BeginAccept( SocketPool.AcquireSocket(), 0, m_OnAccept, listener );
|
listener.BeginAccept( m_OnAccept, listener );
|
||||||
} catch ( SocketException ex ) {
|
} catch ( SocketException ex ) {
|
||||||
NetState.TraceException( ex );
|
NetState.TraceException( ex );
|
||||||
} catch ( ObjectDisposedException ) {
|
} catch ( ObjectDisposedException ) {
|
||||||
|
|
@ -183,8 +183,6 @@ namespace Server.Network
|
||||||
|
|
||||||
try {
|
try {
|
||||||
socket.Close();
|
socket.Close();
|
||||||
|
|
||||||
SocketPool.ReleaseSocket( socket );
|
|
||||||
} catch ( SocketException ex ) {
|
} catch ( SocketException ex ) {
|
||||||
NetState.TraceException( ex );
|
NetState.TraceException( ex );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -845,8 +845,6 @@ namespace Server.Network {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
m_Socket.Close();
|
m_Socket.Close();
|
||||||
|
|
||||||
SocketPool.ReleaseSocket( m_Socket );
|
|
||||||
} catch ( SocketException ex ) {
|
} catch ( SocketException ex ) {
|
||||||
TraceException( ex );
|
TraceException( ex );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,103 +0,0 @@
|
||||||
/***************************************************************************
|
|
||||||
* SocketPool.cs
|
|
||||||
* -------------------
|
|
||||||
* begin : May 1, 2002
|
|
||||||
* copyright : (C) The RunUO Software Team
|
|
||||||
* email : info@runuo.com
|
|
||||||
*
|
|
||||||
* $Id$
|
|
||||||
*
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
/***************************************************************************
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
|
|
||||||
namespace Server.Network
|
|
||||||
{
|
|
||||||
public class SocketPool
|
|
||||||
{
|
|
||||||
private static bool m_Created = false;
|
|
||||||
|
|
||||||
public static bool Created
|
|
||||||
{
|
|
||||||
get { return m_Created; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int m_Misses = 0;
|
|
||||||
private static int m_InitialCapacity = 32;
|
|
||||||
|
|
||||||
public static int InitialCapacity
|
|
||||||
{
|
|
||||||
get { return m_InitialCapacity; }
|
|
||||||
set {
|
|
||||||
if ( m_Created )
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_InitialCapacity = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Queue<Socket> m_FreeSockets;
|
|
||||||
|
|
||||||
public static void Create()
|
|
||||||
{
|
|
||||||
if ( m_Created )
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_FreeSockets = new Queue<Socket>( m_InitialCapacity );
|
|
||||||
|
|
||||||
for ( int i = 0; i < m_InitialCapacity; ++i )
|
|
||||||
m_FreeSockets.Enqueue( new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ) );
|
|
||||||
|
|
||||||
m_Created = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Destroy()
|
|
||||||
{
|
|
||||||
if ( !m_Created )
|
|
||||||
return;
|
|
||||||
|
|
||||||
while ( m_FreeSockets.Count > 0 )
|
|
||||||
m_FreeSockets.Dequeue().Close();
|
|
||||||
|
|
||||||
m_FreeSockets = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Socket AcquireSocket()
|
|
||||||
{
|
|
||||||
lock ( m_FreeSockets )
|
|
||||||
{
|
|
||||||
if ( m_FreeSockets.Count > 0 )
|
|
||||||
return m_FreeSockets.Dequeue();
|
|
||||||
|
|
||||||
++m_Misses;
|
|
||||||
|
|
||||||
for ( int i = 0; i < m_InitialCapacity; ++i )
|
|
||||||
m_FreeSockets.Enqueue( new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ) );
|
|
||||||
|
|
||||||
return m_FreeSockets.Dequeue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ReleaseSocket( Socket s )
|
|
||||||
{
|
|
||||||
/*if ( s == null )
|
|
||||||
return;
|
|
||||||
|
|
||||||
s.Close();
|
|
||||||
|
|
||||||
lock ( m_FreeSockets )
|
|
||||||
m_FreeSockets.Enqueue( s );*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue