/* * packet.cpp * * Simulation of Chandy-Lamport algorithm * * This file is a part of Distributed Systems term thesis * Department KIV, ZCU Plzen * Author: Martin Sloup, msloup@students.zcu.cz */ #include #include #include #include #include #include "packet.h" #include "server.h" #include "util.h" void packet_send(int c, char operation, long value) { packet p; p.branch_id = htonl(branch_id); p.operation = operation; p.value = htonl(value); struct timeval send_at; // prepare packet send time because statistics gettimeofday(&send_at, NULL); p.send_at_sec = htonl(send_at.tv_sec); p.send_at_usec = htonl(send_at.tv_usec); if (send(c, &p, sizeof(packet), MSG_DONTWAIT) < 0) { fatal("Error occurs while sending packet"); } } void packet_send_at(struct timeval *send_at, packet *p) { send_at->tv_sec = ntohl(p->send_at_sec); send_at->tv_usec = ntohl(p->send_at_usec); }