InternetAddress comparison fail
MattCoder via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jan 3 09:26:28 PST 2015
On Saturday, 3 January 2015 at 16:39:05 UTC, Jonathan Marler
wrote:
> Using toAddrString results in the following steps:
> 1. Allocate memory for the InternetAddress (GC memory by the
> way)
> 2. Convert the uint address to an IP Address string
> 3. Convert the ushort port to a string.
> 4. Do steps 1-3 to the second InternetAddress
> 5. Do a string comparision with the two InternetAddresses.
Hmm well, you don't need to convert anything (like ushort to
string etc), you can compare the fields between these 2 classes
directly:
import std.stdio;
import std.socket;
class myIA : InternetAddress{
this(in char[] addr, ushort port){
super(addr, port);
}
bool opEquals(myIA obj){
foreach (i, v; this.tupleof) {
if(v != obj.tupleof[i]){
return false;
}
}
return true;
}
}
void main(){
auto addr1 = new myIA("192.168.0.1", 80);
auto addr2 = new myIA("192.168.0.1", 80);
assert(addr1.opEquals(addr2));
}
Overall I understood your point/pain, but unfortunately this is
what I could do to manage your problem (I'm using D heavily for a
couple months now).
I'll continue looking over this thread to see what the experts
will say. :)
Matheus.
More information about the Digitalmars-d
mailing list