summary refs log tree commit diff stats
path: root/lib
Commit message (Expand)AuthorAgeFilesLines
* Replacement PR for https://github.com/nim-lang/Nim/pull/23779 that (#23793)c-blake2024-07-071-26/+42
* Update documentation for parseEnum in strutils.nim (#23804)Leon Lysak2024-07-061-2/+2
* Fixed issues when using `std/parseopt` in miscripts with cmdline = "" (#23785)Gianmarco2024-07-021-3/+15
* Fix doc: '\c' '\L' in lexbase.nim (#23781)lit2024-07-011-4/+4
* refine: strmisc.expandTabs better code structure (#23783)lit2024-07-011-9/+6
* fixes #5091; Ensure we don't wait on an exited process on Linux (#23743)Mark Leyva2024-07-011-0/+2
* fixes #23725; Size computations work better when they are correct (#23758)Andreas Rumpf2024-06-261-6/+10
* Check for nil in cstringArrayToSeq (#23747)Yuriy Glukhov2024-06-241-0/+2
* fixes #23742; setLen(0) no longer allocates memory for uninitialized strs/seq...ringabout2024-06-211-2/+8
* Add Farm Hash conditioned upon `nimPreviewHashFarm` as 64-bit `Hash` (#23735)c-blake2024-06-191-20/+184
* fixes #23732, os.sleep(-1) now returns immediately (#23734)lit2024-06-181-0/+3
* Fix NIM_STATIC_ASSERT_AUX being redefined on different lines (#23729)fakuivan2024-06-181-4/+8
* Fix non-exported `memfiles.setFileSize` to be able to shrink files on posix v...c-blake2024-06-141-36/+30
* fixes #22927; no test case extractable [backport] (#23707)Andreas Rumpf2024-06-121-11/+23
* fixes #23513, parseutils.nim: parseInt's doc example. (#23561)lit2024-06-121-8/+12
* fixes #22510 (#23100)Andreas Rumpf2024-06-061-27/+24
* make `std/options` compatible with strictdefs (#23675)ringabout2024-06-051-6/+6
* fix noreturn/implicit discard check logic (#23681)metagn2024-06-051-1/+1
* fixes #22798; Duplicate libraries linker warning (i.e., '-lm') on macOS (#23292)ringabout2024-06-022-2/+2
* fixes #23663; Add hash() for Path (#23664)ringabout2024-05-311-1/+8
* Treat CJK Ideographs as letters in `isAlpha()` (#23651)Alexander Kernozhitsky2024-05-291-1957/+1948
* revert #23436; remove workaround (#23653)ringabout2024-05-281-2/+0
* fixes #23635; tasks.toTask Doesn't Expect a Dot Expression (#23641)ringabout2024-05-271-4/+20
* fixes #22852; fixes #23435; fixes #23645; SIGSEGV when slicing string or seq[...ringabout2024-05-271-4/+1
* Handle arbitrarily long symlink target in `expandSymlinks()` (#23650)Alexander Kernozhitsky2024-05-271-8/+10
* doc(format): ospaths2,strutils: followup #23560 (#23629)lit2024-05-202-9/+9
* doc(format): system.nim: doc of hostCPU for `loongarch64` (#23621)lit2024-05-171-1/+1
* provides a `$` function for `Path` (#23617)ringabout2024-05-171-0/+3
* Support NetBSD/aarch64 (#23616)PHO2024-05-161-2/+3
* fixes deprecation messages and adds missing commas (#23609)ringabout2024-05-141-3/+3
* adds Nim-related mimetypes back (#23589)ringabout2024-05-101-0/+4
* Improve strutils.rsplit doc, proc and iterator have oppose result order. (#23...lit2024-05-101-6/+6
* Add Complex version of almostEqual function (#23549)Angel Ezquerra2024-05-081-3/+18
* fixes 12381, HttpClient socket handle leak (#23575)Marius Andra2024-05-081-0/+2
* rework `wasMoved`, `move` on the JS backend (#23577)ringabout2024-05-081-31/+0
* fixes #23442, fix for FileId under Windows (#23444)lit2024-05-081-4/+4
* fixes #23556; typeinfo.extendSeq generates random values in ORC (#23557)ringabout2024-05-032-2/+11
* Update unicode.nim: cmpRunesIgnoreCase: fix doc format (#23560)lit2024-05-021-6/+6
* fixes #23524; global variables cannot be analysed when injecting `move` (#23529)ringabout2024-04-241-3/+5
* Fix std/base64.decode out of bounds read (#23526)bptato2024-04-221-1/+1
* workaround #23435; real fix pending #23279 (#23436)ringabout2024-04-181-0/+2
* fixes #4695; closure iterators support for JS backend (#23493)ringabout2024-04-181-0/+4
* allow Nix builds by not calling git in isGitRepo for Nimble (#23515)Jakub2024-04-181-10/+3
* strictdefs for `repr` so that it can used for debugging purposes in t… (#23...ringabout2024-04-151-2/+2
* fixes #23487; JS chckNilDisp is wrong (#23490)ringabout2024-04-131-1/+1
* fix JSON deep copy description (#23495)Pouriya Jamshidi2024-04-121-1/+1
* fixes #4299 #12492 #10849; lambda lifting for JS backend (#23484)ringabout2024-04-112-1/+13
* Better documentation for typedthreads module (#23483)Antoine Delègue2024-04-111-27/+67
* fixes addr/hiddenAddr in strictdefs (#23477)ringabout2024-04-101-1/+1
* Update encodings.nim, fix `open` with bad arg raising no `EncodingError` (#23...lit2024-04-061-1/+1
l_select}, {NULL, NULL} }; /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ int select_open(lua_State *L) { lua_pushstring(L, "_SETSIZE"); lua_pushinteger(L, FD_SETSIZE); lua_rawset(L, -3); lua_pushstring(L, "_SOCKETINVALID"); lua_pushinteger(L, SOCKET_INVALID); lua_rawset(L, -3); luaL_setfuncs(L, func, 0); return 0; } /*=========================================================================*\ * Global Lua functions \*=========================================================================*/ /*-------------------------------------------------------------------------*\ * Waits for a set of sockets until a condition is met or timeout. \*-------------------------------------------------------------------------*/ static int global_select(lua_State *L) { int rtab, wtab, itab, ret, ndirty; t_socket max_fd = SOCKET_INVALID; fd_set rset, wset; t_timeout tm; double t = luaL_optnumber(L, 3, -1); FD_ZERO(&rset); FD_ZERO(&wset); lua_settop(L, 3); lua_newtable(L); itab = lua_gettop(L); lua_newtable(L); rtab = lua_gettop(L); lua_newtable(L); wtab = lua_gettop(L); collect_fd(L, 1, itab, &rset, &max_fd); collect_fd(L, 2, itab, &wset, &max_fd); ndirty = check_dirty(L, 1, rtab, &rset); t = ndirty > 0? 0.0: t; timeout_init(&tm, t, -1); timeout_markstart(&tm); ret = socket_select(max_fd+1, &rset, &wset, NULL, &tm); if (ret > 0 || ndirty > 0) { return_fd(L, &rset, max_fd+1, itab, rtab, ndirty); return_fd(L, &wset, max_fd+1, itab, wtab, 0); make_assoc(L, rtab); make_assoc(L, wtab); return 2; } else if (ret == 0) { lua_pushstring(L, "timeout"); return 3; } else { luaL_error(L, "select failed"); return 3; } } /*=========================================================================*\ * Internal functions \*=========================================================================*/ static t_socket getfd(lua_State *L) { t_socket fd = SOCKET_INVALID; lua_pushstring(L, "getfd"); lua_gettable(L, -2); if (!lua_isnil(L, -1)) { lua_pushvalue(L, -2); lua_call(L, 1, 1); if (lua_isnumber(L, -1)) { double numfd = lua_tonumber(L, -1); fd = (numfd >= 0.0)? (t_socket) numfd: SOCKET_INVALID; } } lua_pop(L, 1); return fd; } static int dirty(lua_State *L) { int is = 0; lua_pushstring(L, "dirty"); lua_gettable(L, -2); if (!lua_isnil(L, -1)) { lua_pushvalue(L, -2); lua_call(L, 1, 1); is = lua_toboolean(L, -1); } lua_pop(L, 1); return is; } static void collect_fd(lua_State *L, int tab, int itab, fd_set *set, t_socket *max_fd) { int i = 1, n = 0; /* nil is the same as an empty table */ if (lua_isnil(L, tab)) return; /* otherwise we need it to be a table */ luaL_checktype(L, tab, LUA_TTABLE); for ( ;; ) { t_socket fd; lua_pushnumber(L, i); lua_gettable(L, tab); if (lua_isnil(L, -1)) { lua_pop(L, 1); break; } /* getfd figures out if this is a socket */ fd = getfd(L); if (fd != SOCKET_INVALID) { /* make sure we don't overflow the fd_set */ #ifdef _WIN32 if (n >= FD_SETSIZE) luaL_argerror(L, tab, "too many sockets"); #else if (fd >= FD_SETSIZE) luaL_argerror(L, tab, "descriptor too large for set size"); #endif FD_SET(fd, set); n++; /* keep track of the largest descriptor so far */ if (*max_fd == SOCKET_INVALID || *max_fd < fd) *max_fd = fd; /* make sure we can map back from descriptor to the object */ lua_pushnumber(L, (lua_Number) fd); lua_pushvalue(L, -2); lua_settable(L, itab); } lua_pop(L, 1); i = i + 1; } } static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set) { int ndirty = 0, i = 1; if (lua_isnil(L, tab)) return 0; for ( ;; ) { t_socket fd; lua_pushnumber(L, i); lua_gettable(L, tab); if (lua_isnil(L, -1)) { lua_pop(L, 1); break; } fd = getfd(L); if (fd != SOCKET_INVALID && dirty(L)) { lua_pushnumber(L, ++ndirty); lua_pushvalue(L, -2); lua_settable(L, dtab); FD_CLR(fd, set); } lua_pop(L, 1); i = i + 1; } return ndirty; } static void return_fd(lua_State *L, fd_set *set, t_socket max_fd, int itab, int tab, int start) { t_socket fd; for (fd = 0; fd < max_fd; fd++) { if (FD_ISSET(fd, set)) { lua_pushnumber(L, ++start); lua_pushnumber(L, (lua_Number) fd); lua_gettable(L, itab); lua_settable(L, tab); } } } static void make_assoc(lua_State *L, int tab) { int i = 1, atab; lua_newtable(L); atab = lua_gettop(L); for ( ;; ) { lua_pushnumber(L, i); lua_gettable(L, tab); if (!lua_isnil(L, -1)) { lua_pushnumber(L, i); lua_pushvalue(L, -2); lua_settable(L, atab); lua_pushnumber(L, i); lua_settable(L, atab); } else { lua_pop(L, 1); break; } i = i+1; } }