質問

I have a file descriptor (0/stdin) that I want to construct a Socket object of in D. How would I do this? There doesn't seem to be an appropriate constructor for this.

役に立ちましたか?

解決

There's a constructor marked "use an existing socket handle", which takes a socket_t. You can cast an int to socket_t (socket_t is an enum based on int on Unix systems).

    // it requires an address family but i don't think it matters much
    auto socket = new Socket(cast(socket_t) 0, AddressFamily.INET);

That will get you constructed, though then using it results in "Socket operation on non-socket" errors, because D's Socket calls send() and recv() rather that write() and read(), so I'm not sure how to actually make it useful...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top