{"id":15557780,"url":"https://github.com/fgasper/p5-io-sigguard","last_synced_at":"2026-07-01T05:31:32.817Z","repository":{"id":56840675,"uuid":"86128384","full_name":"FGasper/p5-IO-SigGuard","owner":"FGasper","description":"CPAN IO::SigGuard","archived":false,"fork":false,"pushed_at":"2020-06-13T11:05:19.000Z","size":51,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-03T13:45:15.344Z","etag":null,"topics":["io","perl","signal"],"latest_commit_sha":null,"homepage":"","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FGasper.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-25T03:06:10.000Z","updated_at":"2020-06-13T11:05:22.000Z","dependencies_parsed_at":"2022-08-29T01:51:13.853Z","dependency_job_id":null,"html_url":"https://github.com/FGasper/p5-IO-SigGuard","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FGasper%2Fp5-IO-SigGuard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FGasper%2Fp5-IO-SigGuard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FGasper%2Fp5-IO-SigGuard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FGasper%2Fp5-IO-SigGuard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FGasper","download_url":"https://codeload.github.com/FGasper/p5-IO-SigGuard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246135739,"owners_count":20729056,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["io","perl","signal"],"created_at":"2024-10-02T15:20:38.679Z","updated_at":"2026-07-01T05:31:32.767Z","avatar_url":"https://github.com/FGasper.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nIO::SigGuard - SA\\_RESTART in pure Perl\n\n# SYNOPSIS\n\n    IO::SigGuard::sysread( $fh, $buf, $size );\n    IO::SigGuard::sysread( $fh, $buf, $size, $offset );\n\n    IO::SigGuard::syswrite( $fh, $buf );\n    IO::SigGuard::syswrite( $fh, $buf, $len );\n    IO::SigGuard::syswrite( $fh, $buf, $len, $offset );\n\n    IO::SigGuard::send( $fh, $msg, $flags );\n    IO::SigGuard::send( $fh, $msg, $flags, $to );\n\n    IO::SigGuard::select( $read, $write, $exc, $timeout );\n\n# DESCRIPTION\n\n`perldoc perlipc` describes how Perl versions from 5.8.0 onward disable\nthe OS’s SA\\_RESTART flag when installing Perl signal handlers.\n\nThis module imitates that pattern in pure Perl: it does an automatic\nrestart when a signal interrupts an operation so you can avoid\nthe generally-useless EINTR error when using\n`sysread()`, `syswrite()`, and `select()`.\n\nFor this to work, whatever signal handler you implement will need to break\nout of this module, probably via either `die()` or `exit()`.\n\n# ABOUT `sysread()` and `syswrite()`\n\nOther than that you’ll never see EINTR and that\nthere are no function prototypes used (i.e., you need parentheses on\nall invocations), `sysread()` and `syswrite()`\nwork exactly the same as Perl’s equivalent built-ins.\n\n# LAZY-LOADING\n\nAs of version 0.13 this module’s functions lazy-load by default. To have\nfunctionality loaded at compile time give the function name to the import\nlogic, e.g.:\n\n    use IO::SigGuard qw(send recv);\n\n# ABOUT `select()`\n\nTo handle EINTR, `IO::SigGuard::select()` has to subtract the elapsed time\nfrom the given timeout then repeat the internal `select()`. Because\nthe `select()` built-in’s `$timeleft` return is not reliable across\nall platforms, we have to compute the elapsed time ourselves. By default the\nonly means of doing this is the `time()` built-in, which can only measure\nindividual seconds.\n\nThis works, but there are two ways to make it more accurate:\n\n- Have [Time::HiRes](https://metacpan.org/pod/Time::HiRes) loaded, and `IO::SigGuard::select()` will use that\nmodule rather than the `time()` built-in.\n- Set `$IO::SigGuard::TIME_CR` to a compatible code reference. This is\nuseful, e.g., if you have your own logic to do the equivalent of\n[Time::HiRes](https://metacpan.org/pod/Time::HiRes)—for example, in Linux you may prefer to call the `gettimeofday`\nsystem call directly from Perl to avoid [Time::HiRes](https://metacpan.org/pod/Time::HiRes)’s XS overhead.\n\nIn scalar contact, `IO::SigGuard::select()` is a drop-in replacement\nfor Perl’s 4-argument built-in.\n\nIn list context, there may be discrepancies re the `$timeleft` value\nthat Perl returns from a call to `select`. As per Perl’s documentation\nthis value is generally not reliable anyway, though, so that shouldn’t be a\nbig deal. In fact, on systems like MacOS where the built-in’s `$timeleft`\nis completely useless, IO::SigGuard’s return is actually **better** since it\ndoes provide at least a rough estimate of how much of the given timeout value\nis left.\n\nSee `perlport` for portability notes for `select`.\n\n# TODO\n\nThis pattern could probably be extended to other system calls that can\nreceive EINTR. I’ll consider adding new calls as requested.\n\n# REPOSITORY\n\n[https://github.com/FGasper/p5-IO-SigGuard](https://github.com/FGasper/p5-IO-SigGuard)\n\n# AUTHOR\n\nFelipe Gasper (FELIPE)\n\n… with special thanks to Mario Roy (MARIOROY) for extra testing\nand a few fixes/improvements.\n\n# COPYRIGHT\n\nCopyright 2017 by [Gasper Software Consulting](http://gaspersoftware.com)\n\n# LICENSE\n\nThis distribution is released under the same license as Perl.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffgasper%2Fp5-io-sigguard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffgasper%2Fp5-io-sigguard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffgasper%2Fp5-io-sigguard/lists"}