Go Back   RunUO - Ultima Online Emulation > RunUO > Core Modifications > Other

Other Cant find a category above, use this one! Core mods not listed above go here!

Reply
 
Thread Tools Display Modes
Old 01-07-2007, 08:25 PM   #1 (permalink)
Forum Newbie
 
Join Date: Dec 2005
Posts: 3
Default Cleaned Listener.cs a bit

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;
        }
That's a function to check if we have any connection waiting in the m_Accepted queue.

Now modify the Socket[] Slice() function by removing the following lines:
Code:
if ( m_Accepted.Count == 0 )
	return m_EmptySockets;
Those lines are no longer necessary.


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 );
				}
			}
		}
That's it. Thanks.

Last edited by Rawolf; 01-08-2007 at 08:20 AM.
Rawolf is offline   Reply With Quote
Old 01-08-2007, 07:15 AM   #2 (permalink)
Administrator
 
Zippy's Avatar
 
Join Date: Aug 2002
Location: Baltimore, MD
Age: 25
Posts: 4,832
Default

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.
Zippy is offline   Reply With Quote
Old 01-08-2007, 08:13 AM   #3 (permalink)
Forum Newbie
 
Join Date: Dec 2005
Posts: 3
Default

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 );
					}
				}
			}
		}
For me it feels cleaner as I'm not passing around any stuff, but I guess it's just a personal perspective. Booleans are great to check, as they're only 1 byte and fast.

Last edited by Rawolf; 01-08-2007 at 08:25 AM.
Rawolf is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5