Error Accepting Connection Bad File Descriptor
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions connect bad file descriptor openssl you might have Meta Discuss the workings and policies of this bad file descriptor error in c site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers write error bad file descriptor or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a
Socket Error Bad File Descriptor
community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up socket programming: 'accept: Bad file descriptor' up vote 2 down vote favorite 1 I'm trying to write a game that will let multiple clients connect and play - below is the relevant code wget error bad file descriptor (it's very messy - cleaning up later): Edit: I realized it's a lot of scrolling... the crash occurs towards the end of the game during: std::cout << black_hits << " black hits & " << white_hits << " white hits.\n"; if (black_hits == 4) { std::cout << "you won!\n"; std::cin.ignore().get(); close(client); //<<<< CRASH HERE return 0; } Not really a crash I guess... but close enough :) #include
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn socket bad file descriptor python more about Stack Overflow the company Business Learn more about hiring developers or posting
Bad File Descriptor Socket Accept
ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community
Bad File Descriptor Recv
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Linux server socket - Bad file descriptor up vote 3 http://stackoverflow.com/questions/21596004/socket-programming-accept-bad-file-descriptor down vote favorite I have a problem with a server socket under Linux. For some reason unknown to me the server socket vanishes and I get a Bad file descriptor error in the select call that waits for an incomming connection. This problem always occurs when I close an unrelated socket connection in a different thread. This happens on an embedded Linux with 2.6.36 Kernel. Does anyone know http://stackoverflow.com/questions/11735014/linux-server-socket-bad-file-descriptor why this would happen? Is it normal that a server socket can simply vanish resulting in Bad file descriptor? edit: The other socket code implements a VNC Server and runs in a completely different thread. The only thing special in that other code is the use of setjmp/longjmp but that should not be a problem. The code that create the server socket is the following: int server_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); struct sockaddr_in saddr; memset(&saddr, 0, sizeof(saddr)); saddr.sin_family = AF_INET; saddr.sin_addr.s_addr = htonl(INADDR_ANY); saddr.sin_port = htons(1234); const int optionval = 1; setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &optionval, sizeof(optionval)); if (bind(server_socket, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) { perror("bind"); return 0; } if (listen(server_socket, 1) < 0) { perror("listen"); return 0; } I wait for an incomming connection using the code below: static int WaitForConnection(int server_socket, struct timeval *timeout) { fd_set read_fds; FD_ZERO(&read_fds); int max_sd = server_socket; FD_SET(server_socket, &read_fds); // This select will result in 'EBADFD' in the error case. // Even though the server socket was not closed with 'close'. int res = select(max_sd + 1, &read_fds, NULL, NULL, timeout); if (res > 0) { struct sockaddr_in caddr; socklen_t clen = sizeof(caddr); return accept(server_socket, (struct sockaddr *) &caddr, &clen); } return -1; } ed
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this http://stackoverflow.com/questions/29400649/linux-socket-bad-file-descriptor site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x http://forums.devshed.com/programming-42/socket-accept-bad-file-descriptor-423893.html Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Linux Socket bad file Bad file Descriptor up vote 0 down vote favorite Ok,i couldn’t find if this is a duplicate or no, so i decided to post. We're getting into Sockets (beginner level sockets) now and i had be given this code to make the client send a simple message to the server by using send() and recv(). However, everything i tried doesn’t seem to get rid bad file descriptor of the "error: Bad File Descriptor" and newsockfd always returns the value -1. Im just confused and have no idea why it doesn’t work. I've been given 3 files. defs.h #include
Search Username Password Remember Me? Register Lost Password? facebook google twitter rss Free Web Developer Tools Advanced Search Forum Programming Languages C Programming Socket accept: Bad file descriptor Thread: Socket accept: Bad file descriptor Share This Thread Tweet This + 1 this Post To Linkedin Subscribe to this Thread Subscribe to This Thread February 13th, 2007,02:04 PM #1 No Profile Picture Jason Knight View Profile View Forum Posts Contributing User Devshed Newbie (0 - 499 posts) Join Date Jun 2003 Location Long Beach, CA Posts 117 Rep Power 14 Socket accept: Bad file descriptor http://rafb.net/p/qYppK422.html That's my code, this is my error: Code: [jason@1jzgte chatserver]$ ./server_threads ***************************** ------------------------------ ***************************** accept: Bad file descriptor [jason@1jzgte chatserver]$ It starts up with the first line of ***, then waits for a connection. When you connect it does the --- and then the *** again. Then it exits with the bad file descriptor error. What's causing this? Faq Reply With Quote February 13th, 2007,02:16 PM #2 dwise1_aol View Profile View Forum Posts Contributing User Devshed Supreme Being (6500+ posts) Join Date Jan 2003 Location USA Posts 7,323 Rep Power 2225 Because you closed the listening socket, sock. The first thread has been created, so now you've come back around and are calling accept() for the second time. Only there's no listening socket anymore. I also question closing newsock inside the loop. I think that it should be the responsibility of the thread to close the socket when it's done with it. I believe that by closing newsock outside the thread, you're closing that thread's socket out from under it. Faq Reply With Quote Share This Thread Tweet This + 1 this Post To Linkedin Subscribe to this Thread Subscribe to This Thread « Previous Thread | Next Thread » -- vB4 Default Style-- devshed_2014 Contact Us Developer Forums Archive Top Devshed i