lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sat, Aug 23, 2014 at 12:47 AM, Coroutines <coroutines@gmail.com> wrote:

> My bad, I thought I read static :\  Stack overflows are fun... :p  I
> was just thinking offhandedly that you could create a mmap, expose it
> to Lua as a file to read and write from -- and pass it to the
> networking lib as the buffer to recv into.  Hmm.  And it could be
> shared depending on the threading setup -- but that's an afterthought.

Hmm.  This is another tangent -- mostly talking to Sean here.  I was
off-base when I said mmap() -- I haven't used mmap() often and for
some reason I thought I could take a [page-sized] block of memory and
get an fd from it.  WRONG.  I was really thinking of shm_open().  I
wouldn't be sharing the userdata memory, just making it
"fd-accessible".  I'm thinking about making a library to expose
userdata to Lua as file handles.  You'd have userdata exist in one
spot in Lua's memory and then you'd create the file handle which
references that userdata with this library.  This isn't doing what I'm
talking about in this thread, but I thought it would be cool.
Basically I'd use shm_open() on Linux to get an fd, and on Windows
it'd be CreateFileMapping() (which returns a HANDLE that you can feed
to open_osfhandle() to get an fd again).  Would be kinda cool to
operate on userdata as if it were a file or :read() strings from them
-- the number of other interfaces/modules that opens up would be so
worth it :-)  Of course this might all be pointless -- I just didn't
want to duplicate the file handle functions or offer up my own
functions for filling/reading/modify userdata arbitrarily.  It's
exciting when you can make a little glue code to get to other
interfaces, right? :D

Windows: CreateFileMapping()
Mac OS X: shm_open()
Linux: shm_open()

(Again, I recognize the security concerns -- still at the drawing
board over here..)