diff --git a/examples/interop_connector/main.c b/examples/interop_connector/main.c new file mode 100644 index 0000000000000000000000000000000000000000..8661cdb788372368ad0fd4d7d30fc2500ac344d4 --- /dev/null +++ b/examples/interop_connector/main.c @@ -0,0 +1,28 @@ +#include +#include +#include "reowolf.h" + +int main(int argc, char** argv) { + // --- setup --- + Arc_ProtocolDescription * pd = protocol_description_parse("", 0); + Connector * c = connector_new(pd); + PortId putter_a, putter_b; + FfiSocketAddr addresses[4]; + /* (address structure initializations omitted) */ + + // putter_a to UDP mediator (getter id discarded) + // with local addresses[0] and peer addresses[1] + connector_add_udp_mediator_component(c, &putter_a, NULL, addresses[0], addresses[1]); + connector_add_udp_mediator_component(c, &putter_b, NULL, addresses[2], addresses[3]); + connector_connect(c, -1); + + // --- communication --- + connector_put_bytes(c, putter_a, "hello, socket!", 14); + connector_put_bytes(c, putter_b, "hello, pseudo-socket!", 21); + connector_sync(c, -1); + + // --- cleanup --- + protocol_description_destroy(pd); + connector_destroy(c); + return 0; +} \ No newline at end of file diff --git a/examples/interop_pseudo_socket/main.c b/examples/interop_pseudo_socket/main.c new file mode 100644 index 0000000000000000000000000000000000000000..183e5e816c2d8d786f6f00e77013e7a2e91d7205 --- /dev/null +++ b/examples/interop_pseudo_socket/main.c @@ -0,0 +1,23 @@ +#include // socket addresses, constants +#include +#include "pseudo_socket.h" +#define BUFSIZE 512 +int main() { + // --- setup --- + struct sockaddr_in local, peer; + /* (address structure initializations omitted) */ + int fd = rw_socket(AF_INET, SOCK_DGRAM, 0); + rw_bind(fd, (const struct sockaddr *)&local, sizeof(local)); + rw_connect(fd, (const struct sockaddr *)&peer, sizeof(peer)); + // --- communication --- + char buffer = malloc(BUFSIZE); + size_t msglen, i; + msglen = rw_recv(fd, (const void *)buffer, BUFSIZE, 0); + for(i=0; i // socket addresses, constants +#include +#define BUFSIZE 512 +int main() { + // --- setup --- + struct sockaddr_in local, peer; + /* (address structure initializations omitted) */ + int fd = socket(AF_INET, SOCK_DGRAM, 0); + bind(fd, (const struct sockaddr *)&local, sizeof(local)); + connect(fd, (const struct sockaddr *)&peer, sizeof(peer)); + // --- communication --- + char buffer = malloc(BUFSIZE); + size_t msglen, i; + msglen = recv(fd, (const void *)buffer, BUFSIZE, 0); + for(i=0; i // defines {sockaddr, socklen_t} + +int rw_socket(int domain, int type, int protocol); +int rw_connect(int fd, const struct sockaddr *address, socklen_t address_len); +int rw_bind(int socket, const struct sockaddr *address, socklen_t address_len); +int rw_close(int fd); +ssize_t rw_send(int fd, const void * message, size_t length, int flags); +ssize_t rw_recv(int fd, void * buffer, size_t length, int flags); \ No newline at end of file diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index 7f1b00fc9b15e9adb9ce3726cecc07290bb600f6..f5f1aabd32d4c2deb527c29c7bc9858a03338baa 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -268,7 +268,7 @@ pub unsafe extern "C" fn connector_add_net_port( /// - where P is a Putter port that sends messages into the socket /// - where G is a Getter port that recvs messages from the socket #[no_mangle] -pub unsafe extern "C" fn connector_add_udp_port_pair( +pub unsafe extern "C" fn connector_add_udp_mediator_component( connector: &mut Connector, putter: *mut PortId, getter: *mut PortId,