Code Monkey home page Code Monkey logo

lazy-socket.rs's Introduction

lazy-socket

Build status Build Status Crates.io Docs.rs

The library serves as thin wrapper over socket API. It provides necessary minimum amount of safety and easy to use.

Obsolete kinda

It seems I wouldn't need this library anymore as there is socket2 by alexcrichton.

He is definitely more trustworthy and my library might as well be forgotten. So go socket2 instead.

Examples

Create TCP socket and connect in non-blocking mode.

extern crate lazy_socket;

use std::net;
use std::str::FromStr;

use lazy_socket::raw::{
    Socket,
    Family,
    Protocol,
    Type,
    select
};

fn main() {
    let timeout = 1000;
    let socket = match Socket::new(Family::IPv4, Type::STREAM, Protocol::TCP) {
        Ok(socket) => socket,
        Err(error) => {
            println!("Couldn't open socket. Erro: {}", error);
            return;
        }
    };

    let dest = net::SocketAddr::from_str("192.168.0.1:80").unwrap();

    let _ = socket.set_blocking(false);
    let _ = socket.connect(&dest);
    match select(&[], &[&socket], &[&socket], Some(timeout)) {
          Ok(_) => println!("Connected!"),
          Err(error) => println!("Failed to connect. Error:{}", error)
    }
}

lazy-socket.rs's People

Contributors

doumanash avatar norbytus avatar ntninja avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lazy-socket.rs's Issues

Doesn't compile with musl

Saw the deprecation warning, unfortunately this is still used by tokio_ping.

When I try to compile with a musl target, I get the following errors:

error[E0308]: mismatched types
   --> /home/spease/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy-socket-0.2.1/src/raw/unix.rs:458:37
    |
458 |             match ioctl(self.inner, request, value) {
    |                                     ^^^^^^^ expected i32, found u64

error[E0308]: mismatched types
   --> /home/spease/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy-socket-0.2.1/src/raw/unix.rs:467:20
    |
467 |         self.ioctl(FIONBIO, (!value) as c_ulong)
    |                    ^^^^^^^ expected u64, found i32

error: aborting due to 2 previous errors

TODO

  • Replace net::SocketAddr with own struct. From #1
  • Add platform specific extensions as trait (e.g. SocketUnixExt). From #1
  • Pin next version of libc(current 0.2.21) as only versions above have accept4. Ref #3. Done 78a9c83

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.