Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expressed changed status as return statement #243

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/udx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2570,14 +2570,14 @@ udx_stream_change_remote (udx_stream_t *stream, udx_socket_t *socket, uint32_t r
stream->remote_id = remote_id;
set_stream_socket(stream, socket);

if (stream->seq != stream->remote_acked) {
bool defer_change = stream->seq != stream->remote_acked;
if (defer_change) {
debug_printf("change_remote: id=%u RA=%u Seq=%u\n", stream->local_id, stream->remote_acked, stream->seq);
stream->remote_changing = true;
stream->seq_on_remote_changed = stream->seq;
stream->on_remote_changed = on_remote_changed;
} else {
debug_printf("change_remote: id=%u RA=%u Seq=%u, acting now!\n", stream->local_id, stream->remote_acked, stream->seq);
on_remote_changed(stream);
}

stream->mtu = UDX_MTU_BASE;
Expand All @@ -2586,7 +2586,10 @@ udx_stream_change_remote (udx_stream_t *stream, udx_socket_t *socket, uint32_t r
stream->mtu_probe_size = UDX_MTU_BASE; // starts with first ack, counts as a confirmation of base
stream->mtu_max = UDX_MTU_MAX; // revised in connect()

return update_poll(stream->socket);
int err = update_poll(stream->socket);
if (err != 0) return err;

return !defer_change;
}

int
Expand Down
9 changes: 7 additions & 2 deletions test/stream-change-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ on_remote_change (udx_stream_t *s) {
}
}

void
on_immediate_change (udx_stream_t *s) {
assert(false && "should not be called");
}

void
on_read (udx_stream_t *handle, ssize_t read_len, const uv_buf_t *buf) {
int e;
Expand All @@ -71,8 +76,8 @@ on_read (udx_stream_t *handle, ssize_t read_len, const uv_buf_t *buf) {
// swap to relay 1/3 of the way into the stream

if (nbytes_read > (NBYTES_TO_SEND / 3) && !changed) {
e = udx_stream_change_remote(&astream, &bsock, 4, (struct sockaddr *) &daddr, on_remote_change);
assert(e == 0 && "reconnect");
e = udx_stream_change_remote(&astream, &bsock, 4, (struct sockaddr *) &daddr, on_immediate_change);
assert(e == 1 && "reconnect");

e = udx_stream_change_remote(&dstream, &csock, 1, (struct sockaddr *) &aaddr, on_remote_change);
assert(e == 0 && "reconnect");
Expand Down