Re: How can I wrap SSL on Dlang Socket?
On Monday, 16 November 2020 at 01:25:01 UTC, Marcone wrote: How can I wrap SSL on Dlang Socket like I wrap in Python? There is no functionality in the standard library. If you are just looking for a HTTP client, use std.net.curl. If you want your own thing or need a server application you need a custom crypto-library for that.
Issue with opening files on VSCode "D Language utility extension pack"
Hi All, On VS Code "D Language utility extension pack", I notice that if I open a random D file, on the bottom left of the IDE, a message says "D: workspace/(0.0%): starting up...". It stays at 0.0% and doesn't go away and gives the impression that it is broken. Opening a file through a folder in explorer mode however works. Thanks
How can I wrap SSL on Dlang Socket?
How can I wrap SSL on Dlang Socket like I wrap in Python?
Re: How can execute method in new Thread?
On Saturday, 14 November 2020 at 17:21:15 UTC, Marcone wrote: Error: D:\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d(516): Error: struct `Fruit` does not overload () I think you need to pass the this pointer somehow. This works: import std; struct Fruit { string name; static void printmyname(Fruit thisFruit) { writeln(thisFruit.name); } void showname() { task!printmyname(this).executeInNewThread; } } void main() { Fruit f = Fruit("Banana"); f.showname(); } This does too: import std; struct Fruit { string name; void printmyname() { writeln(name); } void showname() { task!((Fruit me){me.printmyname;})(this).executeInNewThread; } } void main() { Fruit f = Fruit("Banana"); f.showname(); } —Bastiaan.
Re: How can execute method in new Thread?
On Saturday, 14 November 2020 at 17:21:15 UTC, Marcone wrote: Error: D:\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d(516): Error: struct `Fruit` does not overload () You can't. Because everything that can run in a new thread must be a (separate) function. If you are using an object (you accessing this) the compiler will generate a delegate instead and cannot pass that to a thread. So you need to make printmyname() a static function. Then you have the problem that you cannot access the object (this). You can only pass the instance you want to work with as a function argument. You do not need "ref" here. But if you omit that keyword the struct may get copied instead and you will see no changes in the passed struct. struct Fruit { string name; this(string name){ this.name = name; } static void printmyname(ref Fruit fruit){ writeln(fruit.name); } void showname(){ task!(printmyname)(this).executeInNewThread(); } }
extern(C) Variant: attempting to use incompatible types int and int
I know the problem that TypeInfo != TypeInfo in main and library context. Is there are a hack to get the data from the Variant even if the TypeInfo-check fails? I assume the only workaround is using an own struct or serializer to achieve the same functionality?
Re: How can I set Timeout of Socket?
On Sunday, 15 November 2020 at 00:05:08 UTC, Marcone wrote: Socket s = new Socket(AddressFamily.INET, SocketType.STREAM); s.connect(new InternetAddress("domain.com", 80)); I want that program raise an error if reach for example 30 seconds of timeout. My program does something like this. (untested) Socket s = new TcpSocket; s.setOption(SocketOptionLevel.SOCKET, SocketOption.RCVTIMEO, 30.seconds); s.setOption(SocketOptionLevel.SOCKET, SocketOption.SNDTIMEO, 30.seconds); auto addresses = getAddress("domain.com", 80); bool isConnected; foreach (address; addresses) { try { s.connect(address); isConnected = true; break; } catch (SocketException e) { // Failed, try next address writeln(e.msg); } } if (!isConnected) return false; // failed to connect // Connected You can tell whether a read timed out by looking at the amount of bytes read (when `Socket.receive` returns `Socket.ERROR`) and the value of `std.socket.lastSocketError` (and/or `core.stdc.errno.errno` equaling EAGAIN).
Re: How format UnixTime to "%Hh:%Mm:%Ss" ?
On Sunday, 15 November 2020 at 03:14:07 UTC, Marcone wrote: I want to convert seconds to hour, minut and second. Do you want to convert a *duration* into hours/minutes/seconds, or format a UNIX *timestamp* to hours/minutes/seconds? These are conceptually two different things. `Clock.currTime` will return a `SysTime` (a point in time) in your local timezone. If you want to get the hour/minute/second parts of a duration of time (for instance, in seconds), use a `Duration` and `split`. // Função strftime() string strftime(string fmt, int tempo){ long H, M, S; tempo.seconds.split!("hours", "minutes", "seconds")(H, M, S); return fmt.replace("%H", H.text).replace("%M", M.text).replace("%S", S.text); } writeln(strftime("%H:%M:%S", 4783)); // 1:19:43 https://run.dlang.io/is/0L5yqP https://dlang.org/articles/intro-to-datetime.html
Re: magically a static member on init?
On Sunday, 15 November 2020 at 00:29:41 UTC, H. S. Teoh wrote: if you don't like the semantics, don't use it; always allocate the field in the class ctor instead. Hi, i neither like it nor dislike it - it just caught me by surprise because i was under the impression that if i create a new instance then all members get initialized according to the declared optional default value. I can see how this is a feature - but it is also of kind "expert knowledge" and i would argue that "expert knowladge" is a designs arch enemy.