[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Learning more about descriptors...
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Learning more about descriptors...

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1 2  

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Sun 19 Jan 2003 04:31 AM (UTC)
Message
I really am a newbie coder that just learned how to do everything by messing with it and figuring out what it meant(and reading some books on C coding, but I believe you don't get the gist of coding till you have really messed with some code). Anyways, I was reading about the entire descriptor deal and I was just saying to myself "Hey, I've looked through that code, but I don't really under stand what it all means.." So, yeah, if you would could you explain in short what descriptors in the MUD are really about, becaue all I know is that you need them to log on and everything.

The second thing I have to say is how nice I think it is that everyone is so helpful on this forum. I think its great we can just post our problems with our code and have other people that are kind enough to help up figure it out. Anyways, I just thought i would say thanks to anyone and everyone who reads, posts, admin's this forum.

Thanks for everything.

~Nick Cash
http://www.nick-cash.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 19 Jan 2003 05:25 AM (UTC)
Message
When you open a file, or create a TCP/IP connection with a socket, the operating system gives you a number, which is its internal reference to that file. This can be called a file descriptor (I think Windows calls it a handle, but a rose by any other name ...).

You subsequently use this descriptor to access the file (eg. read, write, close, query, etc.). The operating system looks it up in its internal table to see which file you are talking about.

In SMAUG, which is mainly TCP/IP I/O (plus some disk files) the term descriptor generally refers to a connected player, and hence the file descriptor returned by the OS when the connection is established. Somewhat confusingly the low-level operating system descriptor is stored in an internal structure called descriptor_data, which stores the OS descriptor, plus other things that are useful, such as incoming data that hasn't been processed yet (eg. because no linefeed), outgoing data yet to be sent, and so on.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 19 Jan 2003 05:26 AM (UTC)
Message
See mud.h for that structure.

And by the way, thanks for the compliments about the forum. Glad you find it useful. :)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Boborak   USA  (228 posts)  [Biography] bio
Date Reply #3 on Sun 19 Jan 2003 06:32 AM (UTC)
Message
A little more info on descriptors..

In a native *nix environment you can see what descriptors a particular program may have open quite easily.

First type 'ps x' You'll get a list of processes your shell user has running. It'll look like a list of these:

15728 pts/12 S 0:01 gdb ../src/smaug

That first number is your pid (Process Id). With that number on hand, change to your /proc directory.

Typing 'ls' you'll see an extensive list of numbers and other seemingly cryptic things. One of those numbers will correspond to your mud's pid. It is in fact, a directory. Change to that directory. In this case, I would type 'cd 15728'.

You'll enter another directory full of files all related to that pid. One of those directories is called 'fd'. Change to that directory. Within that directory will be a *hopefully* medium range of numbers. Each one of those numbers represents a file descriptor your mud is using. It could be a file the mud has open or a 'socket' that's open (someone who's connected). There are also a number of system reserved/used file descriptors.

Typing 'ls -l' will give you a more detailed listing. Like such:

[thresher@users: fd]$ ls -l
total 0
lrwx------ 1 thresher users 64 Jan 19 00:15 0 -> /dev/pts/4 (deleted)
l-wx------ 1 thresher users 64 Jan 19 00:15 1 -> /home/thresher/smaug/dist/log/122.log
lrwx------ 1 thresher users 64 Jan 19 00:15 10 -> socket:[2733641]
l-wx------ 1 thresher users 64 Jan 19 00:15 2 -> /home/thresher/smaug/dist/log/122.log
lr-x------ 1 thresher users 64 Jan 19 00:15 3 -> /dev/null
lr-x------ 1 thresher users 64 Jan 19 00:15 4 -> /dev/null
lrwx------ 1 thresher users 64 Jan 19 00:15 5 -> socket:[2726550]
lrwx------ 1 thresher users 64 Jan 19 00:15 8 -> socket:[2734964]
[thresher@users: fd]$

Looking at this you can see what files the process has open currently and the number of sockets connected. You'll notice that the number listed here corresponds to the descriptor number of a connected user.

This list can also be very handy in tracking down potential 'descriptor leaks'. A descriptor leak is caused by the program opening a file but not closing it. If you see a list of files here pointing at player files for example. You likely have a problem somewhere.

I hope this has expanded your knowledge of descriptors a bit. More then likely I just confused you more ;-)
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sun 19 Jan 2003 10:28 AM (UTC)
Message
This /proc stuff seems to work perfectly on Linux, however I can't get it to work on OS/X, and I think from memory it doesn't work under OpenBSD also.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Samson   USA  (683 posts)  [Biography] bio
Date Reply #5 on Tue 21 Jan 2003 12:03 AM (UTC)
Message
Indeed. The /proc thing works very well under Linux. I've uncovered a few descriptor leaks using that method in some of the extra stuff we have in our code. You need to be especially mindful of those when using copyover since it carries over leaked ones along with your active ones. Needless to say if you leak enough of them this will cause you a world of hurt. Plugging them can be somewhat of a pain too. :)

SmaugMuds.org: http://www.smaugmuds.org - The Smaug MUDs Community Center

"The past was erased, the erasure was forgotten, the lie became truth." -- George Orwell, 1984
[Go to top] top

Posted by Boborak   USA  (228 posts)  [Biography] bio
Date Reply #6 on Tue 21 Jan 2003 06:25 AM (UTC)
Message
The best thing to do when you're having an abundance of descriptor leaks, is to just start with the first file you have, search for an instance of 'fopen' and verify that whatever was opened, gets closed again. Continue doing this until you've gone through all of your files that have and fopen's in them. Sounds painful, but the alternative if you don't bring the situation under control can be much worst.
[Go to top] top

Posted by Samson   USA  (683 posts)  [Biography] bio
Date Reply #7 on Tue 21 Jan 2003 09:04 AM (UTC)
Message
Was talking about open sockets actually. Not file handles. And I've at least traced down that they're coming out of the webserver module. Which I suppose was to be expected since the descriptor handling isn't the best in there. At least I've stopped it from bleeding past a copyover. :)

