digitalmars.D.bugs - std.socket.Socket - syscalls called with wrong arguments
- Martin Riedel (14/14) Aug 30 2005 As to my knowledge, the phobos libraries' Socket class calls the linux
- Ben Hinkle (11/25) Aug 30 2005 That's expected behavior. What code are you trying to write? When I try
- Martin Riedel (5/37) Aug 30 2005 My fault. I'm quite new to D and I didn't expect void to have a defined
As to my knowledge, the phobos libraries' Socket class calls the linux socket send and receive syscalls in the wrong way. int send(void[] buf, SocketFlags flags) { int sent = .send(sock, buf, buf.length, cast(int)flags); return sent; } Taking a void[] buf dynamic array of the data to be sent as an argument, Socket's send member passes buf.length to the syscall which expects its third argument to be the number of bytes to be sent (or in other words the size of buf in bytes). buf.length, though, is the number of elements in the array. Therefore, in every case where the original array (which was passed to Socket.send and has been cast to void[]) has a type which is bigger than one byte, .send gets wrong arguments.
Aug 30 2005
"Martin Riedel" <riedel.martin gmx.net> wrote in message news:df2127$2ddr$1 digitaldaemon.com...As to my knowledge, the phobos libraries' Socket class calls the linux socket send and receive syscalls in the wrong way. int send(void[] buf, SocketFlags flags) { int sent = .send(sock, buf, buf.length, cast(int)flags); return sent; } Taking a void[] buf dynamic array of the data to be sent as an argument, Socket's send member passes buf.length to the syscall which expects its third argument to be the number of bytes to be sent (or in other words the size of buf in bytes). buf.length, though, is the number of elements in the array. Therefore, in every case where the original array (which was passed to Socket.send and has been cast to void[]) has a type which is bigger than one byte, .send gets wrong arguments.That's expected behavior. What code are you trying to write? When I try int main() { void[] va; int[] ia = new int[10]; va = ia; printf("%d %d\n",ia.length,va.length); return 0; } it prints 10 40 so the void array has the entire int array.
Aug 30 2005
Ben Hinkle wrote:"Martin Riedel" <riedel.martin gmx.net> wrote in message news:df2127$2ddr$1 digitaldaemon.com...My fault. I'm quite new to D and I didn't expect void to have a defined size (which is 1, apparently). Furthermore, I didn't know that casting arrays changes the length of the lvalue array. Thanks for your hint.As to my knowledge, the phobos libraries' Socket class calls the linux socket send and receive syscalls in the wrong way. int send(void[] buf, SocketFlags flags) { int sent = .send(sock, buf, buf.length, cast(int)flags); return sent; } Taking a void[] buf dynamic array of the data to be sent as an argument, Socket's send member passes buf.length to the syscall which expects its third argument to be the number of bytes to be sent (or in other words the size of buf in bytes). buf.length, though, is the number of elements in the array. Therefore, in every case where the original array (which was passed to Socket.send and has been cast to void[]) has a type which is bigger than one byte, .send gets wrong arguments.That's expected behavior. What code are you trying to write? When I try int main() { void[] va; int[] ia = new int[10]; va = ia; printf("%d %d\n",ia.length,va.length); return 0; } it prints 10 40 so the void array has the entire int array.
Aug 30 2005