Changeset - 8df425c3752e
[Not reviewed]
0 14 1
Christopher Esterhuyse - 5 years ago 2020-07-24 12:37:33
christopher.esterhuyse@gmail.com
cleaned up examples for compilation on linux
15 files changed with 43 insertions and 35 deletions:
0 comments (0 inline, 0 general)
.gitignore
Show inline comments
 
@@ -4,8 +4,13 @@ target
 
Cargo.lock
 
main
 
examples/*/*.exe
 
examples/*.dll
 
examples/reowolf*
 
examples/*.txt
 
examples/lib*
 
examples/lib*.*
 
examples/*/amy
 
examples/*/bob
 
examples/*/main
 
logs/*
 
logs/*/*
Cargo.toml
Show inline comments
 
@@ -38,11 +38,11 @@ lazy_static = "1.4.0"
 

	
 
[lib]
 
# compile target: dynamically linked library using C ABI
 
crate-type = ["cdylib"]
 

	
 
[features]
 
default = ["ffi", "session_optimization"]
 
default = ["ffi", "session_optimization", "ffi_pseudo_socket_api"]
 
ffi = [] # see src/ffi/mod.rs
 
ffi_pseudo_socket_api = ["ffi", "libc", "os_socketaddr"]# see src/ffi/pseudo_socket_api.rs
 
endpoint_logging = [] # see src/macros.rs
 
session_optimization = [] # see src/runtime/setup.rs
 
\ No newline at end of file
examples/5_put_get/amy.c
Show inline comments
 
@@ -17,14 +17,14 @@ int main(int argc, char** argv) {
 
	connector_put_bytes(c, putter, "hello", 5);
 
	connector_get(c, getter);
 
	
 
	connector_sync(c, -1);
 
	size_t msg_len;
 
	const char * msg_ptr = connector_gotten_bytes(c, getter, &msg_len);
 
	printf("Got msg `%.*s`\n", msg_len, msg_ptr);
 
	printf("Got msg `%.*s`\n", (int) msg_len, msg_ptr);
 
	
 
	
 
	protocol_description_destroy(pd);
 
	connector_destroy(c);
 
	free(pdl_ptr);
 
	return 0;
 
}
 
\ No newline at end of file
 
}
examples/7_recovery/amy.c
Show inline comments
 
@@ -27,13 +27,13 @@ int main(int argc, char** argv) {
 
	connector_put_bytes(c, putter, "hello", 5);
 
	connector_get(c, getter);
 
	err = connector_sync(c, 5000);
 
	printf("Error code %d with string `%s`\n", err, reowolf_error_peek(NULL));
 
	size_t msg_len;
 
	const char * msg_ptr = connector_gotten_bytes(c, getter, &msg_len);
 
	printf("Got msg `%.*s`\n", msg_len, msg_ptr);
 
	printf("Got msg `%.*s`\n", (int) msg_len, msg_ptr);
 
	
 
	protocol_description_destroy(pd);
 
	connector_destroy(c);
 
	free(pdl_ptr);
 
	return 0;
 
}
 
\ No newline at end of file
 
}
examples/cpy_dll.sh
Show inline comments
 
modified file chmod 100644 => 100755
examples/cpy_so.sh
Show inline comments
 
new file 100755
 
cp ./../target/release/reowolf_rs.so ./ --force
examples/interop_connector/main.c
Show inline comments
 
#include <stdio.h>
 
#include <string.h>
 
#include "reowolf.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;
 