SmaugMuds.org: http://www.smaugmuds.org - The Smaug MUDs Community Center

"The past was erased, the erasure was forgotten, the lie became truth." -- George Orwell, 1984
[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Reply #8 on Wed 22 Jan 2003 12:52 AM (UTC)
Message
Another question I think fits in here. Whats up with copyover for SWR. It lags the login screen so you don't even see the intro screen. Any ideas on why it does that?

Thanks.

~Nick Cash
http://www.nick-cash.com
[Go to top] top

Posted by Boborak   USA  (228 posts)  [Biography] bio
Date Reply #9 on Wed 22 Jan 2003 01:12 AM (UTC)
Message
You confuse me a bit. Every version of copyover I've seen has had nothing to do with a login or intro. It's merely a save of who's connected and where they are located (and in the case of Samson's hotboot code, object and mobile positions too). So that when the copyover is complete, everything is put back were it was and the player experiences nothing more then what seems like a brief moment of bad lag. If you took out all of the messages too the player, most wouldn't likely even know a reboot occured.
[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Reply #10 on Wed 22 Jan 2003 08:50 PM (UTC)
Message
What I meant was that after I reboot and try to login with a differen't name the "help greeting" file doesn't even show up. It just says connected, its like horrible login lag. I hope that helps because its a weird problem. Anyways, thanks for the help.

~Nick Cash
http://www.nick-cash.com
[Go to top] top

Posted by Samson   USA  (683 posts)  [Biography] bio
Date Reply #11 on Fri 24 Jan 2003 12:35 PM (UTC)
Message
Not sure why SWR would bomb that way on a copyover, but it sounds like there's definitely some kind of problem. Not having worked with it before, I can't say for sure what the cause is. Which version of SWR? Perhaps if I get bored I'll look at it. Also, which version of copyover? :)

SmaugMuds.org: http://www.smaugmuds.org - The Smaug MUDs Community Center

"The past was erased, the erasure was forgotten, the lie became truth." -- George Orwell, 1984
[Go to top] top

Posted by Boborak   USA  (228 posts)  [Biography] bio
Date Reply #12 on Fri 24 Jan 2003 05:39 PM (UTC)
Message
Describe what happens during a copyover and right after, as well as what happens when you try to log on. By the way I understand it, the copyover works right, but when you or anyone else attmpts to log on to your mud after a copyover the 'greeting' screen is no displayed. Am I correct in this? If that's the case I have at least a partial idea what may be causing it.
[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Reply #13 on Sat 25 Jan 2003 04:17 AM (UTC)
Message
Sorry, forgot to check the forum for replies for a few days. Anyways, yes, that is the exact problem, it works fine but the 'Greeting' help file does not show up when you try to log on. It just says you are connected. And to answer your question Samson, its the copyover snippet from Kyndig. Its under snippets. Here is the URL:
http://www.kyndig.com/codes/diku/merc/smaug/Star_Wars
Anyways, sorry for the delay. Thanks for all the help.

~Nick Cash
http://www.nick-cash.com
[Go to top] top

Posted by Boborak   USA  (228 posts)  [Biography] bio
Date Reply #14 on Sat 25 Jan 2003 05:02 AM (UTC)
Message
Two questions. What client do you use? and Even though the greeting doesn't display, can you still log on by typing your name and such? Also, open up comm.c and in:

void new_descriptor()

look for this chunk of code:
/*
* Send the greeting.
*/
{
extern char * help_greeting;
if ( help_greeting[0] == '.' )
write_to_buffer( dnew, help_greeting+1, 0 );
else
write_to_buffer( dnew, help_greeting , 0 );
}

If you can still log on and that code is not there, see if you can locate something similar to it. But, if by chance you can't even log on properly, you have a much worst situation (you may have skipped a part in the snippet).
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


12,233 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]