Subclass TcpSocket?

Andy Valencia dont at spam.me
Mon Mar 17 22:14:21 UTC 2025


The presence of the "accepting" API in Socket seems to indicate 
that subclassing Socket/TcpSocket is intended to be supported.  
But I'm just not seeing my way through the twisty maze of pure 
and @nothrow barriers?

Andy

     import std.socket : TcpSocket, Address, getAddress;

     class WrappedTCP : TcpSocket {
         string label;

         this(string _label) nothrow {
             this.label = _label;
             super();
         }
         override WrappedTCP accepting() nothrow {
             return new WrappedTCP(this.label);
         }
     }
     void main() {
         import std.stdio : writeln;

         auto s = new WrappedTCP("My Label");
         writeln(s.label);
         s.listen(4);
         auto s2 = cast(WrappedTCP)(s.accept());
         writeln(s2.label);
     }



More information about the Digitalmars-d-learn mailing list