@@ -22,7 +22,7 @@ int main(int argc, char** argv) {
 
  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
 
#include <sys/socket.h> // socket addresses, constants
 
#include <netinet/in.h>
 
#include <stdio.h>
 
#include "pseudo_socket.h"
 
#include <stdlib.h>
 
#include "../../pseudo_socket.h"
 
#define BUFSIZE 512
 
int main() {
 
  // --- setup ---
 
  struct sockaddr_in local, peer; 
 
  struct sockaddr_in addrs[2]; 
 
  /* (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));
 
  rw_bind(fd, (const struct sockaddr *)&addrs[0], sizeof(addrs[0]));
 
  rw_connect(fd, (const struct sockaddr *)&addrs[1], sizeof(addrs[1]));
 
  // --- communication ---
 
  char buffer = malloc(BUFSIZE);
 
  char * buffer = malloc(BUFSIZE);
 
  size_t msglen, i;
 
  msglen = rw_recv(fd, (const void *)buffer, BUFSIZE, 0);
 
  msglen = rw_recv(fd, (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
 
#include <sys/socket.h> // socket addresses, constants
 
#include <stdio.h>
 
#include <netinet/in.h> // definies socketaddr_in
 
#include <stdio.h>  // defines printf
 
#include <stdlib.h> // defines malloc, free
 
#include <unistd.h> // defines close
 
#define BUFSIZE 512
 
int main() {
 
    // --- setup ---
 
    struct sockaddr_in local, peer; 
 
    struct sockaddr_in addrs[2]; 
 
    /* (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));
 
    bind(fd, (const struct sockaddr *)&addrs[0], sizeof(addrs[0]));
 
    connect(fd, (const struct sockaddr *)&addrs[1], sizeof(addrs[1]));
 
    // --- communication ---
 
    char buffer = malloc(BUFSIZE);
 
    char * buffer = malloc(BUFSIZE);
 
    size_t msglen, i;
 
    msglen = recv(fd, (const void *)buffer, BUFSIZE, 0);
 
    msglen = recv(fd, (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
 
}
examples/make.py
Show inline comments
 
@@ -2,16 +2,16 @@ import os, glob, subprocess, time
 
script_path = os.path.dirname(os.path.realpath(__file__));
 
for c_file in glob.glob(script_path + "/*/*.c", recursive=False):
 
  print("compiling", c_file)
 
  args = [
 
    "gcc",          # compiler
 
    "-std=c11",     # C11 mode
 
    "-L",           # lib path flag
 
    "./",           # where to look for libs
 
    "-lreowolf_rs", # add lib called "reowolf_rs"
 
    "-Wl,-R./",     # pass -R flag to linker: produce relocatable object
 
    c_file,         # input source file
 
    "-o",           # output flag
 
    c_file[:-2]     # output filename
 
    c_file[:-2],    # output filename
 
    "-L",           # lib path flag
 
    "./",           # where to look for libs
 
    "-lreowolf_rs"  # add lib called "reowolf_rs"
 
  ];
 
  subprocess.run(args)
 
input("Blocking until newline...");
examples/pres_1/bob.c
Show inline comments
 
@@ -28,14 +28,14 @@ int main(int argc, char** argv) {
 
	connector_sync(c, 1000);
 
	rw_err_peek(c);
 

	
 
	// Read our received message
 
	size_t msg_len;
 
	const char * msg_ptr = connector_gotten_bytes(c, p0, &msg_len);
 
	printf("Got msg `%.*s`\n", msg_len, msg_ptr);
 
	printf("Got msg `%.*s`\n", (int) msg_len, msg_ptr);
 
	
 
	printf("Exiting\n");
 
	protocol_description_destroy(pd);
 
	connector_destroy(c);
 
	sleep(1.0);
 
	return 0;
 
}
 
\ No newline at end of file
 
}
examples/pres_2/bob.c
Show inline comments
 
@@ -31,15 +31,15 @@ int main(int argc, char** argv) {
 
	connector_sync(c, 1000);
 
	rw_err_peek(c);
 

	
 
	// Read our received message
 
	size_t msg_len;
 
	const char * msg_ptr = connector_gotten_bytes(c, ports[2], &msg_len);
 
	printf("Got msg `%.*s`\n", msg_len, msg_ptr);
 
	printf("Got msg `%.*s`\n", (int) msg_len, msg_ptr);
 
	
 
	printf("Exiting\n");
 
	protocol_description_destroy(pd);
 
	connector_destroy(c);
 
	free(pdl);
 
	sleep(1.0);
 
	return 0;
 
}
 
\ No newline at end of file
 
}
examples/pres_5/bob.c
Show inline comments
 
@@ -32,16 +32,16 @@ int main(int argc, char** argv) {
 
		rw_err_peek(c);
 
		connector_sync(c, 1000);
 
		rw_err_peek(c);
 

	
 
		size_t msg_len = 0;
 
		const char * msg_ptr = connector_gotten_bytes(c, ports[3], &msg_len);
 
		printf("Got msg `%.*s`\n", msg_len, msg_ptr);
 
		printf("Got msg `%.*s`\n", (int) msg_len, msg_ptr);
 
	}
 
	
 
	printf("Exiting\n");
 
	protocol_description_destroy(pd);
 
	connector_destroy(c);
 
	free(pdl);
 
	sleep(1.0);
 
	return 0;
 
}
 
\ No newline at end of file
 
}
examples/utility.c
Show inline comments
 
@@ -4,13 +4,13 @@
 
#include <string.h>
 
#include <unistd.h>
 
#include "../reowolf.h"
 

	
 
size_t get_user_msg(char * buf, size_t cap) {
 
	memset(buf, 0, cap);
 
	printf("Insert a msg of max len %d: ", cap);
 
	printf("Insert a msg of max len %zu: ", cap);
 
	fgets(buf, cap, stdin);
 
	for(size_t len = 0; len<cap; len++)
 
		if(buf[len]==0 || buf[len]=='\n')
 
			return len;
 
	return cap;
 
}
src/ffi/pseudo_socket_api.rs
Show inline comments
 
use super::*;
 

	
 
use core::ops::DerefMut;
 
use libc::{sockaddr, socklen_t};
 
use std::{collections::HashMap, ffi::c_void, net::SocketAddr, os::raw::c_int, sync::RwLock};
 
use std::{
 
    collections::HashMap,
 
    ffi::c_void,
 
    net::SocketAddr,
 
    os::raw::c_int,
 
    sync::{Mutex, RwLock},
0 comments (0 inline, 0 general)