Merge pull request #108 from moteus/master
Add. Pass socket as lightuserdata if it not fit to Lua number.
This commit is contained in:
commit
d0cde48bd0
@ -380,7 +380,7 @@ static int lcurl_multi_timeout(lua_State *L){
|
|||||||
|
|
||||||
static int lcurl_multi_socket_action(lua_State *L){
|
static int lcurl_multi_socket_action(lua_State *L){
|
||||||
lcurl_multi_t *p = lcurl_getmulti(L);
|
lcurl_multi_t *p = lcurl_getmulti(L);
|
||||||
curl_socket_t s = lutil_optint64(L, 2, CURL_SOCKET_TIMEOUT);
|
curl_socket_t s = lcurl_opt_os_socket(L, 2, CURL_SOCKET_TIMEOUT);
|
||||||
CURLMcode code; int n, mask;
|
CURLMcode code; int n, mask;
|
||||||
lua_State *curL;
|
lua_State *curL;
|
||||||
|
|
||||||
@ -551,7 +551,7 @@ static int lcurl_multi_socket_callback(CURL *easy, curl_socket_t s, int what, vo
|
|||||||
lua_rawgetp(L, -1, easy);
|
lua_rawgetp(L, -1, easy);
|
||||||
e = lcurl_geteasy_at(L, -1);
|
e = lcurl_geteasy_at(L, -1);
|
||||||
lua_remove(L, -2);
|
lua_remove(L, -2);
|
||||||
lutil_pushint64(L, s);
|
lcurl_push_os_socket(L, s);
|
||||||
lua_pushinteger(L, what);
|
lua_pushinteger(L, what);
|
||||||
|
|
||||||
if(lua_pcall(L, n+2, 0, 0)){
|
if(lua_pcall(L, n+2, 0, 0)){
|
||||||
|
@ -332,4 +332,58 @@ void lcurl_stack_dump (lua_State *L){
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
fprintf(stderr, " ------------ Stack Dump Finished ------------\n" );
|
fprintf(stderr, " ------------ Stack Dump Finished ------------\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
curl_socket_t lcurl_opt_os_socket(lua_State *L, int idx, curl_socket_t def) {
|
||||||
|
if (lua_islightuserdata(L, idx))
|
||||||
|
return (curl_socket_t)lua_touserdata(L, idx);
|
||||||
|
|
||||||
|
return (curl_socket_t)lutil_optint64(L, idx, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lcurl_push_os_socket(lua_State *L, curl_socket_t fd) {
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
lutil_pushint64(L, fd);
|
||||||
|
#else /*_WIN32*/
|
||||||
|
/* Assumes that compiler can optimize constant conditions. MSVC do this. */
|
||||||
|
|
||||||
|
/*On Lua 5.3 lua_Integer type can be represented exactly*/
|
||||||
|
#if LUA_VERSION_NUM >= 503
|
||||||
|
if (sizeof(curl_socket_t) <= sizeof(lua_Integer)) {
|
||||||
|
lua_pushinteger(L, (lua_Integer)fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_NUMBER_FLOAT)
|
||||||
|
/*! @todo test DBL_MANT_DIG, FLT_MANT_DIG */
|
||||||
|
|
||||||
|
if (sizeof(lua_Number) == 8) { /*we have 53 bits for integer*/
|
||||||
|
if ((sizeof(curl_socket_t) <= 6)) {
|
||||||
|
lua_pushnumber(L, (lua_Number)fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(((UINT_PTR)fd & 0x1FFFFFFFFFFFFF) == (UINT_PTR)fd)
|
||||||
|
lua_pushnumber(L, (lua_Number)fd);
|
||||||
|
else
|
||||||
|
lua_pushlightuserdata(L, (void*)fd);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sizeof(lua_Number) == 4) { /*we have 24 bits for integer*/
|
||||||
|
if (((UINT_PTR)fd & 0xFFFFFF) == (UINT_PTR)fd)
|
||||||
|
lua_pushnumber(L, (lua_Number)fd);
|
||||||
|
else
|
||||||
|
lua_pushlightuserdata(L, (void*)fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
lutil_pushint64(L, fd);
|
||||||
|
if (lcurl_opt_os_socket(L, -1, 0) != fd)
|
||||||
|
lua_pushlightuserdata(L, (void*)fd);
|
||||||
|
|
||||||
|
#endif /*_WIN32*/
|
||||||
|
}
|
||||||
|
@ -91,4 +91,8 @@ int lcurl_utils_apply_options(lua_State *L, int opt, int obj, int do_close,
|
|||||||
|
|
||||||
void lcurl_stack_dump (lua_State *L);
|
void lcurl_stack_dump (lua_State *L);
|
||||||
|
|
||||||
|
curl_socket_t lcurl_opt_os_socket(lua_State *L, int idx, curl_socket_t def);
|
||||||
|
|
||||||
|
void lcurl_push_os_socket(lua_State *L, curl_socket_t fd);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user