The amount of time to wait is specified as the value parameter, in seconds.
- The timeout modes are bot implemented, the only settable timeout is the
+ The timeout modes are not implemented, the only settable timeout is the
inactivity time waiting for complete the internal buffer send or waiting for
receive data.
:param class_socket socket: Is the manipulated Socket.
- :param integer value: The timeout value.
+ :param float value: The timeout value. Use flotting point to specify
+ milliseconds.
.. _regex_class:
*/
#include <ctype.h>
+#include <limits.h>
#include <setjmp.h>
#include <lauxlib.h>
{
struct hlua_socket *socket;
int tmout;
+ double dtmout;
struct xref *peer;
struct appctx *appctx;
struct stream_interface *si;
MAY_LJMP(check_args(L, 2, "settimeout"));
socket = MAY_LJMP(hlua_checksocket(L, 1));
- tmout = MAY_LJMP(luaL_checkinteger(L, 2)) * 1000;
+
+ /* round up for inputs that are fractions and convert to millis */
+ dtmout = (0.5 + MAY_LJMP(luaL_checknumber(L, 2))) * 1000;
/* Check for negative values */
- if (tmout < 0)
+ if (dtmout < 0)
WILL_LJMP(luaL_error(L, "settimeout: cannot set negatives values"));
+ if (dtmout > INT_MAX) /* overflow check */
+ WILL_LJMP(luaL_error(L, "settimeout: cannot set values larger than %d", INT_MAX));
+
+ tmout = MS_TO_TICKS((int)dtmout);
+
/* Check if we run on the same thread than the xreator thread.
* We cannot access to the socket if the thread is different.
*/
if (socket->tid != tid)
WILL_LJMP(luaL_error(L, "connect: cannot use socket on other thread"));
- /* check for connection break. If some data where read, return it. */
+ /* check for connection break. If some data were read, return it. */
peer = xref_get_peer_and_lock(&socket->xref);
if (!peer) {
hlua_pusherror(L, "socket: not yet initialised, you can't set timeouts.");