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 35 insertions and 27 deletions:
0 comments (0 inline, 0 general)
.gitignore
Show inline comments
 
@@ -7,5 +7,10 @@ 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
 
@@ -41,7 +41,7 @@ lazy_static = "1.4.0"
 
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
examples/5_put_get/amy.c
Show inline comments
 
@@ -20,7 +20,7 @@ int main(int argc, char** argv) {
 
	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);
examples/7_recovery/amy.c
Show inline comments
 
@@ -30,7 +30,7 @@ int main(int argc, char** argv) {
 
	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);
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 ---
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]);
 
  }
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]);
 
    }
examples/make.py
Show inline comments
 
@@ -5,13 +5,13 @@ for c_file in glob.glob(script_path + "/*/*.c", recursive=False):
 
  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
 
@@ -31,7 +31,7 @@ int main(int argc, char** argv) {
 
	// 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);
examples/pres_2/bob.c
Show inline comments
 
@@ -34,7 +34,7 @@ int main(int argc, char** argv) {
 
	// 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);
examples/pres_5/bob.c
Show inline comments
 
@@ -35,7 +35,7 @@ int main(int argc, char** argv) {
 

	
 
		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");
examples/utility.c
Show inline comments
 
@@ -7,7 +7,7 @@
 

	
 
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')
src/ffi/pseudo_socket_api.rs
Show inline comments
 
@@ -2,7 +2,6 @@ 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,
0 comments (0 inline, 0 general)