This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pin-project-lite = { version = "0.2", default-features = false } | |
#[cfg(test)] | |
mod tests { | |
use std::future::Future; | |
#[tokio::test] | |
async fn test_ipstack_tcp_stream() { | |
let fut = foo(); | |
let ret = Map::new(fut, |i| i * 2).await; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// This is a simple implementation of a futures executor and spawner. | |
// ref: https://www.bilibili.com/video/BV1Ki4y1C7gj/?vd_source=1658ea36cae9cc99e7417f13c4b86b2f&p=4&spm_id_from=333.788.videopod.episodes | |
// | |
// [dependencies] | |
// futures = "0.3" | |
// | |
use futures::{ | |
future::{BoxFuture, FutureExt}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// cargo test mytest -- --nocapture | |
// | |
#[cfg(test)] | |
mod tests { | |
use std::{ | |
future::Future, | |
pin::Pin, | |
task::{Context, Poll}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[test] | |
fn digit_overflow() { | |
assert_eq!(u16::MAX.wrapping_add(9), 8); | |
assert_eq!(u16::MAX.saturating_add(9), u16::MAX); | |
assert_eq!(u16::MAX.checked_add(9), None); | |
assert_eq!(u16::MAX.overflowing_add(9), (8, true)); | |
} | |
#[test] | |
fn digit_overflow_mul() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[cfg(unix)] | |
#[repr(C)] | |
#[derive(Clone, Copy)] | |
pub union sockaddr_union { | |
pub addr_stor: libc::sockaddr_storage, | |
pub addr6: libc::sockaddr_in6, | |
pub addr4: libc::sockaddr_in, | |
pub addr: libc::sockaddr, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Navicat MySQL Data Transfer | |
Source Server : 本地 | |
Source Server Type : MySQL | |
Source Server Version : 50726 | |
Source Host : localhost:3306 | |
Source Schema : grade | |
Target Server Type : MySQL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// https://github.com/ShadowsocksR-Live/ssrMac/blob/master/ssr_mac_sysconf/main.m | |
// | |
use core_foundation::{ | |
array::CFArray, | |
base::{TCFType, ToVoid}, | |
dictionary::{CFDictionary, CFMutableDictionary}, | |
number::CFNumber, | |
propertylist::CFPropertyList, | |
string::{CFString, CFStringRef}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::sync::Arc; | |
use tokio::sync::Notify; | |
#[tokio::main] | |
async fn main() { | |
let notify = Arc::new(Notify::new()); | |
// 注册两个等候者 | |
let notified1 = notify.notified(); | |
let notified2 = notify.notified(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// DnsProxy.h | |
// | |
#import <Foundation/Foundation.h> | |
/** | |
* DNS Proxy | |
* | |
* This class is responsible for setting up a DNS proxy server that listens on a local port and |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn handle_icmp_echo_request(u: &ipstack::stream::IpStackUnknownTransport) -> Result<()> { | |
use etherparse::{IcmpEchoHeader, Icmpv4Header, Icmpv6Header, IpNumber}; | |
assert!(u.ip_protocol() == IpNumber::ICMP || u.ip_protocol() == IpNumber::IPV6_ICMP); | |
if u.src_addr().is_ipv4() { | |
let (icmp_header, req_payload) = Icmpv4Header::from_slice(u.payload()).map_err(|e| Error::from(e.to_string()))?; | |
if let etherparse::Icmpv4Type::EchoRequest(req) = icmp_header.icmp_type { | |
log::info!("#0 ICMPv4 echo"); | |
let echo = IcmpEchoHeader { id: req.id, seq: req.seq }; | |
let mut resp = Icmpv4Header::new(etherparse::Icmpv4Type::EchoReply(echo)); | |
resp.update_checksum(req_payload); |
NewerOlder