Commit de944133 authored by Tommy Olofsson's avatar Tommy Olofsson
Browse files

Fixed a bug with the vx resend queue.

parent bb3b35f9
......@@ -262,9 +262,11 @@ void firefly_transport_udp_posix_write(unsigned char *data, size_t data_size,
int res;
conn_udp = conn->transport->context;
printf("sending\n");
res = sendto(conn_udp->socket, (void *) data, data_size, 0,
(struct sockaddr *) conn_udp->remote_addr,
sizeof(*conn_udp->remote_addr));
printf("sent\n");
if (res == -1) {
firefly_error(FIREFLY_ERROR_TRANS_WRITE, 1, "sendto() failed");
firefly_connection_raise_later(conn,
......@@ -394,7 +396,6 @@ static int firefly_transport_udp_posix_read_event(void *event_arg)
struct transport_llp_udp_posix *llp_udp;
struct firefly_connection *conn;
printf("exec read ev\n");
ev_arg = event_arg;
llp_udp = ev_arg->llp->llp_platspec;
......@@ -421,7 +422,7 @@ static int firefly_transport_udp_posix_read_event(void *event_arg)
ev_arg->llp->protocol_data_received_cb(conn, ev_arg->data, ev_arg->len);
}
free(ev_arg);
puts("ev ok");
return 0;
}
......@@ -477,7 +478,7 @@ void firefly_transport_udp_posix_read(struct firefly_transport_llp *llp)
/* printf("recv %d byte\n", pkg_len); */
res = recvfrom(llp_udp->local_udp_socket, (void *) ev_arg->data, pkg_len, 0,
(struct sockaddr *) &remote_addr, (void *) &len);
printf("recv'd %d byte\n", res);
/* printf("recv'd %d byte\n", res); */
if (res == -1) {
char err_buf[ERROR_STR_MAX_LEN];
#ifdef LABCOMM_COMPAT
......@@ -497,7 +498,7 @@ void firefly_transport_udp_posix_read(struct firefly_transport_llp *llp)
FIREFLY_PRIORITY_HIGH,
firefly_transport_udp_posix_read_event,
ev_arg, 0, NULL);
printf("put read ev\n");
/* printf("put read ev\n"); */
}
bool sockaddr_in_eq(struct sockaddr_in *one, struct sockaddr_in *other)
......
......@@ -96,11 +96,8 @@ int64_t firefly_event_queue_vx_add(struct firefly_event_queue *eq,
res = firefly_event_add(eq, prio, execute, context, nbr_deps, deps);
semGive(ctx->lock);
if (res > 0) {
printf("ADDING ev\n");
semGive(ctx->signal);
printf("ADDED ev\n");
} else
printf("FAILED TO ADD EVENT\n");
}
return res;
}
......@@ -125,32 +122,24 @@ void *firefly_event_vx_thread_main(void *args)
semTake(ctx->lock, WAIT_FOREVER);
event_left = firefly_event_queue_length(eq);
finish = ctx->event_loop_stop;
printf("EQ LEN: %d, DONE: %d\n", event_left, finish);
while (event_left <= 0 && !finish) {
semGive(ctx->lock);
printf("WAIT SIG\n");
semTake(ctx->signal, WAIT_FOREVER);
printf("GOT SIG\n");
semTake(ctx->lock, WAIT_FOREVER);
finish = ctx->event_loop_stop;
event_left = firefly_event_queue_length(eq);
}
ev = firefly_event_pop(eq);
semGive(ctx->lock);
printf("GOT EV?\n");
if (ev) {
/* TODO: Retval can indicate badly contructed event, or
* failed execution. Should this be handled?
*/
printf("EXECUTING EV. %p\n", ev->execute);
firefly_event_execute(ev);
printf("EXECUTING EV DONE.\n");
semTake(ctx->lock, WAIT_FOREVER);
firefly_event_return(eq, &ev);
semGive(ctx->lock);
printf("(EVENT RETURNED)\n");
} else
printf("NO EVENT\n");
}
}
/* semTake(ctx->lock, WAIT_FOREVER); */
......
......@@ -78,7 +78,9 @@ unsigned char firefly_resend_add(struct resend_queue *rq,
re->timeout = timeout_ms;
re->prev = NULL;
printf("WAITING FOR RQ LOCK\n");
semTake(rq->lock, WAIT_FOREVER);
printf("TOOK RQ LOCK\n");
re->id = rq->next_id++;
if (rq->next_id == 0) {
rq->next_id = 1;
......@@ -204,8 +206,11 @@ int firefly_resend_wait(struct resend_queue *rq,
clock_gettime(CLOCK_REALTIME, &now);
res = rq->first;
while (!res || !timespec_past(&now, &res->resend_at)) {
/* TODO: Port of posix code. Clean it up. */
if (!res) {
semGive(rq->lock);
semTake(rq->sig, WAIT_FOREVER);
semTake(rq->lock, WAIT_FOREVER);
} else {
struct timespec at;
long timeout;
......@@ -213,7 +218,9 @@ int firefly_resend_wait(struct resend_queue *rq,
at = res->resend_at;
timeout = ((at.tv_sec - now.tv_sec) * 1000000 +
(at.tv_nsec - now.tv_nsec) / 1000) / sysClkRateGet();
semGive(rq->lock);
semTake(rq->sig, timeout);
semTake(rq->lock, WAIT_FOREVER);
}
clock_gettime(CLOCK_REALTIME, &now);
res = rq->first;
......
Supports Markdown
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