Changeset - a9fb2e3e41d9
[Not reviewed]
0 1 4
Christopher Esterhuyse - 5 years ago 2020-07-24 11:39:40
christopher.esterhuyse@gmail.com
added interop header file and test programs. Testing on linux TODO
5 files changed with 82 insertions and 1 deletions:
0 comments (0 inline, 0 general)
examples/interop_connector/main.c
Show inline comments
 
new file 100644
 
#include <stdio.h>
 
#include <string.h>
 
#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
examples/interop_pseudo_socket/main.c
Show inline comments
 
new file 100644
 
#include <sys/socket.h> // socket addresses, constants
 
#include <stdio.h>
 
#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<msglen; i++) {
 
    printf("%02X", buffer[i]);
 
  }
 
  // --- cleanup ---
 
  rw_close(fd);
 
  free(buffer);
 
  return 0;
 
}
 
\ No newline at end of file
examples/interop_socket/main.c
Show inline comments
 
new file 100644
 
#include <sys/socket.h> // socket addresses, constants
 
#include <stdio.h>
 
#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<msglen; i++) {
 
        printf("%02X", buffer[i]);
 
    }
 
    // --- cleanup ---
 
    close(fd);
 
    free(buffer);
 
    return 0;
 
}
 
\ No newline at end of file
pseudo_socket.h
Show inline comments
 
new file 100644
 
#include <sys/socket.h> // 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
src/ffi/mod.rs
Show inline comments
 
@@ -265,13 +265,13 @@ pub unsafe extern "C" fn connector_add_net_port(
 
/// - a utf-8 encoded BIND socket addresses (i.e., "local"),
 
/// - a utf-8 encoded CONNECT socket addresses (i.e., "peer"),
 
/// returns [P, G] via out pointers [putter, getter],
 
/// - 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,
 
    local_addr: FfiSocketAddr,
 
    peer_addr: FfiSocketAddr,
 
) -> c_int {
0 comments (0 inline, 0 general)