* Add NetBSD Support
Includes:
- Hints to find non-compatibility libc functions
- Struct and constant definitions for sockets, polling, etc.
- Changes to the linker code to work around some quirks in the NetBSD dynamic linker
- A target triple for netbsd aarch64 so llvm builds/links the compiler properly on this platform
* Updated releasenotes and some compacting
---------
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
* Add extern fn socketpair() to posix
* Add extern fn getsockname() for local socketpair loopback in windows
* Add local TcpSocketPair
* Add unit test for TcpSocketPair
* Add implicit wsa startup
---------
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
* fix typos in comments and strings
* fix typos in symbols (and some comments/strings)
* fix typos in releasenotes.md
---------
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
- Printing stacktrace uses its own temp allocator.
- `@pool` no longer takes an argument.
- `Allocator` interface removes `mark` and `reset`.
- DynamicArenaAllocator has changed init function.
- Added `BackedArenaAllocator` which is allocated to a fixed size, then allocates on the backing allocator and supports mark/reset.
* Add `Socket.peek` to allow peeking at the receiving queue.
This uses the `MSG_PEEK` flag to peek at the beginning of the
receiving queue without removing data from said queue.
* net/url: implement url encoding (RFC 3986)
Implement url percent-encoding and -decoding functions according to RFC
3986. Add unit tests.
Link: https://datatracker.ietf.org/doc/html/rfc3986
* net/url: ensure correct encoding of URL components
Add encoding and decoding methods to the Url struct components according
to RFC 3986.
An Url can be parsed from a String with `new_parse()` or `temp_parse()`.
The parsed fields are decoded. The only field that is not decoded is
`raw_query`. To access the decoded query values, use
`Url.query_values()`.
`Url.to_string()` will re-assemble the fields into a valid Url string
with proper percent-encoded values.
If the Url struct fields are filled in manually, use the actual
(un-encoded) values. To create a raw query string, initialize an
`UrlQueryValues` map, use `UrlQueryValues.add()` to add the query
parameters and, finally, call `UrlQueryValues.to_string()`.
---------
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
* add std::net::url for parsing/generating URLs
* Move String.index_of_chars into std
* Fix param contract
* Idiomatic type naming, Allman formatting, slicing, document functions
* Use String.tokenize
* Don't return str_view() from freed dstring
* Change indentation to tabs
* Variable casing according to guidlelines
* Updated API and added line to the releasenotes.
---------
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
If the timeout to net::poll() is -1, poll() will block until a requested
event occurs. However, in the poll() function, the Duration timeout is
converted to milliseconds (Duration is in microseconds). The conversion
involves integer arithmetics which results in a zero timeout (= -1 /
1000), i.e. poll() will return immediately and the following accept will
fail.
To fix this, only convert to milliseconds if timeout paramter is
non-negative.
Example to reproduce the error:
```
module echo;
import std::io, std::net;
fn void main()
{
TcpServerSocket server = tcp::listen("localhost", 6969, 69, REUSEADDR)!!;
server.sock.set_non_blocking(true)!!;
Poll[*] polls = {{ .socket = server.sock, .events = net::SUBSCRIBE_READ }};
if (catch net::poll(polls[..], net::POLL_FOREVER)) io::printn("poll error");
TcpSocket client = tcp::accept(&server)!!;
io::printn("OK");
}
```
Poll() will return immediately and the following tcp::accept() will fail
with an "ACCEPT_FAILED" error.
Reported-by: Alexey Kutepov <reximkut@gmail.com>