www.digitalmars.com         C & C++   DMDScript  

D - a new version of socket.d

reply "Christian Lesage" <christian.lesage.1 agora.ulaval.ca> writes:
Hi folks,

I found two bugs in Pavel Minayev's "socket.d", which is, I believe, a great
module to play with if you need TCP/IP in your apps. I'm posting an updated
version of it along with a slightly modified version of Pavel's sample
program. Is there a better place to send files to, so that everybody can
access them?

The first bug was due to the fact that you can't instantiate an object from
a class which has, somewhere in it's ancestry, an abstract method left
undefined. The TCPSocket class inherits from the StreamSocket class which
inherits from the Stream class which has three abstract methods. One of
these, seek(), was left undefined in the sub-classes. I just defined a dummy
seek() method in StreamSocket to circumvent the problem. Should it be done
otherwise?

The second bug concerned the initialization of an IP address (within the IP
class) using a hostname. It was broken because it didn't use correctly the
data structure returned by gethostbyname(). A char** has to be dereferenced
twice...

Not bad for a newbie, uh? I think I'm going to love D.


Thanks to Lars Ivar Igesund for his hint regarding abstract classes.

Christian Lesage
Oct 08 2003
parent Brad Anderson <brad sankaty.com> writes:
 One of
 these, seek(), was left undefined in the sub-classes. I just defined a dummy
 seek() method in StreamSocket to circumvent the problem. Should it be done
 otherwise?
 
 The second bug concerned the initialization of an IP address (within the IP
 class) using a hostname. It was broken because it didn't use correctly the
 data structure returned by gethostbyname(). A char** has to be dereferenced
 twice...
 

Bravo! I was struggling with seek() a few weeks back. I can't think of another way to do it, but I'll let you know how it works in my app... Thanks, Brad
Oct 09 2003