commit 9de4810b3bf6034e8731a0445f6c023c3094e7ee
parent 9565a773ac5d576c573a0891cdf374fae4cb9e83
Author: Drew DeVault <sir@cmpwn.com>
Date: Mon, 21 Jun 2021 15:33:17 -0400
net::dial: flesh out dial (but not dial_tcp et al)
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/net/dial/dial.ha b/net/dial/dial.ha
@@ -34,5 +34,17 @@ export fn dial(
address: str,
service: str,
) (*io::stream | net::error) = {
- abort(); // TODO
+ for (let i = 0z; i < len(default_protocols); i += 1) {
+ let p = default_protocols[i];
+ if (p.name == proto) {
+ return p.dial(address, service);
+ };
+ };
+ for (let i = 0z; i < len(protocols); i += 1) {
+ let p = protocols[i];
+ if (p.name == proto) {
+ return p.dial(address, service);
+ };
+ };
+ return net::unknownproto;
};
diff --git a/net/errors.ha b/net/errors.ha
@@ -1,10 +1,18 @@
use errors;
+// An attempt was made to use an unsupported protocol.
+export type unknownproto = !void;
+
// All error types which can be returned from networking functions.
-export type error = !errors::error;
+export type error = !(unknownproto | ...errors::error);
// Converts a [[net::error]] into a human-readable string.
-export fn strerror(err: error) const str = errors::strerror(err);
+export fn strerror(err: error) const str = {
+ return match (err) {
+ unknownproto => "Unsupported protocol",
+ err: errors::error => errors::strerror(err),
+ };
+};
// TODO: listener should not be here, working around bug in harec forward
// references