Commit Graph

164 Commits

Author SHA1 Message Date
Josh Holland
c25b157dda remove deprecated uses of ArrayList.span 2020-11-07 11:15:44 +00:00
LemonBoy
7f46672193 More fixups for Windows targets
* Use closeSocket on sockets instead of plain old close, the latter
  doesn't work on them.
* Use winsocket2 everywhere, mingw has no BSD sockets.
2020-10-28 10:03:23 +01:00
LemonBoy
8044ed4c66 std: Add basic smoke test for net functionality 2020-10-27 21:52:47 +01:00
johnLate
0a619c68a6 fix type mismatch in std.net.StreamServer
Parameter in std.os.listen is u31.

Fixes ziglang#6775
2020-10-25 21:18:24 -04:00
heidezomp
1e07487904 Fix std.net.connectUnixSocket in evented I/O mode
The event loop constant was missing.
2020-10-21 23:32:12 -04:00
Loris Cro
c196c27af8 recvfrom
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:06:41 +02:00
Loris Cro
419aea54cb sendto
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:06:41 +02:00
Loris Cro
730428bfd6 connect
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 21:56:27 +02:00
Loris Cro
e85c89630e accept
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 21:56:27 +02:00
Kenta Iwasaki
50e3906951
os: return error.SocketNotListening for EINVAL on accept (#6226) 2020-09-03 13:57:08 -04:00
LemonBoy
dd4994a4e4 std: Fix C-string with missing NUL terminator
Spotted thanks to the stricter conversion rules.
2020-09-01 18:45:35 +02:00
Andrew Kelley
4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Andrew Kelley
d159ba9295 zig fmt 2020-08-04 23:04:20 -07:00
Jonathan Marler
6cc72af03d Provide Ip4Address and Ip6Address in addition to Address 2020-07-27 07:11:07 +00:00
Vexu
e85fe13e44
run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
joachimschmidt557
0ae1157e45 std.mem.dupe is deprecated, move all references in std
Replaced all occurences of std.mem.dupe in stdlib with
Allocator.dupe/std.mem.dupeZ -> Allocator.dupeZ
2020-07-04 21:40:06 +03:00
Andrew Kelley
d4d954abd2 std.sort: give comparator functions a context parameter 2020-06-08 15:16:40 -04:00
Ian Simonson
a6d1ef64d7 tcpConnectToHost try all addresses in AddressList
The AddressList returned can contain more than one item
e.g. the ipv4 and ipv6 addresses for a given hostname.
Previously if a server had multiple addresses but
was not listening on one of them Zig would give up
immediately.

Now on std.os.ConnectError.ConnectionRefused Zig will
try the next address in the list. Zig still gives up on
all other errors as they are related to the system and
system resources rather than whether the remote server
is listening on a particular address.
2020-06-07 22:39:35 +10:00
Andrew Kelley
7fd937fef4 cleanups
* improve docs
 * add TODO comments for things that don't have open issues
 * remove redundant namespacing of struct fields
 * guard against ioctl returning EINTR
 * remove the general std.os.ioctl function in favor of the specific
   ioctl_SIOCGIFINDEX function. This allows us to have a more precise
   error set, and more type-safe API.
2020-06-02 15:28:46 -04:00
Luna
0d091dc923 Replace os.linux to os.system 2020-06-02 14:56:19 -04:00
Luna
09c01ea7b9 Use resolveIp when looking up addresses on linux 2020-06-02 14:56:19 -04:00
Luna
c8468bed42 Add std.os.ioctl 2020-06-02 14:56:19 -04:00
Luna
b72c862725 Use IFNAMESIZE for scope id value 2020-06-02 14:56:06 -04:00
Luna
64e55a74de Add validation for scope ids 2020-06-02 14:56:06 -04:00
Luna
11a06d4341 Remove warn() calls 2020-06-02 14:56:06 -04:00
Luna
cb649b769c Fix ifreq definition 2020-06-02 14:56:06 -04:00
Luna
c50ac9a764 Change Unsupported to InterfaceNotFound 2020-06-02 14:56:06 -04:00
Luna
38109d48a3 Make interface name null-terminated before syscall 2020-06-02 14:56:06 -04:00
Luna
5919831529 Stop using mem.len on array 2020-06-02 14:56:06 -04:00
Luna
901aab8761 Add ioctl errors 2020-06-02 14:56:06 -04:00
Luna
2c641c93da Only resolve scope id when needed 2020-06-02 14:56:06 -04:00
Luna
f02f4c0880 Fix typo and add if_nametoindex 2020-06-02 14:56:06 -04:00
Luna
b816303122 Add basics of resolveIp6
Instead of streaming the scope id digits to an u32, we keep a [32]u8 in
the stack and fill it up with the characters we get for scope id.
2020-06-02 14:56:05 -04:00
Jonathan Marler
58fb5b29b6 more windows network fixes
* support posix SOCK_NONBLOCK and SOCK_CLOEXEC flags on windows
* fix bugs in os.socket and os.connect to return at the correct place
2020-05-31 10:07:51 -06:00
Jonathan Marler
2bae91e769 convert getaddrinfo rc to enum before switching on it 2020-05-30 09:56:52 -06:00
Jonathan Marler
2eaab1e65e more windows network support, including dns 2020-05-29 22:38:48 -06:00
Andrew Kelley
53d011fa1a (breaking) std.time fixups and API changes
Remove the constants that assume a base unit in favor of explicit
x_per_y constants.

nanosecond calendar timestamps now use i128 for the type. This affects
fs.File.Stat, std.time.nanoTimestamp, and fs.File.updateTimes.

calendar timestamps are now signed, because the value can be less than
the epoch (the user can set their computer time to whatever they wish).

implement std.os.clock_gettime for Windows when clock id is
CLOCK_CALENDAR.
2020-05-24 21:40:08 -04:00
Jonathan Marler
832f6c1228 make Address.getOsSockLen pub 2020-05-11 09:11:05 -06:00
Haze Booth
e79d7e0ded Remove fs.File artifact from connectUnixSocket 2020-05-09 12:29:27 -04:00
Vexu
10abffcd98
fix more private member access 2020-05-08 15:10:38 +03:00
Cato
9b788b765c Pass filtered_sock_type to system.socket. Cover PermissionDenied error 2020-05-03 15:35:36 -04:00
Andrew Kelley
8a8beefa36 solve the problem with Darwin shims in std.os instead
* implement SOCK_NONBLOCK and SOCK_CLOEXEC Darwin shims in std.os
 * revert changes to std.net
 * remove os.accept and rename os.accept4 to os.accept
2020-05-02 17:36:28 -04:00
Cato
07bee9da42 Fixed Darwin-incompatible socket flags and unavailable system calls 2020-05-02 16:37:39 -04:00
Andrew Kelley
45bce27b8f cleanup and fixes. behavior tests passing with evented I/O 2020-05-01 23:17:28 -04:00
xackus
cd20e0cc67 rename mem.separate to mem.split 2020-04-04 17:37:51 -04:00
xackus
7a28c644aa new ArrayList API: fix everything else 2020-04-02 16:12:08 +02:00
Andrew Kelley
2e806682f4
(breaking) std.Buffer => std.ArrayListSentineled(u8, 0)
This new name (and the fact that it is a function returning a type) will
make it more clear which use cases are better suited for ArrayList and
which are better suited for ArrayListSentineled.

Also for consistency with ArrayList,
 * `append` => `appendSlice`
 * `appendByte` => `append`

Thanks daurnimator for pointing out the confusion of std.Buffer.
2020-04-01 13:30:07 -04:00
Andrew Kelley
9e7ae06249
std lib API deprecations for the upcoming 0.6.0 release
See #3811
2020-03-30 14:23:22 -04:00
Sebastian
2b0d66736a tcpConnectToHost - fixed compilation error
before:
```
std\net.zig:403:23: error: type '@TypeOf(std.net.getAddressList).ReturnType.ErrorSet!*std.net.AddressList' does not support field access
    const addrs = list.addrs.toSliceConst();
                      ^
```
2020-03-28 21:34:50 -04:00
LemonBoy
541e763010 ir: Peer type resolution between ?[]T and *[N]T
Closes #4767
2020-03-20 12:23:05 -04:00
Andrew Kelley
6b6f2fcf96
std.net: remove the hack from earlier in the branch 2020-03-19 15:09:52 -04:00
Andrew Kelley
7fa88cc0a6
std lib fixups for new semantics
std lib tests are passing now
2020-03-19 09:53:55 -04:00
Benjamin Feng
4aae55b4cc Replace fmt with new fmtstream 2020-03-12 10:41:09 -05:00
Benjamin Feng
0059d9ee3e Convert fmt.bufPrint / fmt.allocPrint 2020-03-12 10:41:09 -05:00
Benjamin Feng
c11d1055b8 Integrated outstreams with new formatter 2020-03-12 10:26:28 -05:00
Andrew Kelley
18f1fef142
update standard library to new I/O streams API 2020-03-10 18:44:30 -04:00
Andrew Kelley
ef3d761da5
breaking: std.mem.len no longer takes a type argument
also update fmt code to use std.mem.span.
2020-03-01 13:21:39 -05:00
Andrew Kelley
4616af0ca4
introduce operating system version ranges as part of the target
* re-introduce `std.build.Target` which is distinct from `std.Target`.
   `std.build.Target` wraps `std.Target` so that it can be annotated as
   "the native target" or an explicitly specified target.
 * `std.Target.Os` is moved to `std.Target.Os.Tag`. The former is now a
   struct which has the tag as well as version range information.
 * `std.elf` gains some more ELF header constants.
 * `std.Target.parse` gains the ability to parse operating system
   version ranges as well as glibc version.
 * Added `std.Target.isGnuLibC()`.
 * self-hosted dynamic linker detection and glibc version detection.
   This also adds the improved logic using `/usr/bin/env` rather than
   invoking the system C compiler to find the dynamic linker when zig
   is statically linked. Related: #2084
   Note: this `/usr/bin/env` code is work-in-progress.
 * `-target-glibc` CLI option is removed in favor of the new `-target`
   syntax. Example: `-target x86_64-linux-gnu.2.27`

closes #1907
2020-02-28 14:51:53 -05:00
Andrew Kelley
1d06c82c3b
Merge pull request #4516 from xackus/remove-bytes-to-slice
remove @bytesToSlice, @sliceToBytes from the language
2020-02-24 13:51:47 -05:00
Andrew Kelley
dff7ca6784
annotate TODO comment with bug tracker link 2020-02-21 14:20:07 -05:00
xackus
783e8ad031 remove @bytesToSlice, @sliceToBytes from std lib 2020-02-21 19:46:53 +01:00
Andrew Kelley
c48831512b
std lib typo fixups 2020-02-08 01:38:01 -05:00
Andrew Kelley
84323504ac
std.fmt.format: comptime output parameter 2020-02-05 16:52:18 -05:00
daurnimator
72ec445677 std: turn EAI_ constants into a non-exhaustive enum 2020-01-18 17:46:44 -05:00
LemonBoy
563d9ebfe5 Implement the callconv() annotation 2020-01-02 18:53:16 +01:00
Luna
0d852effe3
std.net: use mem.toBytes 2019-12-30 19:26:30 -05:00
Luna
50e6a27c29
std.net: fix setsockopt call 2019-12-30 19:26:30 -05:00
Luna
0e67568bca
net: fix Options
- os: fix typos on setsockopt
2019-12-30 19:26:30 -05:00
Luna
4a4d2c0d80
os: add setsockopt
- net: use os.setsockopt()
2019-12-30 19:26:29 -05:00
Luna
631eb6783d
add StreamServer.Options.reuse_address
this uses a bad direct interface with std.os.linux, this should add
setsockopt to std.os.
2019-12-30 19:26:29 -05:00
Raul Leal
62c817420d [#3844 + #3767] update std.c and std.os.linux to use null-terminated pointer types (#3900)
* #3844 update std.c functions to use null-terminated pointer types

* check linux functions

* fix callsites

* fix io test

* Add allocPrintCstr function to remove other cast
2019-12-17 15:43:49 -05:00
Robin Voetter
4b4fbe3887
Replace @typeOf with @TypeOf in all zig source
This change was mostly made with `zig fmt` and this also modified some whitespace. Note that in some files, `zig fmt` produced incorrect code, so the change was made manually.
2019-12-10 11:09:41 -05:00
Andrew Kelley
5f9467d78f
update formatted printing when linking libc 2019-12-08 23:39:30 -05:00
Andrew Kelley
8b2622cdd5
std.fmt.format: tuple parameter instead of var args 2019-12-08 22:53:51 -05:00
Andrew Kelley
b36c07a95a
Merge remote-tracking branch 'origin/master' into remove-array-type-coercion 2019-12-01 09:56:01 -05:00
Andrew Kelley
413f9a5cfc
move std.fs.Dir.cwd to std.fs.cwd
update to non-deprecated std.fs APIs throughout the codebase

Related: #3811
2019-11-30 15:35:27 -05:00
Andrew Kelley
bf3ac66150
remove type coercion from array values to references
* Implements #3768. This is a sweeping breaking change that requires
   many (trivial) edits to Zig source code. Array values no longer
   coerced to slices; however one may use `&` to obtain a reference to
   an array value, which may then be coerced to a slice.

 * Adds `IrInstruction::dump`, for debugging purposes. It's useful to
   call to inspect the instruction when debugging Zig IR.

 * Fixes bugs with result location semantics. See the new behavior test
   cases, and compile error test cases.

 * Fixes bugs with `@typeInfo` not properly resolving const values.

 * Behavior tests are passing but std lib tests are not yet. There
   is more work to do before merging this branch.
2019-11-27 03:37:50 -05:00
Andrew Kelley
bdf3680be1
zig fmt 2019-11-25 13:53:13 -05:00
Andrew Kelley
15d415e10b
make std.mem.toSlice use null terminated pointers
and fix the fallout
2019-11-24 21:21:05 -05:00
Andrew Kelley
47f06be369
string literals are now null terminated
this also deletes C string literals from the language, and then makes
the std lib changes and compiler changes necessary to get the behavior
tests and std lib tests passing again.
2019-11-21 20:43:41 -05:00
frmdstryr
aa4e92f3b3 Make StreamServer return address of accecpted client 2019-11-19 01:06:04 +00:00
Luna
c8a8da2804 remove builtin.os check in Address.initUnix 2019-11-10 16:44:18 -03:00
Luna
d99ecef943 replace panic to unreachable
- remove error.UnsupportedOS from StreamServer.listen
2019-11-10 14:17:39 -03:00
Luna
2d02920a90 use hasDecl instead of switch on builtin.os 2019-11-10 14:04:52 -03:00
Luna
25423eb453 add errors/panics for unsupported OSes 2019-11-10 10:50:22 -03:00
Luna
e4704f68f8 use at-as 2019-11-09 15:10:39 -03:00
Luna
fc2e8f92b2 Merge remote-tracking branch 'upstream/master' into unify-unix-sockets 2019-11-09 15:07:09 -03:00
Luna
348c0232a5 miscellaneous fixes
- make connextUnixSocket use std.net.Address
 - fix StreamServer.listen giving wrong protocol for unix sockets
2019-11-09 14:53:48 -03:00
Luna
05ae21b78e make StreamServer.listen family-agnostic
- rename Address.parseUnix to Address.initUnix
2019-11-09 12:51:33 -03:00
Luna
f4d8dc278b rename TcpServer -> StreamServer
- add AF_UNIX support to getOsSockLen
2019-11-09 12:40:56 -03:00
Luna
c2325053a8 add Address.parseUnix and Address.format support for AF_UNIX 2019-11-08 21:44:17 -03:00
Luna
9458620e18 replace Address.parse Address.parseIp 2019-11-08 19:59:30 -03:00
Luna
5d05cfcfe6 rename IpAddress to Address, add Address.unix 2019-11-08 19:35:04 -03:00
Andrew Kelley
aa0daea541
update more of the std lib to use @as 2019-11-08 15:57:25 -05:00
Andrew Kelley
e0db54e89d
update the codebase to use @as 2019-11-08 15:57:24 -05:00
Vexu
a26e9fa723 add special formatting for ipv4-mapped ipv6 addresses 2019-11-05 12:05:34 -05:00
Vexu
6e786b60d4
support ipv4-mapped ipv6 addresses 2019-11-04 19:54:36 +02:00
Vexu
32ac1b5927
improve ipv6 parsing and formatting 2019-11-04 19:00:58 +02:00
Andrew Kelley
788848e123
std.net: fix reference to incorrect constant name 2019-10-30 23:03:49 -04:00
Andrew Kelley
0de862e8ba
make std.net more portable
* Delete `std.net.TmpWinAddr`. I don't think that was ever meant to
   be a real thing.
 * Delete `std.net.OsAddress`. This abstraction was not helpful.
 * Rename `std.net.Address` to `std.net.IpAddress`. It is now an extern
   union of IPv4 and IPv6 addresses.
 * Move `std.net.parseIp4` and `std.net.parseIp6` to the
   `std.net.IpAddress` namespace. They now return `IpAddress` instead of
   `u32` and `std.net.Ip6Addr`, which is deleted.
 * Add `std.net.IpAddress.parse` which accepts a port and parses either
   an IPv4 or IPv6 address.
 * Add `std.net.IpAddress.parseExpectingFamily` which additionally
   accepts a `family` parameter.
 * `std.net.IpAddress.initIp4` and `std.net.IpAddress.initIp6` are
   improved to directly take the address fields instead of a weird
   in-between type.
 * `std.net.IpAddress.port` is renamed to `std.net.IpAddress.getPort`.
 * Added `std.net.IpAddress.setPort`.
 * `os.sockaddr` struct on all targets is improved to match the
   corresponding system struct. Previously I had made it a union of
   sockaddr_in, sockaddr_in6, and sockaddr_un. The new abstraction for
   this is now `std.net.IpAddress`.
 * `os.sockaddr` and related bits are added for Windows.
 * `os.sockaddr` and related bits now have the `zero` fields default
   to zero initialization, and `len` fields default to the correct size.
   This is enough to abstract the differences across targets, and so
   no more switch on the target OS is needed in `std.net.IpAddress`.
 * Add the missing `os.sockaddr_un` on FreeBSD and NetBSD.
 * `std.net.IpAddress.initPosix` now takes a pointer to `os.sockaddr`.
2019-10-30 20:22:05 -04:00