Set sockets parameters before activating up send_packet timer
This commit is contained in:
parent
2d3d859d9b
commit
d791054cfe
1 changed files with 12 additions and 12 deletions
24
echoc.c
24
echoc.c
|
@ -161,18 +161,6 @@ main(int argc, char *argv[])
|
||||||
disconnected = 0;
|
disconnected = 0;
|
||||||
memset(&client, 0, sizeof(client));
|
memset(&client, 0, sizeof(client));
|
||||||
|
|
||||||
/* timer values */
|
|
||||||
itv.it_interval.tv_usec = interval*1000;
|
|
||||||
itv.it_interval.tv_sec = 0;
|
|
||||||
itv.it_value.tv_usec = interval*1000;
|
|
||||||
itv.it_value.tv_sec = 0;
|
|
||||||
if (setitimer(ITIMER_REAL, &itv, NULL) == -1)
|
|
||||||
err(2, "setitimer");
|
|
||||||
|
|
||||||
signal(SIGALRM, send_packet);
|
|
||||||
|
|
||||||
gettimeofday(&last_ts, NULL);
|
|
||||||
|
|
||||||
recvbuf = malloc(len);
|
recvbuf = malloc(len);
|
||||||
if (recvbuf == NULL)
|
if (recvbuf == NULL)
|
||||||
err(2, "malloc receive buffer");
|
err(2, "malloc receive buffer");
|
||||||
|
@ -186,6 +174,18 @@ main(int argc, char *argv[])
|
||||||
if (setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &ch, sizeof(ch)) < 0)
|
if (setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &ch, sizeof(ch)) < 0)
|
||||||
err(2, "setsockopt IP_MTU_DISCOVER");
|
err(2, "setsockopt IP_MTU_DISCOVER");
|
||||||
#endif
|
#endif
|
||||||
|
/* timer values */
|
||||||
|
itv.it_interval.tv_usec = interval*1000;
|
||||||
|
itv.it_interval.tv_sec = 0;
|
||||||
|
itv.it_value.tv_usec = interval*1000;
|
||||||
|
itv.it_value.tv_sec = 0;
|
||||||
|
if (setitimer(ITIMER_REAL, &itv, NULL) == -1)
|
||||||
|
err(2, "setitimer");
|
||||||
|
|
||||||
|
signal(SIGALRM, send_packet);
|
||||||
|
|
||||||
|
gettimeofday(&last_ts, NULL);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
/* poll() loop to handle interruptions by SIGALRM */
|
/* poll() loop to handle interruptions by SIGALRM */
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue