Re: wrapSocket for socket_t? As wrapFile for FILE*

2016-02-14 Thread Beginner-8 via Digitalmars-d-learn

On Sunday, 14 February 2016 at 08:19:16 UTC, Ali Çehreli wrote:

On 02/14/2016 12:03 AM, Beginner-8 wrote:

Uh, wait! Forgot about that Socket calls .close() in its dtor


Try 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


This recipe works for me! Thanks!


Re: wrapSocket for socket_t? As wrapFile for FILE*

2016-02-14 Thread Beginner-8 via Digitalmars-d-learn

Uh, wait! Forgot about that Socket calls .close() in its dtor


Re: wrapSocket for socket_t? As wrapFile for FILE*

2016-02-14 Thread Beginner-8 via Digitalmars-d-learn

On Sunday, 14 February 2016 at 07:33:11 UTC, Ali Çehreli wrote:


Maybe another option is to duplicate the socket handle


Sure!

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.




Re: wrapSocket for socket_t? As wrapFile for FILE*

2016-02-13 Thread Beginner-8 via Digitalmars-d-learn

(I went to make a patch to Phobos)


Re: wrapSocket for socket_t? As wrapFile for FILE*

2016-02-13 Thread Beginner-8 via Digitalmars-d-learn

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:

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


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.



Re: wrapSocket for socket_t? As wrapFile for FILE*

2016-02-13 Thread Beginner-8 via Digitalmars-d-learn

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



wrapSocket for socket_t? As wrapFile for FILE*

2016-02-13 Thread Beginner-8 via Digitalmars-d-learn

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.