Coder Social home page Coder Social logo

util's People

Contributors

algesten avatar andrepuel avatar chertov avatar edmellum avatar flakebi avatar foxzool avatar giangndm avatar jelmansouri avatar lookback-hugotunius avatar melekes avatar rainliu avatar xnorpx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

util's Issues

Add try_send_to for Conn

util/src/conn/mod.rs

Lines 26 to 36 in 2d193c0

#[async_trait]
pub trait Conn {
async fn connect(&self, addr: SocketAddr) -> Result<()>;
async fn recv(&self, buf: &mut [u8]) -> Result<usize>;
async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>;
async fn send(&self, buf: &[u8]) -> Result<usize>;
async fn send_to(&self, buf: &[u8], target: SocketAddr) -> Result<usize>;
async fn local_addr(&self) -> Result<SocketAddr>;
async fn remote_addr(&self) -> Option<SocketAddr>;
async fn close(&self) -> Result<()>;
}

This is required to implement Write trait

Cross compile for android is broken.

Problem

I write a small example examples/display-interfaces.rs to test ifaces:

use std::error::Error;
use webrtc_util::ifaces::ifaces;

fn main() -> Result<(), Box<dyn Error>> {
    let interfaces = ifaces()?;
    for (index, interface) in interfaces.iter().enumerate() {
        println!("{} {:?}", index, interface);
    }
    Ok(())
}

I have following toolchain config in ~/.cargo/config:

[target.i686-linux-android]
ar = "/Users/ignis/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar"
linker = "/Users/ignis/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android21-clang"

Build commands:

# required by `cc` crate
export CC=/Users/ignis/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android21-clang
export CXX=/Users/ignis/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android21-clang++
export AR=export AR=/Users/ignis/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar

# cross build
cargo build --target i686-linux-android --example display-interfaces

Here is what I got:

  = note: src/ifaces/ffi/android/ifaddrs.cpp:182: error: undefined reference to 'operator new(unsigned int)'
          src/ifaces/ffi/android/ifaddrs.cpp:182: error: undefined reference to 'operator delete(void*)'
          src/ifaces/ffi/android/LocalArray.h:39: error: undefined reference to 'operator new[](unsigned int)'
          src/ifaces/ffi/android/ifaddrs.cpp:69: error: undefined reference to 'operator new[](unsigned int)'
          src/ifaces/ffi/android/ifaddrs.cpp:92: error: undefined reference to 'operator new(unsigned int)'
          src/ifaces/ffi/android/ifaddrs.cpp:103: error: undefined reference to 'operator new(unsigned int)'
          src/ifaces/ffi/android/LocalArray.h:49: error: undefined reference to 'operator delete[](void*)'
          src/ifaces/ffi/android/ifaddrs.cpp:202: error: undefined reference to 'operator delete(void*)'
          src/ifaces/ffi/android/ifaddrs.cpp:54: error: undefined reference to 'operator delete(void*)'
          src/ifaces/ffi/android/ifaddrs.cpp:55: error: undefined reference to 'operator delete[](void*)'
          src/ifaces/ffi/android/ifaddrs.cpp:56: error: undefined reference to 'operator delete(void*)'
          /Users/ignis/rust/util/target/i686-linux-android/debug/deps/libwebrtc_util-823b3c5896b6d105.rlib(ifaddrs.o):ifaddrs.cpp:function __clang_call_terminate: error: undefined reference to '__cxa_begin_catch'
          /Users/ignis/rust/util/target/i686-linux-android/debug/deps/libwebrtc_util-823b3c5896b6d105.rlib(ifaddrs.o):ifaddrs.cpp:function __clang_call_terminate: error: undefined reference to 'std::terminate()'
          /Users/ignis/rust/util/target/i686-linux-android/debug/deps/libwebrtc_util-823b3c5896b6d105.rlib(ifaddrs.o):ifaddrs.cpp:DW.ref.__gxx_personality_v0: error: undefined reference to '__gxx_personality_v0'
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

I can fix this by modify build.rs like this (add .cpp(true)):

fn main() {
    if std::env::var("TARGET")
        .unwrap_or_default()
        .contains("android")
    {
        cc::Build::new()
            .cpp(true) // enable c++
            .file("src/ifaces/ffi/android/ifaddrs.cpp")
            .compile("ifaddrs-android");
    }
}

But when I try to run it on my android simulator, another error shows up:

➜  util git:(main) ✗ adb push target/i686-linux-android/debug/examples/display-interfaces /data/local/tmp
target/i686-linux-android/debug/examples/display-interfaces: 1 file pushed, 0 skipped. 94.0 MB/s (26831268 bytes in 0.272s)
➜  util git:(main) ✗ adb shell                                                                           
generic_x86:/ $ cd /data/local/tmp/                                                                                                                                                                                                
generic_x86:/data/local/tmp $ chmod +x display-interfaces                                                                                                                                                                          
generic_x86:/data/local/tmp $ ./display-interfaces                                                                                                                                                                                 
CANNOT LINK EXECUTABLE "./display-interfaces": library "libc++_shared.so" not found
Aborted 
134|generic_x86:/data/local/tmp $

Solution

It seems all problems come with C++, maybe we should just get rid of it. Two ways to fix:

  1. Rewrite ifaddrs.cpp to c version
  2. Just use this: https://github.com/morristech/android-ifaddrs/blob/master/ifaddrs.c

make Conn accept &mut self

In cases where there exists a custom underlying interface for interfacing with a UDP socket, a tokio Receiver may be used to accept output buffers. In this case, &mut self is required to poll the receiver, not &self. Plus, making async interfaces accept &mut self is preferred especially since polling interfaces usually require Pin<&mut Self>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.