diff options
author | Christian Pointner <equinox@helsinki.at> | 2011-03-21 16:09:14 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2011-03-21 16:09:14 (GMT) |
commit | 473634799142c6cc9f7c78778add94958f5293d2 (patch) | |
tree | be9d7906caebf3bd5532d71784f9f65bc013e7b2 /nopsyncd/l_pipe.c | |
parent | 46348e1cd2782a701134b030be7452910ba2c46e (diff) |
nopsyncd first full version
- only timestamps through tcp connection
- info can be fetched from mysql playlog
Diffstat (limited to 'nopsyncd/l_pipe.c')
-rw-r--r-- | nopsyncd/l_pipe.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/nopsyncd/l_pipe.c b/nopsyncd/l_pipe.c index 5a99809..6b769a5 100644 --- a/nopsyncd/l_pipe.c +++ b/nopsyncd/l_pipe.c @@ -43,16 +43,19 @@ void pipe_close() static int l_pipe_signal(lua_State *L) { - char data = 1; - int ret = 0; + size_t len = 0, written = 0; + const char* data = luaL_checklstring(L, 1, &len); + len++; // also send trailing zero + int ret = 0; for(;;) { - ret = write(pipefds_[1], &data, 1); - if(ret == 1) break; - + ret = write(pipefds_[1], &(data[written]), len - written); if(!ret) continue; if(ret == -1 && (errno == EAGAIN || errno == EINTR)) continue; + written += ret; + if(written == len) break; + break; } @@ -93,19 +96,30 @@ static int l_pipe_getreadfd(lua_State *L) static int l_pipe_consume(lua_State *L) { - char data; - int ret = 0; + char data[17]; // 17 should be sufficient + size_t len = 0; + int ret = 0; for(;;) { - ret = read(pipefds_[0], &data, 1); - if(ret == 1 || ret == 0) break; - + ret = read(pipefds_[0], &(data[len]), 1); + if(ret == 0) break; if(ret == -1 && (errno == EAGAIN || errno == EINTR)) continue; - break; + if(data[len] == 0) + break; + + len += ret; + if(len >= sizeof(data)) { + ret = 0; + break; + } } - lua_pushinteger(L, ret); + if(ret) + lua_pushstring(L, data); + else + lua_pushnil(L); + return 1; } |