digitalmars.D.learn - wrapSocket for socket_t? As wrapFile for FILE*
- Beginner-8 (5/5) Feb 13 2016 Hi!
- Adam D. Ruppe (12/14) Feb 13 2016 See the list on my unofficial docs here:
- tcak (10/15) Feb 13 2016 One of the constructors of class Socket is as follows:
- Beginner-8 (3/6) Feb 13 2016 Hmm, I am seen what Socket dtor contains close() too:
- Beginner-8 (6/12) Feb 13 2016 I would say that the socket should not be closed by my code.
- Beginner-8 (1/1) Feb 13 2016 (I went to make a patch to Phobos)
- =?UTF-8?Q?Ali_=c3=87ehreli?= (4/20) Feb 13 2016 Maybe another option is to duplicate the socket handle before giving it
- Beginner-8 (10/13) Feb 13 2016 Sure!
- Beginner-8 (1/1) Feb 14 2016 Uh, wait! Forgot about that Socket calls .close() in its dtor
- =?UTF-8?Q?Ali_=c3=87ehreli?= (8/9) Feb 14 2016 Try duplicating the socket handle before handing it over to Socket (not
- Beginner-8 (2/11) Feb 14 2016 This recipe works for me! Thanks!
Hi! Anyone seen Socket constructor which uses already available socket of socket_t type? I am need to use already connected socket imported from C library without closing them after using.
Feb 13 2016
On Sunday, 14 February 2016 at 04:13:12 UTC, Beginner-8 wrote:Anyone seen Socket constructor which uses already available socket of socket_t type?See the list on my unofficial docs here: http://dpldocs.info/experimental-docs/std.socket.Socket.html This one does it: http://dpldocs.info/experimental-docs/std.socket.Socket.this.5.html or the official docs here: But basically you can just do: auto socket = new Socket(your_socket_t, AddressFamily.INET); // or whatever it is AddressFamilies are: http://dpldocs.info/experimental-docs/std.socket.AddressFamily.html
Feb 13 2016
On Sunday, 14 February 2016 at 04:13:12 UTC, Beginner-8 wrote:Hi! Anyone seen Socket constructor which uses already available socket of socket_t type? I am need to use already connected socket imported from C library without closing them after using.One of the constructors of class Socket is as follows: pure nothrow nogc safe this(socket_t sock, AddressFamily af); socket_t is basically a file descriptor which is the type "int". Your C library provides you "socket_t" value already as far as I understand. So, you can pass it to constructor. Unless you explicitly call "close" method of Socket object, its descriptor will stay allocated for your process/program.
Feb 13 2016
On Sunday, 14 February 2016 at 06:01:11 UTC, tcak wrote:Unless you explicitly call "close" method of Socket object, its descriptor will stay allocated for your process/program.Hmm, I am seen what Socket dtor contains close() too: https://github.com/D-Programming-Language/phobos/blob/master/std/socket.d#L2659
Feb 13 2016
On Sunday, 14 February 2016 at 06:10:04 UTC, Beginner-8 wrote:On Sunday, 14 February 2016 at 06:01:11 UTC, tcak wrote:I would say that the socket should not be closed by my code. For files this way is wrapFile: "The resulting File never takes the initiative in closing the file." http://dlang.org/library/std/stdio/file.wrap_file.html It seems that something like this is necessary also for Socket.Unless you explicitly call "close" method of Socket object, its descriptor will stay allocated for your process/program.Hmm, I am seen what Socket dtor contains close() too: https://github.com/D-Programming-Language/phobos/blob/master/std/socket.d#L2659
Feb 13 2016
On 02/13/2016 10:38 PM, Beginner-8 wrote:On Sunday, 14 February 2016 at 06:10:04 UTC, Beginner-8 wrote:Maybe another option is to duplicate the socket handle before giving it to Socket but I am failing to find a definitive answer or an example. AliOn Sunday, 14 February 2016 at 06:01:11 UTC, tcak wrote:I would say that the socket should not be closed by my code. For files this way is wrapFile: "The resulting File never takes the initiative in closing the file." http://dlang.org/library/std/stdio/file.wrap_file.html It seems that something like this is necessary also for Socket.Unless you explicitly call "close" method of Socket object, its descriptor will stay allocated for your process/program.Hmm, I am seen what Socket dtor contains close() too: https://github.com/D-Programming-Language/phobos/blob/master/std/socket.d#L2659
Feb 13 2016
On Sunday, 14 February 2016 at 07:33:11 UTC, Ali Çehreli wrote:Maybe another option is to duplicate the socket handleSure! Nevertheless, it is need method for socket_t duplication. Something like: class Socket { ... static Socket dup(socket_t) ... }before giving it to Socket but I am failing to find a definitive answer or an example.
Feb 13 2016
Uh, wait! Forgot about that Socket calls .close() in its dtor
Feb 14 2016
On 02/14/2016 12:03 AM, Beginner-8 wrote:Uh, wait! Forgot about that Socket calls .close() in its dtorTry duplicating the socket handle before handing it over to Socket (not compiled nor tested): import core.sys.posix.unistd; Socket(dup(myHandle)) I think socket handles are duplicatable :p things. Only the last close() would actually close the socket. Ali
Feb 14 2016
On Sunday, 14 February 2016 at 08:19:16 UTC, Ali Çehreli wrote:On 02/14/2016 12:03 AM, Beginner-8 wrote:This recipe works for me! Thanks!Uh, wait! Forgot about that Socket calls .close() in its dtorTry duplicating the socket handle before handing it over to Socket (not compiled nor tested): import core.sys.posix.unistd; Socket(dup(myHandle)) I think socket handles are duplicatable :p things. Only the last close() would actually close the socket. Ali
Feb 14 2016