FourOfAKind
FourOfAKind

Reputation: 2418

Calling Accept() second time gives new socket for the same client request

I like to write a server program with two threads, one thread for accepting requests and queuing them. Second one, worker thread, for processing them (I have not written this yet). Here is the pseudo code.

    while (1) {

    newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
    read_from_newsockfd()
    put_in_queue  

    // I am not closing the newsockfd here. If I close it here how 
to I communicate with the client from my second worker thread.
    }

Now when I send the request from browser, accept() gets called second time giving another socket for the same request without blocking. I tried sending second request from different browser, I got segmentation fault. Could any one please tell me how to approach this problem?

Upvotes: 1

Views: 312

Answers (2)

Jon Skeet
Jon Skeet

Reputation: 1500675

Is it possible that the browser is making multiple requests, in particular for /favicon.ico as well as the HTML?

I suggest you use Wireshark to see what's going on at the network level.

Upvotes: 1

Mahmoud Al-Qudsi
Mahmoud Al-Qudsi

Reputation: 29539

Most likely, your client is sending multiple requests for multiple resources?

Upvotes: 0

Related Questions