arisuchan.xyz arisu
[ sci / cult / art ]   [ λ / Δ ]   [ psy ]   [ random ]   [ meta ]   [ all ]   [ irc / radio / tv ]
[ sci / cult / art ] [ λ / Δ ] [ psy ] [ r ] [ q ] [ all ]
Arisu Theme Lain Theme


/λ/ - programming

Striped sock enthusiasts

Catalog
Logs


File: 1773631212775.png ( 9.86 KB , 900x673 , png-clipart-rust-programmi….png ) ImgOps

[Reply] No.29

Most “modern” async solutions these days come bundled with thread pools, executors, reactors, hundreds of macros, and half a megabyte of generated state machines just to read 4kb from a socket.
I’m trying to keep a personal networking tool extremely lean. Think single binary < 5mb, no heavy runtime if possible. But I still want proper non-blocking I/O without busy-looping or blocking the whole program.
Heres the kind of "ugly-but-works" code I usually end up writing when I want to stay close to the metal:
Rustuse std::io::{self, Read, Write};
use std::net::TcpStream;
use std::os::unix::io::AsRawFd;

fn main() -> io::Result<()> {
    let mut stream = TcpStream::connect("1.1.1.1:443")?;
    stream.set_nonblocking(true)?;

    let mut buf = vec![0u8; 4096];

    loop {
        match stream.read(&mut buf) {
            Ok(0) => break,                     //eof
            Ok(n)  => { /* handle data */ }
            Err(e) if e.kind() == io::ErrorKind::WouldBlock => {
                //this is the part that usually turns into mio / epoll / kqueue / iocp / select spaghetti
            }
            Err(e) => return Err(e),
        }
    }
    Ok(())
}

The question is: how do you people actually handle the “wait for something to happen” part in 2026 without immediately reaching for tokio/async-std/libuv/go runtime/whatever-the-800-line-crate-of-the-week-is?

 No.30

It's very simple to make an async scheduler without macros and craziness if:
- You are single-threaded
- You only target one OS
- You don't need accurate timers

I've built an async scheduler in Nim from scratch using Linux syscalls, and it was easy until I ran into threads and timers.

For threads, what you can (and should) do if you are writing a network tool is to do a shared-nothing architecture with a scheduler per-thread. This means that as long as you aren't passing data between threads, you do not need atomics or locks. This eliminates what people usually complain about with async Rust, using Arc<T> everywhere.

Before I talk about why timers are hard, let's look at a conceptual single-thread async scheduler:

Task - in Rust terms, this will be a Future
Queue - Vec<Future>
Loop - While queue is not empty, pop a task and poll it. If it's done, discard it, if not, put it back on the queue.

Post too long. Click here to view the full text.

 No.31

>>30
By the way, all this assumes you're running Linux with epoll. If you are using anything else, especially Windows, it will be very different. Windows (and the semi-new io_uring Linux module) use a completion model (you call the kernel, it lets you know when it's done) vs. a readiness model (it lets you know when you can submit work).

I highly recommend anyone who is interested in high-performance Linux networking to read about io_uring. There is a great introduction to it here: https://unixism.net/loti/



File: 1767159624935.jpg ( 493.24 KB , 1544x720 , Screenshot_20251231_123234.jpg ) ImgOps

[Reply] No.23

http://tululoo.com/ where to find more tutorial for this tool, even it's YouTube is lacking and I struggle to even, make projection. I just need… A huge book of… SNES programming. But using that tool. Also less math or typing ..just because.

 No.24

