<div dir="ltr">Thank's David.<div>I followed your advice (this plugin is included in Pharo).</div><div><br></div><div>So I succeed with libssh2. There are a couple of strange issues but they are not critical for now.</div><div>Project is on github <a href="https://github.com/dionisiydk/libssh2-pharo-bindings">https://github.com/dionisiydk/libssh2-pharo-bindings</a>. It uses UFFI. So it is only for Pharo</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-08-08 21:43 GMT+02:00 David T. Lewis <span dir="ltr"><<a href="mailto:lewis@mail.msen.com" target="_blank">lewis@mail.msen.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Good guidance on how to do it with a plugin (and please do give it a try!).<br>
Also, if you have the AIO plugin in your VM, check and see if this works<br>
for you:<br>
<br>
primOSSocketHandle: sqSocket<br>
        "Answer the low level socket descriptor for a socket IO handle."<br>
<br>
        <primitive: 'primitiveOSSocketHandle' module: 'AioPlugin'><br>
        ^ nil<br>
<br>
See class AioEventHandler in the OSProcess package for example usage.<br>
<br>
Dave<br>
<span class=""><br>
<br>
On Tue, Aug 08, 2017 at 11:34:16AM -0700, Eliot Miranda wrote:<br>
><br>
> Hi Denis,<br>
><br>
> On Tue, Aug 8, 2017 at 2:11 AM, Denis Kudriashov <<a href="mailto:dionisiydk@gmail.com">dionisiydk@gmail.com</a>><br>
> wrote:<br>
><br>
> ><br>
</span><span class="">> > Hi.<br>
> ><br>
> > I play a bit of idea to make binding to libssh2 library.<br>
> ><br>
> > And the main problem is function<br>
> ><br>
> > int libssh2_session_handshake(<wbr>LIBSSH2_SESSION *session, libssh2_socket_t<br>
> > socket)<br>
> ><br>
> > where socket parameter is raw OS socket handle as I understand.<br>
> ><br>
> > So question: is it possible to access this handle from image side from<br>
> > Socket instance?<br>
> ><br>
><br>
</span>> Yes, but non-trivially.<br>
<span class="im HOEnZb">><br>
><br>
> > There is socketHandle instance variable which is bytearray. What is it?<br>
> ><br>
><br>
</span><div class="HOEnZb"><div class="h5">> It is an instance of this struct:<br>
><br>
> typedef struct<br>
> {<br>
>   int   sessionID;<br>
>   int   socketType;  /* 0 = TCP, 1 = UDP */<br>
>   void  *privateSocketPtr;<br>
> }  SQSocket, *SocketPtr;<br>
><br>
> The two most common definitions are:<br>
> linux/mac<br>
> typedef struct privateSocketStruct<br>
> {<br>
>   int s;            /* Unix socket */<br>
>   int connSema;         /* connection io notification semaphore */<br>
>   int readSema;         /* read io notification semaphore */<br>
>   int writeSema;        /* write io notification semaphore */<br>
>   int sockState;        /* connection + data state */<br>
>   int sockError;        /* errno after socket error */<br>
>   union sockaddr_any peer;  /* default send/recv address for UDP */<br>
>   socklen_t peerSize;       /* dynamic sizeof(peer) */<br>
>   union sockaddr_any sender;    /* sender address for last UDP receive */<br>
>   socklen_t senderSize;     /* dynamic sizeof(sender) */<br>
>   int multiListen;      /* whether to listen for multiple connections */<br>
>   int acceptedSock;     /* a connection that has been accepted */<br>
> } privateSocketStruct;<br>
><br>
> win32:<br>
> typedef struct privateSocketStruct {<br>
>   struct privateSocketStruct *next;<br>
>   SOCKET s;<br>
><br>
>   int sockType;<br>
>   int sockState;<br>
>   int sockError;<br>
><br>
>   int readSema;<br>
>   int writeSema;<br>
>   int connSema;<br>
><br>
>   union sockaddr_any peer;  /* socket address in connect() or send/rcv<br>
> address for UDP */<br>
>   socklen_t peerSize;       /* dynamic sizeof(peer) */<br>
><br>
>   HANDLE mutex;             /* The mutex used for synchronized access to<br>
> this socket */<br>
>   acceptedSocketStruct *accepted; /* Accepted connections on a socket */<br>
><br>
><br>
>   DWORD  readWatcherOp;      /* read operation to watch */<br>
>   HANDLE hReadWatcherEvent;  /* event for waking up read watcher */<br>
>   HANDLE hReadThread;<br>
><br>
>   DWORD  writeWatcherOp;     /* write operation to watch */<br>
>   HANDLE hWriteWatcherEvent; /* event for waking up write watcher */<br>
>   HANDLE hWriteThread;<br>
><br>
>   volatile DWORD closePending; /* Cleanup counter */<br>
><br>
>   int readSelect;<br>
>   int writeSelect;<br>
> } privateSocketStruct;<br>
><br>
> So you *could* create an Alien on the 4 bytes at 9 in the handle on<br>
> 32-bits, or the 8 bytes at 9 on 64-bits, and then decode the resulting<br>
> pointer to a privateSocketStruct.  On linux & mac os it is the 4 bytes at<br>
> 1.  On Win32 it's the 4 bytes at 5, and on Win64 it's the 4 bytes at 9.<br>
><br>
> But I would instead add a new primitive to the socket plugin, something<br>
> like primitiveSocketGetNativeHandle<wbr>, and use that :-)<br>
><br>
> To do this:<br>
> a) modify VMMaker.oscog's SocketPlugin to add the primitive<br>
> b) in platforms/Cross/plugins/<wbr>SocketPlugin./SocketPlugin.h add something<br>
> like<br>
>     sqInt sqSocketNativeHandle(SocketPtr s, int type);<br>
> where type is, say, 0 for the normal file descriptor and other values for<br>
> future use (one platform has both data and control sockets in its<br>
> privateSocketStruct<br>
> c) implement sqSocketNativeHandle appropriately in<br>
> platforms/unix/plugins/<wbr>SocketPlugin/sqUnixSocket.c,<br>
> platforms/win32/plugins/<wbr>SocketPlugin/sqWin32NewNet.c et al. There are 5 in<br>
> all; Mac OS Carbon, RiscOS & Plan9 are the other three.)<br>
><br>
> Best regards,<br>
> > Denis<br>
> ><br>
><br>
> _,,,^..^,,,_<br>
> best, Eliot<br>
<br>
</div></div></blockquote></div><br></div>