Skip to content

DRAFT: std.posix.read: should expect ConnectionRefused #24365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pseudocc
Copy link
Contributor

@pseudocc pseudocc commented Jul 8, 2025

Closes: #20219

@pseudocc pseudocc force-pushed the fix-posix-read-error branch from c0be27e to 64d4ec9 Compare July 8, 2025 10:08
@pseudocc
Copy link
Contributor Author

pseudocc commented Jul 8, 2025

flake.nix (apply this patch on top of 0.14.1).

{
  description = "Verify a patch for Zig";

  inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";

  outputs = { self, nixpkgs }: import ./nix/each-system.nix nixpkgs (
    system: pkgs: let
      inherit (pkgs) lib;
      name = "poc";
      zig = pkgs.zig.overrideAttrs {
        patches = pkgs.fetchurl {
          url = "https://github.com/ziglang/zig/pull/24365.patch";
          hash = "sha256-3ZaebBTfKeMEPr5XK+2UfMAao0zR+WuP34bINr7SsDA=";
        };
      };
    in {
      devShells.default = pkgs.mkShell {
        buildInputs = [ zig ];
      };
    }
  );
}

main.zig (copied from comment)

const std = @import("std");

pub fn main() !void {
    const socket = try std.posix.socket(std.posix.AF.INET, std.posix.SOCK.DGRAM, 0);
    const address = std.net.Address.parseIp4("0.0.0.0", 9999) catch unreachable;
    try std.posix.connect(socket, &address.any, address.getOsSockLen());

    var i: usize = 0;
    while (i < 2) : (i = i + 1) {
        _ = try std.posix.send(socket, "hello", 0);
        std.time.sleep(10 * std.time.ns_per_ms);
    }
    std.debug.print("ok?\n", .{});
}

Run nix develop and zig run main.zig.

@pseudocc pseudocc force-pushed the fix-posix-read-error branch from 64d4ec9 to 2b200d0 Compare July 8, 2025 10:28
@rootbeer
Copy link
Contributor

rootbeer commented Jul 8, 2025

Fix looks good to me (just a drive-by reviewer). However, because your diff hits File.zig, this PR should probably wait at least until #24329 lands (just to avoid creating merge traffic for it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

std.posix.send with a UDP socket leads to unexpected errno but this errno is to be expected
2 participants