diff --git a/std/socket.d b/std/socket.d index f4184a8530e..514ec9b4e89 100644 --- a/std/socket.d +++ b/std/socket.d @@ -2740,13 +2740,13 @@ public: /// Get the socket's address family. - @property AddressFamily addressFamily() const pure nothrow @nogc + @property AddressFamily addressFamily() { return _family; } /// Property that indicates if this is a valid, alive socket. - @property bool isAlive() @trusted const nothrow @nogc + @property bool isAlive() @trusted const { int type; socklen_t typesize = cast(socklen_t) type.sizeof; @@ -2754,7 +2754,7 @@ public: } /// Associate a local address with this socket. - void bind(Address addr) @trusted const + void bind(Address addr) @trusted { if (_SOCKET_ERROR == .bind(sock, addr.name, addr.nameLen)) throw new SocketOSException("Unable to bind socket"); @@ -2765,7 +2765,7 @@ public: * the connection to be made. If the socket is nonblocking, connect * returns immediately and the connection attempt is still in progress. */ - void connect(Address to) @trusted const + void connect(Address to) @trusted { if (_SOCKET_ERROR == .connect(sock, to.name, to.nameLen)) { @@ -2798,7 +2798,7 @@ public: * can $(D listen). The $(D backlog) is a request of how many pending * incoming connections are queued until $(D accept)ed. */ - void listen(int backlog) @trusted const + void listen(int backlog) @trusted { if (_SOCKET_ERROR == .listen(sock, backlog)) throw new SocketOSException("Unable to listen on socket"); @@ -2813,7 +2813,7 @@ public: */ // Override to use a derived class. // The returned socket's handle must not be set. - protected Socket accepting() const pure nothrow + protected Socket accepting() pure nothrow { return new Socket; } @@ -2823,7 +2823,7 @@ public: * waits for a connection request. Throws $(D SocketAcceptException) if * unable to _accept. See $(D accepting) for use with derived classes. */ - Socket accept() const @trusted + Socket accept() @trusted { auto newsock = cast(socket_t).accept(sock, null, null); if (socket_t.init == newsock) @@ -2850,7 +2850,7 @@ public: } /// Disables sends and/or receives. - void shutdown(SocketShutdown how) @trusted const nothrow @nogc + void shutdown(SocketShutdown how) @trusted nothrow @nogc { .shutdown(sock, cast(int)how); } @@ -2895,7 +2895,7 @@ public: } /// Remote endpoint $(D Address). - @property Address remoteAddress() const @trusted + @property Address remoteAddress() @trusted { Address addr = createAddress(); socklen_t nameLen = addr.nameLen; @@ -2908,7 +2908,7 @@ public: } /// Local endpoint $(D Address). - @property Address localAddress() const @trusted + @property Address localAddress() @trusted { Address addr = createAddress(); socklen_t nameLen = addr.nameLen; @@ -2943,7 +2943,7 @@ public: * failure. */ //returns number of bytes actually sent, or -1 on error - ptrdiff_t send(const(void)[] buf, SocketFlags flags) @trusted const nothrow @nogc + ptrdiff_t send(const(void)[] buf, SocketFlags flags) @trusted { static if (is(typeof(MSG_NOSIGNAL))) { @@ -2957,7 +2957,7 @@ public: } /// ditto - ptrdiff_t send(const(void)[] buf) @trusted const nothrow @nogc + ptrdiff_t send(const(void)[] buf) { return send(buf, SocketFlags.NONE); } @@ -2969,7 +2969,7 @@ public: * Returns: The number of bytes actually sent, or $(D Socket.ERROR) on * failure. */ - ptrdiff_t sendTo(const(void)[] buf, SocketFlags flags, Address to) @trusted const nothrow @nogc + ptrdiff_t sendTo(const(void)[] buf, SocketFlags flags, Address to) @trusted { static if (is(typeof(MSG_NOSIGNAL))) { @@ -2985,7 +2985,7 @@ public: } /// ditto - ptrdiff_t sendTo(const(void)[] buf, Address to) @trusted const nothrow @nogc + ptrdiff_t sendTo(const(void)[] buf, Address to) { return sendTo(buf, SocketFlags.NONE, to); } @@ -2993,7 +2993,7 @@ public: //assumes you connect()ed /// ditto - ptrdiff_t sendTo(const(void)[] buf, SocketFlags flags) @trusted const nothrow @nogc + ptrdiff_t sendTo(const(void)[] buf, SocketFlags flags) @trusted { static if (is(typeof(MSG_NOSIGNAL))) { @@ -3008,7 +3008,7 @@ public: //assumes you connect()ed /// ditto - ptrdiff_t sendTo(const(void)[] buf) @trusted const nothrow @nogc + ptrdiff_t sendTo(const(void)[] buf) { return sendTo(buf, SocketFlags.NONE); } @@ -3021,7 +3021,7 @@ public: * has closed the connection, or $(D Socket.ERROR) on failure. */ //returns number of bytes actually received, 0 on connection closure, or -1 on error - ptrdiff_t receive(void[] buf, SocketFlags flags) @trusted const nothrow @nogc + ptrdiff_t receive(void[] buf, SocketFlags flags) @trusted { version(Windows) // Does not use size_t { @@ -3038,7 +3038,7 @@ public: } /// ditto - ptrdiff_t receive(void[] buf) @trusted const nothrow @nogc + ptrdiff_t receive(void[] buf) { return receive(buf, SocketFlags.NONE); } @@ -3050,7 +3050,7 @@ public: * Returns: The number of bytes actually received, $(D 0) if the remote side * has closed the connection, or $(D Socket.ERROR) on failure. */ - ptrdiff_t receiveFrom(void[] buf, SocketFlags flags, ref Address from) @trusted const nothrow + ptrdiff_t receiveFrom(void[] buf, SocketFlags flags, ref Address from) @trusted { if (!buf.length) //return 0 and don't think the connection closed return 0; @@ -3075,7 +3075,7 @@ public: /// ditto - ptrdiff_t receiveFrom(void[] buf, ref Address from) @trusted const nothrow + ptrdiff_t receiveFrom(void[] buf, ref Address from) { return receiveFrom(buf, SocketFlags.NONE, from); } @@ -3083,7 +3083,7 @@ public: //assumes you connect()ed /// ditto - ptrdiff_t receiveFrom(void[] buf, SocketFlags flags) @trusted const nothrow @nogc + ptrdiff_t receiveFrom(void[] buf, SocketFlags flags) @trusted { if (!buf.length) //return 0 and don't think the connection closed return 0; @@ -3104,7 +3104,7 @@ public: //assumes you connect()ed /// ditto - ptrdiff_t receiveFrom(void[] buf) @trusted const nothrow @nogc + ptrdiff_t receiveFrom(void[] buf) { return receiveFrom(buf, SocketFlags.NONE); } @@ -3113,7 +3113,7 @@ public: /// Get a socket option. /// Returns: The number of bytes written to $(D result). //returns the length, in bytes, of the actual result - very different from getsockopt() - int getOption(SocketOptionLevel level, SocketOption option, void[] result) @trusted const + int getOption(SocketOptionLevel level, SocketOption option, void[] result) @trusted { socklen_t len = cast(socklen_t) result.length; if (_SOCKET_ERROR == .getsockopt(sock, cast(int)level, cast(int)option, result.ptr, &len)) @@ -3123,21 +3123,21 @@ public: /// Common case of getting integer and boolean options. - int getOption(SocketOptionLevel level, SocketOption option, out int32_t result) @trusted const + int getOption(SocketOptionLevel level, SocketOption option, out int32_t result) @trusted { return getOption(level, option, (&result)[0 .. 1]); } /// Get the linger option. - int getOption(SocketOptionLevel level, SocketOption option, out Linger result) @trusted const + int getOption(SocketOptionLevel level, SocketOption option, out Linger result) @trusted { //return getOption(cast(SocketOptionLevel)SocketOptionLevel.SOCKET, SocketOption.LINGER, (&result)[0 .. 1]); return getOption(level, option, (&result.clinger)[0 .. 1]); } /// Get a timeout (duration) option. - void getOption(SocketOptionLevel level, SocketOption option, out Duration result) @trusted const + void getOption(SocketOptionLevel level, SocketOption option, out Duration result) @trusted { enforce(option == SocketOption.SNDTIMEO || option == SocketOption.RCVTIMEO, new SocketParameterException("Not a valid timeout option: " ~ to!string(option))); @@ -3161,7 +3161,7 @@ public: } /// Set a socket option. - void setOption(SocketOptionLevel level, SocketOption option, void[] value) @trusted const + void setOption(SocketOptionLevel level, SocketOption option, void[] value) @trusted { if (_SOCKET_ERROR == .setsockopt(sock, cast(int)level, cast(int)option, value.ptr, cast(uint) value.length)) @@ -3170,14 +3170,14 @@ public: /// Common case for setting integer and boolean options. - void setOption(SocketOptionLevel level, SocketOption option, int32_t value) @trusted const + void setOption(SocketOptionLevel level, SocketOption option, int32_t value) @trusted { setOption(level, option, (&value)[0 .. 1]); } /// Set the linger option. - void setOption(SocketOptionLevel level, SocketOption option, Linger value) @trusted const + void setOption(SocketOptionLevel level, SocketOption option, Linger value) @trusted { //setOption(cast(SocketOptionLevel)SocketOptionLevel.SOCKET, SocketOption.LINGER, (&value)[0 .. 1]); setOption(level, option, (&value.clinger)[0 .. 1]); @@ -3225,7 +3225,7 @@ public: * sw.peek.msecs); * --- */ - void setOption(SocketOptionLevel level, SocketOption option, Duration value) @trusted const + void setOption(SocketOptionLevel level, SocketOption option, Duration value) @trusted { enforce(option == SocketOption.SNDTIMEO || option == SocketOption.RCVTIMEO, new SocketParameterException("Not a valid timeout option: " ~ to!string(option))); @@ -3253,7 +3253,7 @@ public: /// Get a text description of this socket's error status, and clear the /// socket's error status. - string getErrorText() const + string getErrorText() { int32_t error; getOption(SocketOptionLevel.SOCKET, SocketOption.ERROR, error); @@ -3273,7 +3273,7 @@ public: * $(D SocketFeatureException) if setting keep-alive parameters is * unsupported on the current platform. */ - void setKeepAlive(int time, int interval) @trusted const + void setKeepAlive(int time, int interval) @trusted { version(Windows) { @@ -3432,7 +3432,7 @@ public: /// Returns a new Address object for the current address family. /// Can be overridden to support other addresses. - protected Address createAddress() const pure nothrow + protected Address createAddress() pure nothrow { Address result; switch (_family) @@ -3504,6 +3504,51 @@ class UdpSocket: Socket } } +// Issue 16514 +unittest +{ + class TestSocket : Socket + { + override const pure nothrow @nogc @property @safe socket_t handle() { assert(false); } + override const nothrow @nogc @property @trusted bool blocking() { assert(false); } + override @property @trusted void blocking(bool byes) { assert(false); } + override @property @safe AddressFamily addressFamily() { assert(false); } + override const @property @trusted bool isAlive() { assert(false); } + override @trusted void bind(Address addr) { assert(false); } + override @trusted void connect(Address to) { assert(false); } + override @trusted void listen(int backlog) { assert(false); } + override protected pure nothrow @safe Socket accepting() { assert(false); } + override @trusted Socket accept() { assert(false); } + override nothrow @nogc @trusted void shutdown(SocketShutdown how) { assert(false); } + override nothrow @nogc @trusted void close() { assert(false); } + override @property @trusted Address remoteAddress() { assert(false); } + override @property @trusted Address localAddress() { assert(false); } + override @trusted ptrdiff_t send(const(void)[] buf, SocketFlags flags) { assert(false); } + override @safe ptrdiff_t send(const(void)[] buf) { assert(false); } + override @trusted ptrdiff_t sendTo(const(void)[] buf, SocketFlags flags, Address to) { assert(false); } + override @safe ptrdiff_t sendTo(const(void)[] buf, Address to) { assert(false); } + override @trusted ptrdiff_t sendTo(const(void)[] buf, SocketFlags flags) { assert(false); } + override @safe ptrdiff_t sendTo(const(void)[] buf) { assert(false); } + override @trusted ptrdiff_t receive(void[] buf, SocketFlags flags) { assert(false); } + override @safe ptrdiff_t receive(void[] buf) { assert(false); } + override @trusted ptrdiff_t receiveFrom(void[] buf, SocketFlags flags, ref Address from) { assert(false); } + override @safe ptrdiff_t receiveFrom(void[] buf, ref Address from) { assert(false); } + override @trusted ptrdiff_t receiveFrom(void[] buf, SocketFlags flags) { assert(false); } + override @safe ptrdiff_t receiveFrom(void[] buf) { assert(false); } + override @trusted int getOption(SocketOptionLevel level, SocketOption option, void[] result) { assert(false); } + override @trusted int getOption(SocketOptionLevel level, SocketOption option, out int32_t result) { assert(false); } + override @trusted int getOption(SocketOptionLevel level, SocketOption option, out Linger result) { assert(false); } + override @trusted void getOption(SocketOptionLevel level, SocketOption option, out Duration result) { assert(false); } + override @trusted void setOption(SocketOptionLevel level, SocketOption option, void[] value) { assert(false); } + override @trusted void setOption(SocketOptionLevel level, SocketOption option, int32_t value) { assert(false); } + override @trusted void setOption(SocketOptionLevel level, SocketOption option, Linger value) { assert(false); } + override @trusted void setOption(SocketOptionLevel level, SocketOption option, Duration value) { assert(false); } + override @safe string getErrorText() { assert(false); } + override @trusted void setKeepAlive(int time, int interval) { assert(false); } + override protected pure nothrow @safe Address createAddress() { assert(false); } + } +} + /** * Creates a pair of connected sockets. *