Re: recvmsg on AsyncSocket

2019-11-29 Thread AMIGrAve
> but we do have recvFrom, can you use that instead?

I will check that and keep posted

> I'm curious what you're trying to achieve at a high level though, maybe there 
> is another way that doesn't require FDs being sent across processes?

I've already built this containerized shared hosting platform in python which 
has been successfully running on production for 3 years and actually I was 
looking at nim in order to speed up one part of the platform which can 
bottleneck on high concurrency. In many cases I have to pass file descriptors 
from the "host" to some linux namespaced processes.


Re: recvmsg on AsyncSocket

2019-11-28 Thread AMIGrAve
Thanks for backing me up @cumulonimbus .

So yeah, you can transfer file descriptors between processes. Each process have 
his file descriptor table but the resource behind it can be shared to another 
process through an ipc socket.

Here's how you would pass a payload along with one or more file descriptors 
through an ipc socket in python:


sock.sendmsg([payload], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, 
array.array("i", [file_descriptor]))])


Run

...receiving it on the other side can be done with recvmsg: 
[https://docs.python.org/3/library/socket.html#socket.socket.recvmsg](https://docs.python.org/3/library/socket.html#socket.socket.recvmsg)

I'm still a nim newbie and I wouldn't even know where to start in order to 
implement recvmsg in async mode, that said I'm surprised no one encountered 
this issue before as it's a common practice when doing low level networking 
systems.

Maybe @dom96 have some experience with this ?


Re: recvmsg on AsyncSocket

2019-11-25 Thread AMIGrAve
Sorry to bump this but anyone here ever succeeded to pass a file descriptor 
through an ipc socket in nim async ? It seems to me that it's a common practice 
when writing servers and I'm surprised nim would not cover it.


Accessing selectors from dispatcher ?

2019-11-21 Thread AMIGrAve
I'm struggling trying to use selectors on an AsyncSocket but despite checking 
the dom96's httpbeast source I can't get it to work.

Anyway, before trying harder I'm wondering if the async dispatcher is using 
selectors on it's registered descriptors. In such case is it possible to get 
access to those descriptors so it would avoid to do instantiate one by myself ?


Re: recvmsg on AsyncSocket

2019-10-18 Thread AMIGrAve
Actually I didn't meant passing a string but it's my fault because I left a var 
buf: cstring which was just a test.

recvmsg and sendmsg allows to pass a structure which can be used to pass file 
descriptors.

So I'm not talking about simply passing a string through a socket here but 
passing file descriptors from a process to another. So recvLine won't help me 
here. 


recvmsg on AsyncSocket

2019-10-17 Thread AMIGrAve
Hi,

I'm trying to pass a file descriptor from a python program to a nim program but 
I can't find a way to do it:


# the server is created like this:
# var server = newAsyncSocket(AF_UNIX, SOCK_STREAM, IPPROTO_IP)
# server.bindUnix("\0proxy")
# and the client socket is dispatched to a processClient function

proc processClient(client: AsyncSocket) {.async.} =
var buf: cstring
let n = client.recvmsg(addr buf, 4096)


Run

but the compilation error is:


Error: attempting to call undeclared routine: 'recvmsg'


Run

So I guess that recvmsg is not defined for async sockets, is this expected/not 
yet implemented ?

I tried to google for an example of message passing with a file descriptor 
through an async socket but I could not find one.

Is it possible to do such a thing in nim ?


Re: call glibc functions

2019-10-06 Thread AMIGrAve
Thanks @Araq, I was messing with emitc instead of simply using importc


call glibc functions

2019-09-28 Thread AMIGrAve
I can feel it's a stupid question but how I call glibc functions from nim ?