diff --git a/include/reactor-uc/network_channel.h b/include/reactor-uc/network_channel.h index 0f5bb35c..ac439a0f 100644 --- a/include/reactor-uc/network_channel.h +++ b/include/reactor-uc/network_channel.h @@ -23,14 +23,15 @@ typedef struct NetworkChannel NetworkChannel; struct NetworkChannel { /** - * @brief Used to identify this NetworkChannel among other NetworkChannels at the other federate. + * @brief Expected time until a connection is established after calling @p try_connect. */ - size_t dest_channel_id; + interval_t expected_try_connect_duration; /** - * @brief Expected time until a connection is established after calling @p try_connect. + * @brief Get the other federates channel id. + * Used to identify this NetworkChannel among other NetworkChannels at incoming messages from the other federate. */ - interval_t expected_try_connect_duration; + uint32_t (*get_dest_channel_id)(NetworkChannel *self); /** * @brief Get the current state of the connection. diff --git a/src/platform/posix/tcp_ip_channel.c b/src/platform/posix/tcp_ip_channel.c index 0ad78aa2..a61c6f3f 100644 --- a/src/platform/posix/tcp_ip_channel.c +++ b/src/platform/posix/tcp_ip_channel.c @@ -469,7 +469,17 @@ static void TcpIpChannel_free(NetworkChannel *untyped_self) { self->super.close_connection((NetworkChannel *)self); } -NetworkChannelState TcpIpChannel_get_state(NetworkChannel *untyped_self) { +static uint32_t TcpIpChannel_get_dest_channel_id(NetworkChannel *untyped_self) { + TcpIpChannel *self = (TcpIpChannel *)untyped_self; + + if (self->server) { + return self->client; + } else { + return self->fd; + } +} + +static NetworkChannelState TcpIpChannel_get_connection_state(NetworkChannel *untyped_self) { TcpIpChannel *self = (TcpIpChannel *)untyped_self; return self->state; } @@ -486,6 +496,8 @@ void TcpIpChannel_ctor(TcpIpChannel *self, const char *host, unsigned short port self->fd = 0; self->state = NETWORK_CHANNEL_STATE_UNINITIALIZED; + self->super.get_dest_channel_id = TcpIpChannel_get_dest_channel_id; + self->super.get_connection_state = TcpIpChannel_get_connection_state; self->super.open_connection = TcpIpChannel_open_connection; self->super.try_connect = TcpIpChannel_try_connect; self->super.close_connection = TcpIpChannel_close_connection;