mirror of
https://github.com/DragonOS-Community/dragonos-berkeley-socket.git
synced 2025-06-08 07:35:03 +00:00
socket example but haven't test run
This commit is contained in:
parent
a34468c6c1
commit
48ab5e9b25
16
src/main.rs
16
src/main.rs
@ -1,10 +1,9 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use berkeley_socket::{
|
||||
driver::{irq::start_network_polling_thread, tap::TapDevice},
|
||||
interface::tap::TapIface,
|
||||
socket::inet::common::NET_DEVICES,
|
||||
driver::{irq::start_network_polling_thread, tap::TapDevice}, interface::tap::TapIface, posix::SOCK, socket::{endpoint::Endpoint, inet::{common::NET_DEVICES, syscall::Inet}, Family}
|
||||
};
|
||||
use smoltcp::wire::{IpAddress, IpEndpoint};
|
||||
use spin::Mutex;
|
||||
|
||||
fn main() {
|
||||
@ -13,4 +12,15 @@ fn main() {
|
||||
NET_DEVICES.write().insert(0, iface);
|
||||
let _ = start_network_polling_thread();
|
||||
// TODO: add socket tests
|
||||
|
||||
let socket = Inet::socket(SOCK::Datagram, 0).unwrap();
|
||||
socket.bind(Endpoint::Ip(
|
||||
IpEndpoint::new(
|
||||
IpAddress::v4(192, 168, 199, 1),
|
||||
1234,
|
||||
)
|
||||
)).unwrap();
|
||||
let mut buffer = [0u8; 1024];
|
||||
socket.read(&mut buffer).unwrap();
|
||||
socket.write(&buffer).unwrap();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user