Unix Programming - fdopen blocks - originally titled -Looking for direction

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > February 2005 > fdopen blocks - originally titled -Looking for direction





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author fdopen blocks - originally titled -Looking for direction
Douglas Dillon

2005-02-21, 2:48 am

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
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com