fdopen blocks - originally titled -Looking for direction #2

  • Follow


I've been told I mis-titled my original message.

I have inherited an app that retrieves data for applets and is having
trouble running multiple sessions. I have located the problem but
being new to this field need help understanding why it occurs.

I've cut the code to make it more readable. The problem occurs when
you try to create a second connection at "data->in = fdopen(socket,
"rb");" . The statement will not return until the previous applet has
committed an action.

 pthread_t *thread;
 pthread_attr_t attr;

 length = sizeof(struct sockaddr_in);
 socket = accept(tcp_sock, (struct sockaddr *) &client_addr, &length);

 if (setsockopt(socket, SOL_TCP, TCP_NODELAY, &nodelay,
sizeof(nodelay)) < 0) error("Error setting connection socket option
2");
 if (setsockopt(socket, SOL_SOCKET, SO_SNDBUF, &bufsize,
sizeof(bufsize)) < 0) error("Error setting connection socket option
6");
 if (setsockopt(socket, SOL_SOCKET, SO_RCVBUF, &bufsize,
sizeof(bufsize)) < 0) error("Error setting connection socket option
7");

 pthread_attr_init(&attr);
 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 if (NUM_USERS < MAX_USERS / 5) { // first 20% users get faster system
I/O threads if allowed
  pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
 } else { pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS);
 };
 thread = malloc(sizeof(pthread_t));

 thread_data *data =  (thread_data *)malloc(sizeof(thread_data));
 data->data_socket = socket;
 data->in = fdopen(socket, "rb");
 data->out = fdopen(socket, "wb");
 pthread_create(thread, &attr, Service_Thread, (void *) data);
 pthread_attr_destroy(&attr);

Thanks,

Douglas
0
Reply douglasjd2000 2/21/2005 4:29:58 AM


0 Replies
115 Views

(page loaded in 0.043 seconds)


Reply: