/******************************************/ /* main.c 0.0.1 (1999-Nov-28-Sun) */ /* Adam M. Costello */ /******************************************/ /* Example main loop for the simulation. */ /* This is ANSI C code. */ #include #include #include "deliver_packet.h" #include "network.h" #include "streamers.h" #include "timer_expire.h" #include "transport.h" static struct network_address source_address = { 1, { 1 } }, sink_address = { 1, { 2 } }; static void *transport_source, *transport_sink; void deliver_packet(struct network_packet packet) { unsigned short length; unsigned char *address; length = packet.destination.length; address = packet.destination.address; if (length == source_address.length && !memcmp(address, source_address.address, length)) { transport_source_receive_packet(transport_source, packet); return; } if (length == sink_address.length && !memcmp(address, sink_address.address, length)) { transport_sink_receive_packet(transport_sink, packet); return; } assert(0); /* Cannot reach here. */ } int main() { void *byte_source, *byte_sink; struct transport_connection connection; transport_source = transport_source_create(source_address); transport_sink = transport_sink_create(sink_address); byte_source = byte_source_create(); byte_sink = byte_sink_create(); connection.source.address = source_address; connection.source.port = 101; connection.sink.address = sink_address; connection.sink.port = 102; transport_source_create_connection( transport_source, connection, byte_source, byte_source_go_ahead, 1000 ); transport_sink_create_connection( transport_sink, connection, byte_sink, byte_sink_transfer, 1000 ); byte_source_talk_to( byte_source, transport_source, transport_source_receive_bytes ); byte_sink_listen_to( byte_sink, transport_sink, transport_sink_okay_to_deliver ); while (timer_expire()); return EXIT_SUCCESS; }