Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
=========== DESCRIPTION =========== I added a paragraph for ``SO_TIMESTAMP``, and modified the paragraph for ``SIOCGSTAMP`` in relation to ``SO_TIMESTAMPNS``. I based the documentation on the existing ``SO_TIMESTAMP`` documentation, and on my experience using ``SO_TIMESTAMPNS``. I asked a question on stackoverflow, which helped me understand ``SO_TIMESTAMPNS``: https://stackoverflow.com/q/60971556/6872717 Testing of the feature being documented ======================================= I wrote a simple server and client test. In the client side, I connected a socket specifying ``SOCK_STREAM`` and ``"tcp"``. Then I enabled timestamp in ns: .. code-block:: c int enable = 1; if (setsockopt(sd, SOL_SOCKET, SO_TIMESTAMPNS, &enable, sizeof(enable))) goto err; Then I prepared the msg header: .. code-block:: c char buf[BUFSIZ]; char cbuf[BUFSIZ]; struct msghdr msg; struct iovec iov; memset(buf, 0, ARRAY_BYTES(buf)); iov.iov_len = ARRAY_BYTES(buf) - 1; iov.iov_base = buf; msg.msg_name = NULL; msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = cbuf; msg.msg_controllen = ARRAY_BYTES(cbuf); And got some times before and after receiving the msg: .. code-block:: c struct timespec tm_before, tm_recvmsg, tm_after, tm_msg; clock_gettime(CLOCK_REALTIME, &tm_before); usleep(500000); clock_gettime(CLOCK_REALTIME, &tm_recvmsg); n = recvmsg(sd, &msg, MSG_WAITALL); if (n < 0) goto err; usleep(1000000); clock_gettime(CLOCK_REALTIME, &tm_after); After that I read the timestamp of the msg: .. code-block:: c struct cmsghdr *cmsg; for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SO_TIMESTAMPNS) { memcpy(&tm_msg, CMSG_DATA(cmsg), sizeof(tm_msg)); break; } } if (!cmsg) goto err; And finally printed the results: .. code-block:: c double tdiff; printf("%s\n", buf); tdiff = timespec_diff_ms(&tm_before, &tm_recvmsg); printf("tm_r - tm_b = %lf ms\n", tdiff); tdiff = timespec_diff_ms(&tm_before, &tm_after); printf("tm_a - tm_b = %lf ms\n", tdiff); tdiff = timespec_diff_ms(&tm_before, &tm_msg); printf("tm_m - tm_b = %lf ms\n", tdiff); Which printed: :: asdasdfasdfasdfadfgdfghfthgujty 6, 0; tm_r - tm_b = 500.000000 ms tm_a - tm_b = 1500.000000 ms tm_m - tm_b = 18.000000 ms System: :: Linux debian 5.4.0-4-amd64 #1 SMP Debian 5.4.19-1 (2020-02-13) x86_64 GNU/Linux gcc (Debian 9.3.0-8) 9.3.0 Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
- Loading branch information