tarantool/tarantool

bsdsocket: implement recfrom(), accept(), name(), peer() using FFI

Open

#893 建立於 2015年7月2日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)Lua (3,633 star) (406 fork)batch import
featuregood first issue

描述

The reason these function were implemented in Lua/C was complexity of struct sockaddr for ffi.cdef(). However, it is possible to define this structure in FFI in platform-independent way. Please take a look on C preprocessor output and definition in [ljsyscall](https://github.com/justincormack/ljsyscall project).

The plan:

  1. Create ffi.cdef() for struct sockaddr
  2. Re-implement lbox_bsdsocket_push_family(), lbox_bsdsocket_push_sotype(), lbox_bsdsocket_push_addr() using FFI (without removing existing Lua/C version)
  3. Re-implement socket:recfrom() and socket:accept() using FFI
  4. Re-implement lbox_bsdsocket_peername() and lbox_bsdsocket_soname() using FFI
  5. Split lbox_bsdsocket_getaddrinfo() into two parts:
    • Lua/C version should perform actual name resolution and then push struct addrinfo to Lua stack using luaL_pushcdata() (the code above this line).
    • Lua/FFI version should call Lua/C version, get struct addrinfo, set ffi.gc() on it and create corresponding Lua table with results using new Lua code of lbox_bsdsocket_push_addr().
  6. Remove lbox_bsdsocket_push_addr(), lbox_bsdsocket_push_family() and so on.

As result your boxsocket.cc file will contain only two Lua/C functions:

    { "iowait",     lbox_bsdsocket_iowait       },
    { "abort",      lbox_bsdsocket_abort        },
        { NULL,         NULL                }

Please discuss with me how to split this work into patches.

P.S. lbox_socket_abort() will be affected by #880

貢獻者指南