Thread: Bad File number?

  1. #1
    Unregistered
    Guest

    Question Bad File number?

    Alright, as some of you know, I downloaded Cygwin to compile Unix code under windows.

    I have a MUD(Multi User Demension/Dungeon) that I am writing. I have a nice shell that allows player connection, and character creation. It compiled 100% fine under the Linux server I WAS using. Now I downloaded Cygwin, and I have a slight problem.

    It compiles fine, with no errors. However, when I run the program it logs an error in the log files, and then shuts down.

    Heres the error I got:
    *Wed May 29 15:04:50 2002: mux select(): Bad file number*

    And Heres the Code that uses that:
    Code:
    ...
    int max_files;
    ...
    
    	if ((max_files = getdtablesize()) == -1) {
    		log_to_file(LOG_ERRNO, "getdtablesize()");
    		exit(EXIT_FAILURE);
    	}
    
    	is_running = TRUE;
    	
    	while (is_running) {
    		FD_ZERO(&input_sfd);
    		FD_ZERO(&output_sfd);
    		FD_ZERO(&exception_sfd);
    
    		FD_SET(control, &input_sfd);
    		
    		for (con = first_con; con != NULL; con = con->next) {
    			FD_SET(con->sd, &input_sfd);
    			FD_SET(con->sd, &output_sfd);
    			FD_SET(con->sd, &exception_sfd);
    		}
    
    		if (select(max_files, &input_sfd, &output_sfd, &exception_sfd, &tv_zero) == -1) {
    			log_to_file(LOG_ERRNO, "mux select()");
    			exit(EXIT_FAILURE);
    		}
    ...
    Some of that may be irrelevent... but you can see the 'mux select()' part. I figured bad file number means that it can't log the error number? I'm not sure. And I've no clue why it would be messing up. I'm not a genius at sockets, and I followed a unix tutorial and fumbled my way through creating the basic MUD engine, but it works fine. Well, it used to. Nothing has changed sense I compiled on the server. does anyone have a clue to why it is not working? Or point me in a general direction?

    Thanks!

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    44

    Talking Oops!

    Sorry! I enetered my password wrong on the above post. Just wanted you all to know who was posting. -g-
    [Strut]

    I lay on my bed watching the stars, and I thought to myself... Where the hell is my roof?

  3. #3
    Registered User
    Join Date
    Sep 2001
    Location
    Fiji
    Posts
    212
    When using cygwin, there is a file in cywins' home directory something like "cygwing1.dll" or to that effect. this file has to be copied to the directory the executable is in.

    I don't know if this is causing it cause I have no idea on MUD, except the stuff you played with when your a kid, and made pies out of.

    Hope I helped.

    kwigibo

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    44

    Post

    It doesn't have a problem running the actual executable. Once the program runs, it goes into a loop and keeps checking each connection.

    Thats where the problem comes in on the if statment of select().

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I can simulate this problem if I pass a file descriptor to select that is already closed.

    Are you sure you are removing dead entries from the con list?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM