Bug 16514 – std.socket methods are const, and thus cannot be overriden for SSLSocket, for example

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-09-20T19:20:00Z
Last change time
2017-01-16T23:24:06Z
Keywords
pull
Assigned to
nobody
Creator
ketmar

Comments

Comment #0 by ketmar — 2016-09-20T19:20:51Z
commit 1fc5f9b34ca9bb333ee429ab2ca39e07c3304f01 made most of virtual methods of std.socket `const`, and now it is not possible to do any internal housekeeping in overriden methods. bind, connect, listen, accept... this should be reverted.
Comment #1 by dlang-bugzilla — 2016-10-12T14:35:08Z
My fault. I wonder if we could provide protected non-const and public const overloads.
Comment #2 by ketmar — 2016-10-13T06:32:48Z
is there any sense in having const methods there at all? anything more complex than "syscall with fd" will require non-const anyway. besides, Socket is heap object, and class with VMT, so it isn't supposed to be lightning-fast anyway. const/nothrow simply adds some "attribute noise" here, without any real purpose. i think. ;-)
Comment #3 by dlang-bugzilla — 2016-10-13T07:08:13Z
It's sometimes useful, such as when it's a field in a const object. Or when you want to use a class as an AA key, to associate some data with it but don't have control over the class's creation.
Comment #4 by dlang-bugzilla — 2016-10-13T07:09:02Z
Comment #5 by ketmar — 2016-10-13T07:36:15Z
i'd say that for AA it is way better (at least in this case) to subclass the thing with new opHash implementation. also, `const` Socket has very little sense: despite being `const`, it is still changing some of it's internal state. slapping `const` usually means "it should not change while i holding it", but this is not the case for open Socket (OS doesn't know about that restriction ;-). i.e. i see no sense in trying to *pretend* that const Socket has any meaning: it is confusing and mostly useless.
Comment #6 by dlang-bugzilla — 2016-10-13T07:39:39Z
Well, even if it doesn't make sense for non-pure methods, there's still some getter methods that should actually be const.
Comment #7 by dlang-bugzilla — 2016-10-13T07:53:41Z
Comment #8 by ketmar — 2016-10-13T08:12:48Z
why not `inout` then?
Comment #9 by dlang-bugzilla — 2016-10-13T08:13:25Z
Oops, meant to paste link to PR. https://github.com/dlang/phobos/pull/4858 (In reply to Vladimir Panteleev from comment #1) > I wonder if we could provide protected non-const and public const overloads. No because then you get "class Y use of X.fun() is hidden by Y; use 'alias fun = X.fun;' to introduce base class overload set" errors.
Comment #10 by dlang-bugzilla — 2016-10-13T08:14:33Z
(In reply to Ketmar Dark from comment #8) > why not `inout` then? Well, that still doesn't fix that that PR broke code. With const/non-const overrides I thought that we could just make the const ones public (maybe final) and non-const protected for overriding, but that didn't work.
Comment #11 by dlang-bugzilla — 2016-10-13T08:16:00Z
(In reply to Vladimir Panteleev from comment #10) > With const/non-const overrides Overloads. I meant overloads.
Comment #12 by github-bugzilla — 2016-10-24T06:52:26Z
Comment #13 by github-bugzilla — 2016-11-20T23:19:11Z
Comment #14 by github-bugzilla — 2016-12-27T13:11:00Z
Comment #15 by github-bugzilla — 2017-01-16T23:24:06Z