Original post:
I have been learning network programming from Beej's Guide to Network Programming for school. I'm currently working on a prototype for myself to communicate among multiple connections concurrently by using threads and I/O multiplexing. I'm getting a problem where when I receive a connection and call accept() to return a new file descriptor to "new_fd" instead of returning a new file descriptor it returns 1. This doesn't make sense to me because I'm not closing stdout anywhere in my code and accept() is supposed to return a reference to the socket as a new file descriptor, and as far as I know threads share the same file descriptors across a single process so it shouldn't be a problem that I have it threaded. I thought that the problem might be that I was connecting from my own computer using the loopback, but when I connected by referencing my ip address or another computer it also resulted in the same error of returning a fd of 1. I have no idea where to look anymore to solve this issue
Original posted code: http://pastebin.com/APQYjxg9 (I had posted all of my code)
Editing this for clarity. There were two things wrong with my code. The first one was pointed out by R.. immediately and that code snippet is here:
if (value = pthread_create((chat+chat_count), NULL, chatDaemon, (void *) &new_fd) != 0)
{ -snip- }
void * chatDaemon(void * fd)
{
int my_fd = *((int *)fd);
-snip-
}
I later figured out what went wrong and posted my answer. Code snippet for that here:
if (new_fd = accept(listen_fd, (struct sockaddr*) &(remoteHost), &addrlen) != -1) { -snip-}