hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

socketpair.ha (652B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use errors;
      5 use io;
      6 use net;
      7 use rt;
      8 
      9 // A thin wrapper around socketpair(2) that presumes [[rt::AF_UNIX]] for the
     10 // domain and returns an unnamed pair of sockets of type [[rt::SOCK_STREAM]].
     11 export fn socketpair(flags: net::sockflag = 0) ((net::socket, net::socket) | net::error) = {
     12 	let sv: [2]int = [0...];
     13 	flags ^= rt::SOCK_CLOEXEC: net::sockflag; // invert CLOEXEC
     14 	match (rt::socketpair(rt::AF_UNIX: int, rt::SOCK_STREAM | flags, 0, &sv)) {
     15 	case let err: rt::errno =>
     16 		return errors::errno(err);
     17 	case =>
     18 		return (io::fdopen(sv[0]), io::fdopen(sv[1]));
     19 	};
     20 };