开发者

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, &cli开发者_如何学Golen);
    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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