socket sendfile, for offloading file send to AP_Networking */
| 973 | socket sendfile, for offloading file send to AP_Networking |
| 974 | */ |
| 975 | int SocketAPM_sendfile(lua_State *L) { |
| 976 | binding_argcheck(L, 2); |
| 977 | |
| 978 | SocketAPM *ud = *check_SocketAPM(L, 1); |
| 979 | |
| 980 | auto *p = (luaL_Stream *)luaL_checkudata(L, 2, LUA_FILEHANDLE); |
| 981 | int fd = p->f->fd; |
| 982 | |
| 983 | bool ret = fd != -1 && AP::network().sendfile(ud, fd); |
| 984 | if (ret) { |
| 985 | // the fd is no longer valid. The lua script must |
| 986 | // still call close() to release the memory from the |
| 987 | // socket |
| 988 | p->f->fd = -1; |
| 989 | } |
| 990 | |
| 991 | lua_pushboolean(L, ret); |
| 992 | return 1; |
| 993 | } |
| 994 | |
| 995 | /* |
| 996 | receive from a socket to a lua string |
nothing calls this directly
no test coverage detected