|
||
|
|||||||
| Other Cant find a category above, use this one! Core mods not listed above go here! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Forum Newbie
Join Date: Dec 2005
Posts: 3
|
Ok I know what I did made no sense except to make the code cleaner and to avoid throwing an array of size 0 to the MessagePumper. This part of the core is very important & used every time there's incoming data, that's the main reason I wanted to clean it up.
In Listener.cs add the following function: Code:
public bool bSocketWaiting()
{
if (m_Accepted.Count > 0)
return true;
else
return false;
}
Now modify the Socket[] Slice() function by removing the following lines: Code:
if ( m_Accepted.Count == 0 ) return m_EmptySockets; Now open MessagePump.cs and change the CheckListener() function to this: Code:
private void CheckListener()
{
for ( int j = 0; j < m_Listeners.Length; ++j )
{
if (m_Listeners[j].bSocketWaiting())
{
Socket[] accepted = m_Listeners[j].Slice();
for ( int i = 0; i < accepted.Length; ++i )
{
NetState ns = new NetState( accepted[i], this );
ns.Start();
if ( ns.Running )
Console.WriteLine( "Client: {0}: Connected. [{1} Online]", ns, } NetState.Instances.Count );
}
}
}
Last edited by Rawolf; 01-08-2007 at 08:20 AM. |
|
|
|
|
|
#2 (permalink) |
|
Administrator
Join Date: Aug 2002
Location: Baltimore, MD
Age: 25
Posts: 4,832
|
Shouldn't that be a continue and not a return, right? Otherwise all other listeners would never be checked if the first one did not receive any new connections.
I'm not sure I understand the point of this change though. The old code implicitly accomplished the same thing. Returning an empty array means the for loop will never get run, and I think that is maybe a little bit more clear than this code.
__________________
Zippy, Razor Creator and RunUO Core Developer The RunUO Software Team "Intuition, like a flash of lightning, lasts only for a second. It generally comes when one is tormented by a difficult decipherment and when one reviews in his mind the fruitless experiments already tried. Suddenly the light breaks through and one finds after a few minutes what previous days of labor were unable to reveal." ~The Cryptonomicon Last edited by Zippy; 01-08-2007 at 07:24 AM. |
|
|
|
|
|
#3 (permalink) |
|
Forum Newbie
Join Date: Dec 2005
Posts: 3
|
You're right, I forgot that it's looping through every listener. But in that case I'd just modify CheckListener() to:
Code:
private void CheckListener()
{
for ( int j = 0; j < m_Listeners.Length; ++j )
{
if (m_Listeners[j].bSocketWaiting())
{
Socket[] accepted = m_Listeners[j].Slice();
for ( int i = 0; i < accepted.Length; ++i )
{
NetState ns = new NetState( accepted[i], this );
ns.Start();
if ( ns.Running )
Console.WriteLine( "Client: {0}: Connected. [{1} Online]", ns, NetState.Instances.Count );
}
}
}
}
Last edited by Rawolf; 01-08-2007 at 08:25 AM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|