On 6/5/11 8:51 PM, Jonathan Sternberg wrote:
I'm trying to learn how to do some networking code in D. In C, if I wanted to
read 4 bytes into an integer, I could just do (ignoring any error detection):
int foo;
recv(sockfd,&foo, sizeof(int), 0);
How do I do this with D? The receive function takes in a void [] parameter and
doesn't take in a number of bytes to read. Is there anyway to accomplish this
in D?
auto socket = new Socket(…);
…
int foo;
socket.receive((&foo)[0..1]);
---
void[] is like an array of bytes, with the difference to ubyte[] being
that it can contain pointers which must be taken into account by the GC,
and implicit convertibility. However, all the socket functions should
operate on ubyte[] instead of void[] by current guidelines – the socket
module is really old, this will definitely be changed when it will be
overhauled/replaced.
David