Commit 1079affb authored by Andreas Schmidt's avatar Andreas Schmidt

Destroy packet if pacing or wait for space fails.

parent 63e73bd7
......@@ -78,13 +78,18 @@ static bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
memset(buf, 0, sizeof(buf));
prrtPacketLength_t length = PrrtPacket_size(packet);
prrtPacketLength_t payloadLength = packet->payloadLength;
PrrtSocket_pace(sock_ptr);
bool paceSuccessful = PrrtSocket_pace(sock_ptr);
if (!paceSuccessful) {
PrrtPacket_destroy(packet);
return false;
}
int64_t space = PrrtReceiver_get_space(sock_ptr->receiver);
while (space < sock_ptr->maximum_payload_size) {
//PrrtReceiver_check_rto(sock_ptr->receiver, packet->sequenceNumber, PrrtPacket_type(packet));
PrrtReceiver_wait_for_space(sock_ptr->receiver);
if(PrrtSocket_closing(sock_ptr)) {
PrrtPacket_destroy(packet);
return false;
}
space = PrrtReceiver_get_space(sock_ptr->receiver);
......
......@@ -266,7 +266,7 @@ bool PrrtSocket_closing(PrrtSocket *s) {
return atomic_load_explicit(&s->closing, memory_order_acquire);
}
void PrrtSocket_pace(PrrtSocket *s) {
bool PrrtSocket_pace(PrrtSocket *s) {
if (s->pacingEnabled && s->nextSendTime != 0) {
debug(DEBUG_DATATRANSMITTER, "About to check for pacing.");
prrtTimeDifference_t diff = 0;
......@@ -275,11 +275,15 @@ void PrrtSocket_pace(PrrtSocket *s) {
diff = ((prrtTimeDifference_t) s->nextSendTime) - now;
if (diff > 0) {
usleep_nano((uint32_t) diff);
if(PrrtSocket_closing(s)) {
return false;
}
}
} while (diff > 0);
} else {
usleep_nano(1);
}
return true;
}
int32_t PrrtSocket_receive_asap(PrrtSocket *s, void *buf_ptr, struct sockaddr* addr) {
......
......@@ -116,7 +116,7 @@ int PrrtSocket_connect(PrrtSocket *s, const char *host, uint16_t port);
int PrrtSocket_send_async(PrrtSocket *s, const uint8_t *data, const size_t data_len);
int PrrtSocket_send_sync(PrrtSocket *s, const uint8_t *data, size_t data_len);
void PrrtSocket_pace(PrrtSocket *s);
bool PrrtSocket_pace(PrrtSocket *s);
int32_t PrrtSocket_recv(PrrtSocket *s, void *buf_ptr, struct sockaddr* addr);
......
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