tarantool/tarantool
在 GitHub 查看bsdsocket: implement recfrom(), accept(), name(), peer() using FFI
Open
#893 建立於 2015年7月2日
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:
- Create ffi.cdef() for
struct sockaddr - Re-implement
lbox_bsdsocket_push_family(),lbox_bsdsocket_push_sotype(),lbox_bsdsocket_push_addr()using FFI (without removing existing Lua/C version) - Re-implement socket:recfrom() and socket:accept() using FFI
- Re-implement lbox_bsdsocket_peername() and lbox_bsdsocket_soname() using FFI
- Split
lbox_bsdsocket_getaddrinfo()into two parts:- Lua/C version should perform actual name resolution and then push
struct addrinfoto Lua stack usingluaL_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().
- Lua/C version should perform actual name resolution and then push
- 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