diff --git a/std/socket.d b/std/socket.d index dee2c6467c8..7edbf112704 100644 --- a/std/socket.d +++ b/std/socket.d @@ -2739,13 +2739,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; @@ -2753,7 +2753,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"); @@ -2764,7 +2764,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)) { @@ -2797,7 +2797,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"); @@ -2812,7 +2812,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; } @@ -2822,7 +2822,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) @@ -2849,7 +2849,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); } @@ -2894,7 +2894,7 @@ public: } /// Remote endpoint $(D Address). - @property Address remoteAddress() const @trusted + @property Address remoteAddress() @trusted { Address addr = createAddress(); socklen_t nameLen = addr.nameLen; @@ -2907,7 +2907,7 @@ public: } /// Local endpoint $(D Address). - @property Address localAddress() const @trusted + @property Address localAddress() @trusted { Address addr = createAddress(); socklen_t nameLen = addr.nameLen; @@ -2942,7 +2942,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))) { @@ -2956,7 +2956,7 @@ public: } /// ditto - ptrdiff_t send(const(void)[] buf) @trusted const nothrow @nogc + ptrdiff_t send(const(void)[] buf) { return send(buf, SocketFlags.NONE); } @@ -2968,7 +2968,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))) { @@ -2984,7 +2984,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); } @@ -2992,7 +2992,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))) { @@ -3007,7 +3007,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); } @@ -3020,7 +3020,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 { @@ -3037,7 +3037,7 @@ public: } /// ditto - ptrdiff_t receive(void[] buf) @trusted const nothrow @nogc + ptrdiff_t receive(void[] buf) { return receive(buf, SocketFlags.NONE); } @@ -3049,7 +3049,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; @@ -3074,7 +3074,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); } @@ -3082,7 +3082,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; @@ -3103,7 +3103,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); } @@ -3112,7 +3112,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)) @@ -3122,21 +3122,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))); @@ -3160,7 +3160,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)) @@ -3169,14 +3169,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]); @@ -3223,7 +3223,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))); @@ -3251,7 +3251,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); @@ -3271,7 +3271,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) { @@ -3430,7 +3430,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) @@ -3502,6 +3502,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. *