[Haskell-cafe] How to return a network connection to C

C K Kashyap ckkashyap at gmail.com
Thu Feb 28 19:59:36 CET 2013


Okay, for now I have figured out a working solution to the original problem
I was facing .....

I just forkIO another IO action that does the actual network work and in
addition, it opens a server socket and waits for commands.

The calls from C reach Haskell, from where a connection is made to the
server and command is sent. A little convoluted but works. I have the whole
implementation here - https://github.com/ckkashyap/gmail
So now I am able to create a standalone, self sufficient DLL that I can
just hand off to the folks in my org and they can write a C program and
connect to gmail!!!!

Hey Donn ... when you say, implement the IO in C, you also imply
implementing the SSL stuff too right? ... that's one thing I wanted to
avoid - and I was also reluctant to use something like openSSL because that
would come in the way of making standalone, self - sufficient DLL.

I really have to see what kind of performance hit my DLL has ...

Regards,
Kashyap


On Fri, Mar 1, 2013 at 12:07 AM, Donn Cave <donn at avvanta.com> wrote:

> Quoth C K Kashyap <ckkashyap at gmail.com>,
>
> > I am using http://hackage.haskell.org/package/connection.
> > So I create network connection in Haskell
> >
> > getConnection :: IO Connection
> >
> > I'd like this connection to be returned to C so that subsequent calls
> from
> > C can send in the connection handle.
>
> According to the documentation, he doesn't export enough of the
> Connection type to access the handle inside, and there appears to
> be no function provided to do that either.  So it looks to me like
> you'd have to 1) make the connection "by hand" with Network.Socket.connect
> etc., 2) get the Socket fd, 3) make a Handle from the Socket,
> 4) pass that to connectFromHandle, and 5) use the fd with your
> C function.
>
> Note that the socket connection itself, represented by the fd that
> you return to C, will simply transmit data back and forth without
> modification.  Specifically without SSL encryption.  If you need
> SSL encryption in both Haskell and C, it would probably be simpler
> to implement the I/O in C and call it from Haskell.
>
>         Donn
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130301/4fac543f/attachment.htm>


More information about the Haskell-Cafe mailing list