From ed8fe903ec2344a341eefdfaa117a6b937d4b3bc Mon Sep 17 00:00:00 2001 From: Emil Renner Berthing Date: Mon, 28 Jan 2013 13:25:10 +0100 Subject: io: don't try to emulate TCP_CORK with TCP_NOPUSH OSX and some versions FreeBSD doesn't send data immediately after unsetting TCP_NOPUSH. On OSX if you set TCP_NOPUSH, write data and then unset TCP_NOPUSH you'll get a 2 second delay before the last data is sent. Unfortunately I've found no reliable work-around. --- lem/io.lua | 9 +++++++++ lem/io/core.c | 2 ++ lem/io/stream.c | 6 ++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lem/io.lua b/lem/io.lua index 41d7732..26f4274 100644 --- a/lem/io.lua +++ b/lem/io.lua @@ -69,6 +69,15 @@ do end end +if not io.Stream.cork then + function io.Stream:cork() + return nil, 'Operation not supported' + end + function io.Stream:uncork() + return nil, 'Operation not supported' + end +end + do local MultiServer = {} MultiServer.__index = MultiServer diff --git a/lem/io/core.c b/lem/io/core.c index 6f7aa8b..b282583 100644 --- a/lem/io/core.c +++ b/lem/io/core.c @@ -322,12 +322,14 @@ luaopen_lem_io_core(lua_State *L) /* mt.write = */ lua_pushcfunction(L, stream_write); lua_setfield(L, -2, "write"); +#ifdef TCP_CORK /* mt.cork = */ lua_pushcfunction(L, stream_cork); lua_setfield(L, -2, "cork"); /* mt.uncork = */ lua_pushcfunction(L, stream_uncork); lua_setfield(L, -2, "uncork"); +#endif /* mt.getpeer = */ lua_pushcfunction(L, stream_getpeer); lua_setfield(L, -2, "getpeer"); diff --git a/lem/io/stream.c b/lem/io/stream.c index b2b8f00..07aa5d2 100644 --- a/lem/io/stream.c +++ b/lem/io/stream.c @@ -290,10 +290,7 @@ stream_write(lua_State *T) return lua_yield(T, top); } -#ifndef TCP_CORK -#define TCP_CORK TCP_NOPUSH -#endif - +#ifdef TCP_CORK static int stream_setcork(lua_State *T, int state) { @@ -324,6 +321,7 @@ stream_uncork(lua_State *T) { return stream_setcork(T, 0); } +#endif static int stream_getpeer(lua_State *T) -- cgit v1.2.1