digitalmars.D.learn - listener.d: Range violation.
- Jesse Brands (30/30) May 29 2011 Hello there,
- Dmitry Olshansky (8/38) May 29 2011 Just a stub in the dark, but since you are killing the last one socket,
- Jesse Brands (2/2) May 29 2011 That worked, thanks a lot! I was going nuts as to why it wouldn't work!
Hello there, For a small chat server thingie I'm making, I decided to use D; finding myself with a very neat example from listener.d to get a kick start I decided to pretty much take the example over! However, I'm stuck on a bug I can't truly wrap my finger around. Most likely it's my own fault and I'm doing something wrong, but considering I took the code pretty much from the example I am more inclined to believe the example is broken. I'll explain what happens: -- I start up my server (nothing wrong, it's running as it should and listening) -- I telnet to it. My server accepts the connection. -- I use telnet to send some information. Server handles the information properly, again, no issue. -- I quit telnet by using ^] and then writing quit. Breaking the connection rather ungracefully. -- The server properly recognises this isn't a clean disconnect and executes the code to remove the socket. -- I then get a range violation. This is the main process and it's loop: https://github.com/JGBrands/BlaatServer/blob/master/source/bserver.d This is the server class, the code where it deletes the socket is at the complete bottom in the function void destroySocket(int index); https://github.com/JGBrands/BlaatServer/blob/master/source/server.d The code is primarily taken over from the listener.d example like I said, the error I get is this: core.exception.RangeError server(61): Range violation ---------------- ---------------- I'm lead to believe the function is deleting something it shouldn't, for those interested, this is line 61 in server.d: if (this.sset.isSet(this.reads[i])) {
May 29 2011
On 30.05.2011 0:38, Jesse Brands wrote:Hello there, For a small chat server thingie I'm making, I decided to use D; finding myself with a very neat example from listener.d to get a kick start I decided to pretty much take the example over! However, I'm stuck on a bug I can't truly wrap my finger around. Most likely it's my own fault and I'm doing something wrong, but considering I took the code pretty much from the example I am more inclined to believe the example is broken. I'll explain what happens: -- I start up my server (nothing wrong, it's running as it should and listening) -- I telnet to it. My server accepts the connection. -- I use telnet to send some information. Server handles the information properly, again, no issue. -- I quit telnet by using ^] and then writing quit. Breaking the connection rather ungracefully. -- The server properly recognises this isn't a clean disconnect and executes the code to remove the socket. -- I then get a range violation. This is the main process and it's loop: https://github.com/JGBrands/BlaatServer/blob/master/source/bserver.d This is the server class, the code where it deletes the socket is at the complete bottom in the function void destroySocket(int index); https://github.com/JGBrands/BlaatServer/blob/master/source/server.d The code is primarily taken over from the listener.d example like I said, the error I get is this: core.exception.RangeError server(61): Range violation ---------------- ---------------- I'm lead to believe the function is deleting something it shouldn't, for those interested, this is line 61 in server.d: if (this.sset.isSet(this.reads[i])) {Just a stub in the dark, but since you are killing the last one socket, (that is calling destroySocket in next) but you get your index still incremented (next returns true) so it will point out of array and it won't be equal to reads.length on next step. Try adjusting that == to >= on line 60 to test this theory. -- Dmitry Olshansky
May 29 2011
That worked, thanks a lot! I was going nuts as to why it wouldn't work! Much loves to you!
May 29 2011