2 Replies - 664 Views - Last Post: 16 March 2011 - 12:30 AM Rate Topic: -----

#1 djenriquez  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 79
  • Joined: 22-November 09

code linearity (networking calculating data rate)

Posted 10 March 2011 - 04:49 PM

I'm working on code that returns the time it takes to send a file from one computer to another. The basic idea is:

// obtain start timestamp
start = time (NULL);

// transfer data
send(sock, temps, strlen(temps) ,0);

// obtain end timestamp
end = time (NULL);

end - start = transfer_time



When I run the code, it states that the start and end times are the same regardless of the file size, so I'm thinking that it executes without waiting for the send to finish - the end time is taken before the send is actually done. Does the code wait until the data is completely finished sending before executing the next line? If not, how can I ensure that the end time is taken only when the data is finished sending?

Is This A Good Question/Topic? 0
  • +

Replies To: code linearity (networking calculating data rate)

#2 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1762
  • View blog
  • Posts: 3,417
  • Joined: 30-May 10

Re: code linearity (networking calculating data rate)

Posted 11 March 2011 - 01:53 AM

Are you assuming that time() returns an infinitely precise answer?

Because on my machine, anything less than a second (which is a LONG LONG time for most machine operations) would appear to take zero time.

Perhaps you need a faster clock.
Was This Post Helpful? 0
  • +
  • -

#3 djenriquez  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 79
  • Joined: 22-November 09

Re: code linearity (networking calculating data rate)

Posted 16 March 2011 - 12:30 AM

View PostSalem_c, on 11 March 2011 - 02:53 AM, said:

Are you assuming that time() returns an infinitely precise answer?

Because on my machine, anything less than a second (which is a LONG LONG time for most machine operations) would appear to take zero time.

Perhaps you need a faster clock.


Ah thanks! Changed to ms and worked fine.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1