Re: UDP Sockets & Clock Synchronization
Re: UDP Sockets & Clock Synchronization
- Subject: Re: UDP Sockets & Clock Synchronization
- From: Peter Sichel <email@hidden>
- Date: Thu, 28 Feb 2002 00:15:14 -0500
I've discovered there is a better way. Although not documented
in Stevens "UNIX Network Programming", I found an SO_TIMESTAMP option
in sys/socket.h
If the SO_TIMESTAMP option is enabled on a SOCK_DGRAM socket, the
recvmsg() call will return a timestamp corresponding to when the
datagram was received. The msg_control field in the msghdr structure
points to a buffer that contains a cmsghdr structure followed by a
struct timeval. The cmsghdr fields have the following values:
cmsg_len = sizeof(struct timeval)
cmsg_level = SOL_SOCKET
cmsg_type = SCM_TIMESTAMP
So even though you can't respond at interrupt time, you can capture
when UDP datagrams arrive without resorting to an NKE.
By including both the timestamp and send time in your response,
you should be able to calculate the relative time difference.
Enjoy!
- Peter
At 3:46 PM -0500 2/26/02, Peter Sichel wrote:
Blocking on recv() is no better than select(). You still have to
wait for the kernel to schedule you. select() has the advantage
that you can set a time out for any operation including connect()
and you can cancel by including another socket (pipe end) you
can make readable.
In OT, your notifier was called at interrupt time.
As I understand it, BSD networking does not offer this
level of performance. The closest you can get is to capture
time stamp information from an interface filter NKE or AppKit
driver.
I'd love to hear any better ideas.
- Peter
At 9:23 AM -0800 2/26/02, Vincent Lubet wrote:
Can't you just block your thread on recv() instead of using select()?
Vincent
On Monday, February 25, 2002, at 09:44 PM, Zack Morris wrote:
Hi, I am messing with sockets on OS X and I need a way to have an
"interrupt" that fires when a UDP packet comes in. Using select() doesn't
really help, because if my game runs at 30 fps, that means I have a 33ms
uncertainty about when a packet came in (if I poll the network each time
through my main loop). I need something similar to the asynch mode of OS 9.
That's because I send out a "ping" packet (using UDP) with the current time.
Ont the other end, the server needs to see the packet come in and return a
response packet as quickly as possible to mimimize the latency. The
original computer gets that response packet and looks at the server's time
and round trip time to compute how much to change the clock by. Obviously
throwing an extra 33ms in there doesn't help! Is there a way to do this?
P.S. It would be nice if this worked with GUSI so I could have one method,
but it's not mandatory...thanx for your time,
Zack Morris
--
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.