hello,
is it necessary to use pthread and select if i want to build a http server and wish to have concurrent client access?
like this code from the gnuc library page (delorie.com/gnu/docs/glibc/libc_340.html)
such as how you might see the comments if i may create a pthread_create when input arrives on the socket and it is not already an established connection,
hope this makes sense,
regards
Code:
while (1)
{
/* Block until input arrives on one or more active sockets. */
read_fd_set = active_fd_set;
if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, NULL) < 0)
{
perror ("select");
exit (EXIT_FAILURE);
}
/* Service all the sockets with input pending. */
for (i = 0; i < FD_SETSIZE; ++i)
if (FD_ISSET (i, &read_fd_set))
{
if (i == sock)
{
/* Connection request on original socket. */
int new;
size = sizeof (clientname);
//do i need to put a pthread_create() here in
//order to have concurrent client execution
//and handle the accepting/recv'ing/sending etc to the socket
//such as in the normal multithreaded/concurrent server
new = accept (sock,
(struct sockaddr *) &clientname,
&size);
if (new < 0)
{
perror ("accept");
exit (EXIT_FAILURE);
}
fprintf (stderr,
"Server: connect from host %s, port %hd.\n",
inet_ntoa (clientname.sin_addr),
ntohs (clientname.sin_port));
FD_SET (new, &active_fd_set);
}
else
{
/* Data arriving on an already-connected socket. */
if (read_from_client (i) < 0)
{
close (i);
FD_CLR (i, &active_fd_set);
}
}
}
}
}