Jump to content
  • Advertisement
Sign in to follow this  
beebs1

Does time() return consistent values?

This topic is 2497 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hiya,

I'm looking to use the time() function in <ctime> to implement authentication tickets.

I can imagine a situation where there is some drift between the values on different machines - does anyone know how consistent time() is in this way?

I'm assuming it works off the system clock or...?

Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
Yes, it works off of the system clock. So it's only as consistent as your system clocks are. Which may not be very consistent from my personal experience.

Share this post


Link to post
Share on other sites

Indeed. That's great, thanks for the quick reply.

Funny story I'll give to expand on what I mean by system clocks not being very consistent. At work, I was making a program that would communicate certain things to our servers and upload assets to Amazon S3. I was making the C++ API, while my boss was making the Java API. Amazon S3 requires you to do some special hashing of keys and tokens, and part of the token being hashed is the current time. My S3 uploader worked just fine on most computers, but on one computer it was failing. The Java version which my boss made worked just fine on it though.

After a lot of debugging and checking the responses I was getting from Amazon, it turns out the computer's system clock was waaaay off. Amazon gives you a 15 minute window to begin uploading a file (that is, the hashed key is only valid for 15 minutes from the correct time), and I kept saying the time was really off, so it kept rejecting me (and included in the rejection message was the correct time from the S3 server). Turns out the Java version (because a 3rd party S3 library was used, whereas I was doing the C++ uploading from scratch) would automatically parse the rejection message, pull out the time that Amazon said it was, and try again. So that's why the Java version worked and mine failed.

Moral of the story: the bug isn't always in the code, and if you're doing time-dependent communications between two machines, be careful of their system clocks and find a way to gracefully deal when one might be off by several years.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!