Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

question about writing threaded web server

Name: Anonymous 2009-04-21 0:42

I'm trying to teach myself threads and sockets in C and decided the best way was to write a multithreaded http server. I'm having a little bit of trouble putting together the pieces, can someone more knowledgeable than myself tell me whether I have the right idea?

I've figured out how to open and bind a socket. Here's what I'm trying to do after that:


int main() {

    // set up connection
    ...
    // already listening, socket connection var is sfd
    while(connfd = accept(sfd, NULL, NULL)
    {
        if(connfd < 0)
         // scream and die

        pthread_create( [ vars, handle thread with serv() ] );
    }
}

void* serve(void* args)
{
    /// declare vars used below
    accept( [appropriate args throughs *args] );
    recv( [from connection[ );
    // *request now contains the URL the client asked for
    send( [http 200 or 404, depending] );
    // mutex lock file pointer to log file, to log pages served
    // write to log file
    // mutex unlock log file

    pthread_exit([whatever arg it is]);
}


Is the general idea right?

Name: Anonymous 2009-04-21 6:03

>>19
What brain-damaged regex implementation doesn't let you specify the delimiter?

s@http://www.red-bean.com/guile/guile/old/2217.html@http://erlang.org/

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List