2

I am building a multi-threaded HTTP server. This is part of a university course I am taking. The server needs to have a dedicated thread which has to listen to incoming HTTP requests and insert them in a ready queue from where a scheduling thread will assign execution threads.

I don't know how to do that. If anyone could explain the direction in which I should proceed it would be very helpful.

[I had recently asked an unrelated question here: How to parse HTTP requests from a C based web server ]

Community
  • 1
  • 1
Chaitanya Nettem
  • 1,209
  • 2
  • 23
  • 45
  • What have you attempted so far? Read a request, stuff its data and socket handle into a structure and put it in the queue, schedule it, let that task thread process the request as needed and send the response to the original socket. What's hard about that? – Remy Lebeau Nov 01 '13 at 23:16
  • I am confused by the fact that there is a listen queue which is acted on by `listen()`. http://man7.org/linux/man-pages/man2/listen.2.html So should I be trying to use that queue or should I be using my own queue [where I would be stuffing structs for each request which contain the integers returned by accept()] – Chaitanya Nettem Nov 01 '13 at 23:24
  • 1
    `listen()` opens the queue of inbound client connections that `accept()` establishes connections from, nothing more. They have no concept of how the connections will be used. HTTP requests are data packets sent over those connections after they have been established. So you need to do your own queuing of the HTTP processing over the accepted connections. – Remy Lebeau Nov 02 '13 at 00:06
  • @remy lebeau can you please post the c code of the server you described on the first comment? – Jones G Dec 08 '19 at 22:50
  • @JamesGuana there is no C code to post. What I described earlier was just a general overview of the kind of tasks needed, based on the OP's description of the server he was making. – Remy Lebeau Dec 08 '19 at 23:24
  • Your description of the code is what i am looking for but i could not find a code that does exactly that. – Jones G Dec 09 '19 at 10:13
  • I think you are the one that can answer my question, the code you describe is exactly what i want to solve here https://stackoverflow.com/questions/55085401/how-to-queue-the-previous-http-request-and-read-another-request-without-blocking – Jones G Dec 09 '19 at 10:25

0 Answers0