Commit 6ce8b49a authored by Joanne Hugé's avatar Joanne Hugé

Fix mistakes regarding timestamps configuration

parent c73d8534
...@@ -41,9 +41,9 @@ ...@@ -41,9 +41,9 @@
#define MESSAGE ((uint32_t)0x00FACADE) #define MESSAGE ((uint32_t)0x00FACADE)
#define NSEC_PER_SEC 1000000000 #define NSEC_PER_SEC 1000000000
static int process_socket_error_queue(int fd); static int process_socket_error_queue();
static void print_timestamps(struct msghdr *msg); static void print_timestamps(struct msghdr *msg);
static void process_timestamps(int sock); static void process_timestamps(int recvmsg_flags);
static int so_priority = 3; static int so_priority = 3;
static struct sock_txtime sk_txtime; static struct sock_txtime sk_txtime;
...@@ -130,6 +130,8 @@ void send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime, ...@@ -130,6 +130,8 @@ void send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime,
.fd = fd, .fd = fd,
}; };
int sendmsgerr; int sendmsgerr;
int res;
fd_set readfs;
memset(&sin, 0, sizeof(sin)); memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
...@@ -163,34 +165,42 @@ void send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime, ...@@ -163,34 +165,42 @@ void send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime,
error(EXIT_FAILURE, errno, "sendmsg failed, ret value: %d\n", sendmsgerr); error(EXIT_FAILURE, errno, "sendmsg failed, ret value: %d\n", sendmsgerr);
if(use_timestamps) { if(use_timestamps) {
#ifdef DEBUG
printf("Polling for timestamps...\n"); FD_ZERO(&readfs);
#endif FD_SET(fd, &readfs);
poll(&poll_fd, 1, 0);
process_timestamps(fd); res = select(fd + 1, &readfs, 0, NULL, NULL);
printf("select returned: %d, %s\n", res, res < 0 ? strerror(errno) : "success");
if (res > 0) {
if (FD_ISSET(fd, &readfs)) printf("ready for reading\n");
process_timestamps(MSG_ERRQUEUE);
}
} }
} }
static void process_timestamps(int sock) { static void process_timestamps(int recvmsg_flags) {
char data[256];
struct msghdr msg; struct msghdr msg;
struct iovec entry; struct iovec entry;
struct sockaddr_in from_addr;
struct { struct {
struct cmsghdr cm; struct cmsghdr cm;
char control[512]; char control[512];
} control; } control;
int res;
#ifdef DEBUG
printf("process_timestamps\n");
#endif
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
msg.msg_iov = &entry; msg.msg_iov = &entry;
msg.msg_iovlen = 1; msg.msg_iovlen = 1;
entry.iov_base = data;
entry.iov_len = sizeof(data);
msg.msg_name = (caddr_t)&from_addr;
msg.msg_namelen = sizeof(from_addr);
msg.msg_control = &control; msg.msg_control = &control;
msg.msg_controllen = sizeof(control); msg.msg_controllen = sizeof(control);
if (recvmsg(sock, &msg, MSG_DONTWAIT) == -1) { if (recvmsg(fd, &msg, recvmsg_flags | MSG_DONTWAIT) == -1) {
fprintf(stderr, "recvmsg failed"); fprintf(stderr, "recvmsg failed\n");
} }
else { else {
print_timestamps(&msg); print_timestamps(&msg);
...@@ -254,7 +264,7 @@ static void print_timestamps(struct msghdr *msg) { ...@@ -254,7 +264,7 @@ static void print_timestamps(struct msghdr *msg) {
/* /*
* Code from scheduled_tx_tools * Code from scheduled_tx_tools
*/ */
static int process_socket_error_queue(int fd) { static int process_socket_error_queue() {
uint8_t msg_control[CMSG_SPACE(sizeof(struct sock_extended_err))]; uint8_t msg_control[CMSG_SPACE(sizeof(struct sock_extended_err))];
unsigned char err_buffer[sizeof(tx_buffer)]; unsigned char err_buffer[sizeof(tx_buffer)];
struct sock_extended_err *serr; struct sock_extended_err *serr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment