Wednesday 15 September 2010

c - Persistent Connection on a web server HTTP1.1 -


I am trying to write a web server under Linux by using the protocol HTTP1.1. I have used selection for many requests and I want to apply a consistent connection but it does not work yet because I can not set up scheduling properly How can I do this? I think about the SetCop ​​function:

  SETOPOP (CONCORDY, SOL_COCK, SO_RCTVETO, (four *) AND TV, SACHOF (TV))   

This is not working either where the TV is a straight timeual.

Any suggestions?

SO_RCVTIMEO will work only when you are actually reading data < Code> Select () will not respect it > Select the () takes a timeout parameter in its last argument if you have a timer data structure, to set which connection You should adjust from time to time, then you can pass time range to () . If the return value is 0, then one time has expired, and you should end all the expired connections. After processing live connection (and resetting their idle scheduling in their timer data structure), you will need to see again that by selecting select () again First must be the time limit.

There are various data structures you can use, but among the popular people include time chakra and timer pile.

A time cycle is an array array arranged in the form of an array buffer, where each buffer position represents a time unit. If the wheel units are in seconds, you can construct a 300 element array to represent 5 minutes time. There is a sticky index that represents the last time a timer expires, and in the current state the current time module of the array will be the current. To add a timeout, calculate the whole time, which needs to expire, by the size of the module array, and add it to the list in that array position. All the buckets that have expired between the last index and the current situation, need to be ended. After the completion of the entries, the previous index is updated in the current state. To calculate the time till the next end, the bucket is being scanned, scanned to find a bucket with the entry starting from the current position.

A timer pile is basically a priority queue, where the entries that end sooner have a higher priority compared to those entries which are later terminated. Determines the expiration time on non-empty stacks.

If your app is inserting a lot of time and many timers, and then canceling them all the time, then a wheel may be more suitable, inserting the wheel and removing it from the wheel priority Queue is more efficient than inserting and deleting.

No comments:

Post a Comment