diff --git a/examples/bench_11/main.c b/examples/bench_11/main.c index 98526b97f13450f199f77174d208a3c21a32f62f..3f6b4f055cd8392119ee7b947106affb0646d374 100644 --- a/examples/bench_11/main.c +++ b/examples/bench_11/main.c @@ -5,9 +5,8 @@ int main(int argc, char** argv) { int i, j, forwards, num_options, correct_index; forwards = atoi(argv[1]); num_options = atoi(argv[2]); - correct_index = atoi(argv[3]); - printf("forwards %d, num_options %d, correct_index %d\n", - forwards, num_options, correct_index); + printf("forwards %d, num_options %d\n", + forwards, num_options); unsigned char pdl[] = "primitive recv_zero(in a) { " " while(true) synchronous {" @@ -43,7 +42,8 @@ int main(int argc, char** argv) { clock_t begin = clock(); char msg = 0; - for (i=0; i<10000; i++) { + for (i=0; i<1000; i++) { + correct_index = i%num_options; for(j=0; j +#include "../../reowolf.h" +#include "../utility.c" +int main(int argc, char** argv) { + int i, j, batches; + batches = atoi(argv[1]); + printf("batches %d\n", batches); + unsigned char pdl[] = ""; + Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1); + printf("Error str `%s`\n", reowolf_error_peek(NULL)); + char logpath[] = "./bench_12.txt"; + Connector * c = connector_new_logging(pd, logpath, sizeof(logpath)-1); + + connector_connect(c, -1); + printf("Error str `%s`\n", reowolf_error_peek(NULL)); + + clock_t begin = clock(); + char msg = 0; + for (i=0; i<1000000; i++) { + for(j=1; j +#include "../../reowolf.h" +#include "../utility.c" +int main(int argc, char** argv) { + int i, msglen, inside, total; + char * transport; + transport = argv[1]; + msglen = atoi(argv[2]); + inside = atoi(argv[3]); + total = atoi(argv[4]); + printf("transport `%s`, msglen %d, inside %d, total %d\n", + transport, msglen, inside, total); + unsigned char pdl[] = ""; + Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1); + printf("Error str `%s`\n", reowolf_error_peek(NULL)); + char logpath[] = "./bench_13.txt"; + Connector * c = connector_new_logging(pd, logpath, sizeof(logpath)-1); + + PortId native_putter, native_getter; + char ident[] = "sync"; // defined in reowolf's stdlib + connector_add_port_pair(c, &native_putter, &native_getter); + for (i=0; i +#include "../../reowolf.h" +#include "../utility.c" +int main(int argc, char** argv) { + int i, msglen; + msglen = atoi(argv[1]); + printf("msglen %d\n", msglen); + printf("Error str `%s`\n", reowolf_error_peek(NULL)); + char * msg = malloc(msglen); + memset(msg, msglen, 42); + + unsigned char pdl[] = ""; + Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1); + printf("Error str `%s`\n", reowolf_error_peek(NULL)); + char logpath[] = "./bench_14_amy.txt"; + Connector * c = connector_new_logging_with_id(pd, logpath, sizeof(logpath)-1, 0); + + PortId putter, getter; + connector_add_net_port( + c, + &putter, + (FfiSocketAddr) {{127, 0, 0, 1}, 7000}, + Polarity_Putter, + EndpointPolarity_Active); + connector_add_net_port( + c, + &getter, + (FfiSocketAddr) {{127, 0, 0, 1}, 7001}, + Polarity_Getter, + EndpointPolarity_Passive); + connector_connect(c, -1); + + clock_t begin = clock(); + for (i=0; i<10000; i++) { + connector_put_bytes(c, putter, msg, msglen); + connector_get(c, getter); + connector_sync(c, -1); + } + clock_t end = clock(); + double time_spent = (double)(end - begin) / CLOCKS_PER_SEC; + printf("Time taken: %f\n", time_spent); + + free(msg); + return 0; +} \ No newline at end of file diff --git a/examples/bench_14/bob.c b/examples/bench_14/bob.c new file mode 100644 index 0000000000000000000000000000000000000000..c878b3516030560f4a762e370420135236db7fc8 --- /dev/null +++ b/examples/bench_14/bob.c @@ -0,0 +1,39 @@ +#include +#include "../../reowolf.h" +#include "../utility.c" +int main(int argc, char** argv) { + int i; + unsigned char pdl[] = ""; + Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1); + printf("Error str `%s`\n", reowolf_error_peek(NULL)); + char logpath[] = "./bench_14_bob.txt"; + Connector * c = connector_new_logging_with_id(pd, logpath, sizeof(logpath)-1, 1); + + PortId putter, getter; + connector_add_net_port( + c, + &putter, + (FfiSocketAddr) {{127, 0, 0, 1}, 7001}, + Polarity_Putter, + EndpointPolarity_Active); + connector_add_net_port( + c, + &getter, + (FfiSocketAddr) {{127, 0, 0, 1}, 7000}, + Polarity_Getter, + EndpointPolarity_Passive); + connector_add_component(c, "forward", 7, (PortId[]){getter, putter}, 2); + printf("Error str `%s`\n", reowolf_error_peek(NULL)); + connector_connect(c, -1); + printf("Error str `%s`\n", reowolf_error_peek(NULL)); + + clock_t begin = clock(); + for (i=0; i<10000; i++) { + connector_sync(c, -1); + } + clock_t end = clock(); + + double time_spent = (double)(end - begin) / CLOCKS_PER_SEC; + printf("Time taken: %f\n", time_spent); + return 0; +} \ No newline at end of file diff --git a/examples/bench_15/main.c b/examples/bench_15/main.c new file mode 100644 index 0000000000000000000000000000000000000000..08a6b43fe743aa5203f65349ad757b943d0b9cc4 --- /dev/null +++ b/examples/bench_15/main.c @@ -0,0 +1,45 @@ +#include +#include "../../reowolf.h" +#include "../utility.c" +int main(int argc, char** argv) { + int i, cid; + cid = atoi(argv[1]); + printf("cid %d\n", cid); + printf("Error str `%s`\n", reowolf_error_peek(NULL)); + + unsigned char pdl[] = ""; + Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1); + Connector * c = connector_new_with_id(pd, cid); + + bool seen_delim = false; + for(i=2; i +#include "../../reowolf.h" +#include "../utility.c" +int main(int argc, char** argv) { + int i, cid; + cid = atoi(argv[1]); + printf("cid %d\n", cid); + printf("Error str `%s`\n", reowolf_error_peek(NULL)); + + unsigned char pdl[] = ""; + Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1); + Connector * c = connector_new_with_id(pd, cid); + + bool seen_delim = false; + for(i=2; i +#include "../../reowolf.h" +#include "../utility.c" +#define N 5 +int main(int argc, char** argv) { + int i, cid, min_pid, msgs; + cid = atoi(argv[1]); + min_pid = atoi(argv[2]); + char role = argv[3][0]; // 'h' for head, 'i' for inner, 't' for tail, 's' for singleton + msgs = atoi(argv[4]); + printf("cid %d, min_pid %d, role='%c', msgs %d\n", + cid, min_pid, role, msgs); + printf("Error str `%s`\n", reowolf_error_peek(NULL)); + + unsigned char pdl[] = ""; + Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1); + Connector * c = connector_new_with_id(pd, cid); + PortId putters[N], getters[N]; + FfiSocketAddr addr = {{127, 0, 0, 1}, 0}; + if(role=='i' || role=='t') { + // I have N getter ports! + for(i=0; i, + connector_id: ConnectorId, +) -> *mut Connector { + let c = Connector::new(Box::new(DummyLogger), pd.clone(), connector_id); + Box::into_raw(Box::new(c)) +} +#[no_mangle] pub unsafe extern "C" fn connector_new_logging( pd: &Arc, path_ptr: *const u8, @@ -176,17 +184,11 @@ pub unsafe extern "C" fn connector_new_logging( connector_new_logging_with_id(pd, path_ptr, path_len, Connector::random_id()) } -#[no_mangle] -pub unsafe extern "C" fn connector_print_debug(connector: &mut Connector) { - println!("Debug print dump {:#?}", connector); -} - /// Initializes `out` with a new connector using the given protocol description as its configuration. /// The connector uses the given (internal) connector ID. #[no_mangle] pub unsafe extern "C" fn connector_new(pd: &Arc) -> *mut Connector { - let c = Connector::new(Box::new(DummyLogger), pd.clone(), Connector::random_id()); - Box::into_raw(Box::new(c)) + connector_new_with_id(pd, Connector::random_id()) } /// Destroys the given a pointer to the connector on the heap, freeing its resources. @@ -196,6 +198,11 @@ pub unsafe extern "C" fn connector_destroy(connector: *mut Connector) { drop(Box::from_raw(connector)) } +#[no_mangle] +pub unsafe extern "C" fn connector_print_debug(connector: &mut Connector) { + println!("Debug print dump {:#?}", connector); +} + /// Given an initialized connector in setup or connecting state, /// - Creates a new directed port pair with logical channel putter->getter, /// - adds the ports to the native component's interface, diff --git a/src/runtime/error.rs b/src/runtime/error.rs index 409d56d590d11d1e3fa2256275f917b7b72f6204..1284844b8dbbeb6f808f3c37c23095758a84ea32 100644 --- a/src/runtime/error.rs +++ b/src/runtime/error.rs @@ -4,6 +4,7 @@ use crate::common::*; pub enum ConnectError { BindFailed(SocketAddr), UdpConnectFailed(SocketAddr), + TcpInvalidConnect(SocketAddr), PollInitFailed, Timeout, PollFailed, diff --git a/src/runtime/setup.rs b/src/runtime/setup.rs index 3e35d1aead0774491e75544ac3440cef14ff8271..701228314b31045c8fbdd3db4187345179253120 100644 --- a/src/runtime/setup.rs +++ b/src/runtime/setup.rs @@ -327,7 +327,7 @@ fn setup_endpoints_and_pair_ports( log!(logger, "Net endpoint {} beginning setup with {:?}", index, &endpoint_setup); let todo_endpoint = if let EndpointPolarity::Active = endpoint_setup.endpoint_polarity { let mut stream = TcpStream::connect(endpoint_setup.sock_addr) - .expect("mio::TcpStream connect should not fail!"); + .map_err(|_| Ce::TcpInvalidConnect(endpoint_setup.sock_addr))?; poll.registry().register(&mut stream, token, BOTH).unwrap(); NetTodoEndpoint::PeerInfoRecving(NetEndpoint { stream, inbox: vec![] }) } else {