instruction stringlengths 271 288 | input stringclasses 1
value | output stringlengths 154 28.8k |
|---|---|---|
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: 03_arena_allocator.c. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | // 03_arena_allocator.c
//
// Fixed-size slab allocator for network packet buffers: one mmap'd arena
// is carved into N fixed-size slots up front; alloc/free are O(1) free-list
// stack operations with no malloc()/free() in the hot path and no per-
// packet heap fragmentation. This is the allocation pattern behind mo... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: 03_ring_buffer.rs. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | // 03_ring_buffer.rs
//
// Fixed-capacity, single-producer/single-consumer lock-free ring buffer of
// pre-allocated packet slots. No heap allocation on the hot path once the
// ring is built: push/pop move raw bytes into slots allocated exactly once
// at startup. Acquire/Release ordering on `head`/`tail` establishes ... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: 04_epoll_async_server.c. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | // 04_epoll_async_server.c
//
// Non-blocking, single-threaded epoll event loop serving a TCP echo
// service. Each connection owns a small buffer + state machine so partial
// reads/writes (the normal case with non-blocking sockets) are handled
// without extra copies, busy-waiting, or blocking the whole server.
//
//... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: 02_raw_tcp_construct.c. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | // 02_raw_tcp_construct.c
//
// Hand-builds an IPv4 header and a TCP SYN segment byte-for-byte, computes
// both checksums per RFC 791 / RFC 793, and transmits the single resulting
// packet on an IP_HDRINCL raw socket. No libpcap, no high-level socket
// wrappers - just struct layouts matching the wire format and one ... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: 05_io_uring_async.c. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | // 05_io_uring_async.c
//
// io_uring-based async TCP echo server: one submission/completion ring
// drives accept, recv, and send completions. No epoll, no blocking
// syscalls in the steady state - every I/O op is submitted to the kernel
// and picked back up off the completion queue, including the next accept,
// wh... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: 01_raw_packet_parser.rs. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | // 01_raw_packet_parser.rs
//
// Raw AF_PACKET/SOCK_RAW capture with manual Ethernet/IPv4/TCP header
// parsing, driven straight off libc syscalls - no pcap/pnet dependency.
//
// Build: cargo build --release --bin raw_packet_parser
// Run: sudo ./target/release/raw_packet_parser eth0
// Needs: CAP_NET_RAW (or root) ... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: 01_raw_packet_parser.c. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | // 01_raw_packet_parser.c
//
// Captures raw Ethernet frames on a given interface via AF_PACKET/SOCK_RAW
// and parses Ethernet, IPv4, and TCP headers directly off the wire format
// - no libpcap, struct layouts match RFC 791 / RFC 793 byte-for-byte.
//
// Build: gcc -O2 -Wall -Wextra -o raw_packet_parser 01_raw_packet... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: build.sh. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | #!/bin/sh
# Builds every module. 05 needs liburing-dev (apt install liburing-dev /
# dnf install liburing-devel). 01/02 need CAP_NET_RAW to *run*, not to build.
set -e
for f in 01_raw_packet_parser 02_raw_tcp_construct 03_arena_allocator 04_epoll_async_server; do
gcc -O2 -Wall -Wextra -Wpedantic -o "$f" "$f.c"
done
g... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: Cargo.toml. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | [package]
name = "net_systems_examples"
version = "0.1.0"
edition = "2021"
[dependencies]
libc = "0.2"
io-uring = "0.6"
[profile.release]
opt-level = 2
| |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: 02_raw_tcp_construct.rs. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | // 02_raw_tcp_construct.rs
//
// Same wire-level construction as the C version: a hand-built IPv4 header
// and TCP SYN segment, checksums computed per RFC 791/793, sent through a
// single IP_HDRINCL raw socket via a direct libc::sendto call.
//
// Build: cargo build --release --bin raw_tcp_construct
// Run: sudo ./... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: 04_epoll_async.rs. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | // 04_epoll_async.rs
//
// Non-blocking TCP echo server driven directly by libc syscalls:
// socket()/bind()/listen()/accept4() for the sockets, epoll_create1()/
// epoll_ctl()/epoll_wait() for the event loop. No mio, no tokio,
// no std::net - the same mechanics as the C version, one level up in Rust.
//
// Build: car... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: 05_io_uring_async.rs. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | // 05_io_uring_async.rs
//
// io_uring TCP echo server using the `io-uring` crate's raw submission/
// completion queue API directly - no tokio, no async/await, just manual
// SQE preparation and CQE polling, mirroring the C/liburing version.
//
// Build: cargo build --release --bin io_uring_async
// Run: ./target/re... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: spsc_ring.h. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | /*
* spsc_ring.h -- lock-free single-producer / single-consumer ring buffer.
*
* SPSC_DEFINE(ring_u64, uint64_t, 1024) // at file scope, no ';'
*
* generates a type `ring_u64` plus these static inline functions:
*
* void ring_u64_init (ring_u64 *q); // before sharing
* bo... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: slab.c. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | /*
* slab.c -- see slab.h for the design overview.
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include "slab.h"
#include <errno.h>
#include <stdalign.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#ifndef __has_feature
#define __has_feature(x) 0
#endif
#if defined(__SANITIZE_ADDRESS__) || _... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: workpool.h. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | /*
* workpool.h -- thread pool whose job and result queues are raw file descriptors.
*
* submitters --wp_submit()--> [ job pipe ] --read(2)--> N worker pthreads
* |
* on_result() <-- collector pthread <-- [ result pipe ] <--write(2)
*
* Why pipes?
... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: lib.rs. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | //! # embedded-kit
//!
//! Three building blocks for Linux-based embedded systems, mirroring the C implementations in
//! `../c` so the two languages can be compared side by side:
//!
//! | module | what it is |
//! |---|---|
//! | [`slab`] | fixed-size block allocator over `mmap(2)` arenas |
//! | [`spsc`] | lock-free... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: kit_util.h. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | /*
* kit_util.h -- tiny helpers shared by the tests and the benchmark.
* Header-only, no dependencies beyond libc.
*/
#ifndef KIT_UTIL_H
#define KIT_UTIL_H
#include <sched.h>
#include <stdint.h>
#include <time.h>
/* Monotonic clock in nanoseconds. */
static inline uint64_t kit_now_ns(void)
{
struct timespec ts... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: Cargo.toml. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | [package]
name = "embedded-kit"
version = "0.1.0"
edition = "2021"
rust-version = "1.70"
description = "Linux embedded systems kit: mmap slab allocator, lock-free SPSC ring, fd-based worker pool"
publish = false
[lib]
name = "embedded_kit"
path = "src/lib.rs"
[dependencies]
libc = "0.2"
[features]
# Extra validation... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: spsc.rs. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | //! Lock-free single-producer / single-consumer ring buffer.
//!
//! ```
//! use embedded_kit::spsc::Ring;
//!
//! let mut ring = Ring::<u32, 8>::new();
//! let (mut tx, mut rx) = ring.split();
//! std::thread::scope(|s| {
//! s.spawn(move || {
//! for i in 0..100 {
//! while tx.push(i).is_err()... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: workpool.rs. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | //! Thread pool whose job and result queues are raw file descriptors.
//!
//! ```text
//! submit(&self) --write(2)--> [ job pipe ] --read(2)--> N worker threads
//! |
//! on_result(&mut S, JobResult) <-- collector thread <-- [ result pipe ] <--write(2)
//! ... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: slab.h. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | /*
* slab.h -- fixed-size block allocator built on POSIX mmap(2).
*
* How it works
* ------------
* - A cache serves blocks of ONE size. Memory comes from "arenas": anonymous
* mmap() regions of `arena_size` bytes (a power of two >= the page size)
* whose base address is aligned to `arena_size`.
* - Bec... | |
Write a professional, completely optimized, production-ready, and exhaustive low-level systems programming implementation for the file target: slab.rs. Focus strictly on memory management, network sockets execution, zero-overhead patterns, and direct OS/Kernel level APIs. | //! Fixed-size block slab allocator built on POSIX `mmap(2)`.
//!
//! ## How it works
//!
//! * A [`SlabCache`] serves blocks of **one** size. Memory comes from *arenas*: anonymous `mmap`
//! regions of `arena_size` bytes (a power of two, at least one page) whose base address is
//! aligned to `arena_size`.
//! * B... |
No dataset card yet
- Downloads last month
- 33