Re: Question: has anyone worked on code for sockets?
[Thread Prev] | [Thread Next]
- Subject: Re: Question: has anyone worked on code for sockets?
- From: Ori Bernstein <ori@xxxxxxxxxxxxxx>
- Reply-to: myrddin-dev@xxxxxxxxxxxxxx
- Date: Sun, 30 Jul 2017 18:20:27 -0700
- To: Ryan Gonzalez <rymg19@xxxxxxxxx>
- Cc: myrddin-dev <myrddin-dev@xxxxxxxxxxxxxx>
On Sun, 30 Jul 2017 20:05:06 -0500, Ryan Gonzalez <rymg19@xxxxxxxxx> wrote: > I'm actually using Unix sockets, so dial is literally PERFECT. > > As a side note: what's the most idiomatic way of converting a pointer > to a byte slice? I'm trying to transfer a union over a Unix socket, > and right now I'm doing: > > > type X = union > `Y > ;; > > /* ... */ > var x = `Y > var bytes = (&x[:]) : (byte[:]) > > but it's not working: > > src/common.myr:40: type union > `Shutdown > ;; does not support member operators near <message#>.len You're close, only a few of small mistakes: 1) operator precedence: postfix binds tighter than prefix. 2) you need to give a size when slicing a pointer, since there's no implicit sizing there. 3) if you want raw bytes, you'll need to cast the pointer before slicing: So: var bytes = ((&x : byte#)[:sizeof(thing)]) It's a tad ugly, unfortunately. I wouldn't object to tossing a generic function into libstd, since it seems to have come up a few times. Maybe something like: std.rawstorage : (valp : @a# -> byte[:]) -- Ori Bernstein
Question: has anyone worked on code for sockets? | "rymg19@xxxxxxxxx" <rymg19@xxxxxxxxx> |
Re: Question: has anyone worked on code for sockets? | Ori Bernstein <ori@xxxxxxxxxxxxxx> |
Re: Question: has anyone worked on code for sockets? | Ryan Gonzalez <rymg19@xxxxxxxxx> |
Re: Question: has anyone worked on code for sockets? | Ori Bernstein <ori@xxxxxxxxxxxxxx> |
Re: Question: has anyone worked on code for sockets? | Ryan Gonzalez <rymg19@xxxxxxxxx> |
- Prev by Date: Crash when using sizeof in array size
- Next by Date: Re: Crash when using sizeof in array size
- Previous by thread: Re: Question: has anyone worked on code for sockets?
- Next by thread: Crash when using sizeof in array size
- Index(es):