>>23
why are you choosing to use that in the first place if it has no documentation? besides the documentation issue, its extremely uncommon, and also quite old for web technology at this point (tululoo's development ceased 13 years ago…)

apparently someone created their own game-making-engine that was inspired by tululoo:
https://comigo.games/en/p/ctjs/

that projects website is here:
https://ctjs.rocks/

are you a beginner trying to learn? damn near anything else would be a better learning experience than 13 year old shovelware - that is such an odd choice

 No.25

>>24
Hey cheers for commenting.
First of all, don't they say, the harder the better, no pain no gain, no discount for all you can eat, SpongeBob wears only one suit?
Ok last one not real quote.
>Comigo ctjs
Oh yeah I know that one. Quite good, rather big… Well.
There is also whimsy.rocks
Almost like the slimmed version of ctjs.

I think I CAN, use them. So aren't I considered, "learned"? After that though, it just don't translate to tululoo. Maybe I am just, curious and obsessed at this point, but bringing up tululoo to, a med student, seems awkward anyway. Other than that again, does ctjs teach you how to embed in center? I have ALot, like, alot to know still.



File: 1732336800903-0.png ( 130.2 KB , 717x976 , Capture d’écran du 2024-11….png ) ImgOps

File: 1732336800903-1.png ( 76.96 KB , 717x599 , Capture d’écran du 2024-11….png ) ImgOps

[Reply] No.1

Glad to see this place back online! Been far too long.
Let's start this board back up with a code review; you show some code you wrote and other brutally tear it to shreds for fun.

Mine is some code I wrote a month or two ago to make my own version of cat(1) that just prints one text file to stdout. I figured it would be a good thing to write before I started some college classes about C.

I also called it p after an old video of Brian Kernighan demonstrating unix pipes and he used a homonymous program to print a file to stdout before using some text processing on it.

Let's all love lain!

 No.11

being that lainchan has nice syntax highlighting for code i modified our vichan instance to support highlighting as well

for example, if you type:

[code php]
some php code…
[/code]

then it renders like this:

	// Fix code markup
	if ($config['markup_code']) {
		foreach ($code_markup as $id =&gt; $val) {
			$code = isset($val[2]) ? $val[2] : $val[1];
			$code_lang = isset($val[2]) ? $val[1] : "";

			//$code = "&lt;pre class='code lang-$code_lang'&gt;".str_replace(array("\n","\t"), array("&amp;#10;","&amp;#9;"), htmlspecialchars($code))."&lt;/pre&gt;";
			$code = "&lt;pre style='max-width:90em!important';&gt;&lt;code class='language-$code_lang'&gt;".str_replace(array("\n","\t"), array("&amp;#10;","&amp;#9;"), htmlspecialchars($code))."&lt;/code&gt;&lt;/pre&gt;";

			$body = str_replace("&lt;code $id&gt;", $code, $body);
		}
	}

if you dont include the language in the code tag highlight.js will try to guess (it doesn't guess perfectly every time but eh)

>that snippet happens to include the change i made in vichans functions.php to enable highlighting with highlight.js and add a scrollbar for code that overflows a posts body


also vichan stripped the <> characters from my code snippet and i dont feel like finding where to disable that after hacking this shit together, feel good though i fixed up a handful of things on the site today just for shits

 No.13

I can't program…. except in x86 but that was years ago and I was never good at it.

 No.15

File: 1736837731241-0.png ( 31.45 KB , 630x357 , 2025-01-14_00-59.png ) ImgOps

File: 1736837731241-1.png ( 40.16 KB , 590x466 , 2025-01-14_01-00.png ) ImgOps

i rarely ever write code by myself nowadays since LLM's came out

just had ChatGPT spit this out for me and figured someone else may find it useful

it runs a short SMART test on all your ZPOOL's disks and sends you an email about any disks that fail SMART checks
set it to run with cron for automated tests/reporting

it requires smartctl and msmtp (and that msmtp is configured to send mail properly)

edit the EMAIL and ZPOOL_NAME variables to match your setup

>the log file output is a bit ugly, but i dont really need logs for this so eh



#!/bin/bash

# Email configuration
EMAIL="your@email.address"  # Your email address
SUBJECT="SMART Errors on $(hostname)"
LOGFILE="/tmp/smartcheck.log"
TMP_EMAIL="/tmp/smart_email.txt"
FAILED_DRIVES=()

# Dynamically retrieve drives from ZFS pool
ZPOOL_NAME="dozer"  # Replace with your ZFS pool name
DRIVES=($(zpool status "$ZPOOL_NAME" | grep -E '^\s+(scsi|ata)-' | awk '{print $1}'))

# Clear previous log
> "$LOGFILE"

echo "SMART check started..."

# Initiate and check each drive
for DRIVE in "${DRIVES[@]}"; do
    DEVICE="/dev/disk/by-id/$DRIVE"

    # Output progress
    echo "$DEVICE - in progress"
    echo "Initiating short SMART test for $DEVICE..." >> "$LOGFILE"
    smartctl -t short "$DEVICE" >> "$LOGFILE" 2>&1

    #echo "Waiting for test to complete for $DEVICE..."
    while true; do
        TEST_STATUS=$(smartctl -a "$DEVICE" | grep '^# 1 ' | awk '{print $5}')
        #echo $TEST_STATUS
        if [[ "$TEST_STATUS" == "Completed" ]] || [[ "$TEST_STATUS" == "Failed" ]]; then
            break
        fi
        #echo "Test in progress for $DEVICE..."
        sleep 10
    done

    echo "Checking results for $DEVICE..." >> "$LOGFILE"
    SMART_OUTPUT=$(smartctl -H "$DEVICE" 2>&1)
    echo "$SMART_OUTPUT" >> "$LOGFILE"

    # Output progress
    echo "$DEVICE - done"

    # Check for errors in the test results
    if echo "$SMART_OUTPUT" | grep -qiE "FAILED|impending|critical|failure"; then
        ERROR_LINE=$(echo "$SMART_OUTPUT" | grep -iE "Health Status:.*|FAILED|impending|critical|failure")
        FAILED_DRIVES+=("$DEVICE: $ERRO
Post too long. Click here to view the full text.

 No.16

File: 1736845678682.jpg ( 39.81 KB , 500x500 , qu9tv.jpg ) ImgOps

ok, i finally figured out what was going on with the stripping/replacing of certain characters within code tags

i had to make this change in functions.php:

before
$code = "<pre style='max-width:90em!important';><code class='language-$code_lang'>".str_replace(array("\n","\t"), array("&#10;","&#9;"), htmlspecialchars($code))."</code></pre>";

after
$code = "<pre style='max-width:90em!important';><code class='language-$code_lang'>".str_replace(array("\n","\t"), array("&#10;","&#9;"), $code)."</code></pre>";


funny enough thats the same line i changed to enable highlighting but my dumb ass did not consider what htmlspecialchars() was doing

previously, code blocks within a posts body had HTML characters double-escaped
HTML renders escaped characters back into their original non-escaped form, but not double-escaped characters

now that those characters are only escaped once, code in code tags wont have any replaced characters (after your browser renders them)

>i also changed max_body from 1800 to 5800 so you can make much longer posts now

 No.17

so I tried making a Logger that can be used in a cpp project and used makros to avoid the mess of the singleton and to get automatically the current parameters for the vLOG (verbose logging) I was told that this is old c-style and "not good" ….


#define vLOG(entry, tag) \
  Logger::getInstance().logWithContext((entry), (tag), __FILE__, __LINE__, __func__)

#define LOG(entry, tag) \
  Logger::getInstance().log((entry), (tag))

#define REGISTER() \
    Logger::getInstance().registerTask([&](bool isPaused){ \
    (Logger::s_thread_local_pause).store(isPaused); \
   })

#define PAUSE() \
    Logger::getInstance().pause(); \

#define PAUSE(id) \
    Logger::getInstance().pause(id); \

#define RESUME() \
    Logger::getInstance().resume(); \

#define RESUME(id) \
    Logger::getInstance().resume(id); \




Previous [1] Next
Catalog
[ sci / cult / art ] [ λ / Δ ] [ psy ] [ r ] [ q ] [ all ]