diff options
Diffstat (limited to 'src/l_tcp.c')
-rw-r--r-- | src/l_tcp.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/l_tcp.c b/src/l_tcp.c index c00921e..9418ea5 100644 --- a/src/l_tcp.c +++ b/src/l_tcp.c @@ -1,15 +1,15 @@ /* * gcsd * - * gcsd the generic command sequencer daemon can be used to serialize + * gcsd the generic command sequencer daemon can be used to serialize * commands sent over various paralell communication channels to a * single command output. It can be seen as a multiplexer for any * kind of communication between a single resource and various clients * which want to submit commands to it or query information from it. - * gcsd is written in C and Lua. The goal is to provide an easy to + * gcsd is written in C and Lua. The goal is to provide an easy to * understand high level API based on Lua which can be used to * implement the business logic of the so formed multiplexer daemon. - * + * * * Copyright (C) 2009-2010 Markus Grueneis <gimpf@spreadspace.org> * Christian Pointner <equinox@spreadspace.org> @@ -70,7 +70,7 @@ static char* tcp_endpoint_to_string(tcp_endpoint_t* e) size_t addrstr_len = 0; char addrstr[INET6_ADDRSTRLEN + 1], portstr[6], *ret; char addrport_sep = ':'; - + switch(e->addr_.ss_family) { case AF_INET: addrport_sep = ':'; break; @@ -152,7 +152,7 @@ static int l_tcp_server(lua_State *L) if(!strcmp(addr, "*") || !strlen(addr)) addr = NULL; const char* port = luaL_checkstring(L, 2); int af = luaL_optint(L, 3, 0); - + struct addrinfo *res = tcp_resolve_endpoint(addr, port, af, 1); if(!res) { lua_pushnil(L); @@ -299,11 +299,11 @@ static int l_tcp_client(lua_State *L) memcpy(se, &source, sizeof(tcp_endpoint_t)); lua_settable(L, -3); } - + lua_pushliteral(L, "fd"); lua_pushinteger(L, fd); lua_settable(L, -3); - + if(connect(fd, (struct sockaddr *)&(remote.addr_), remote.len_)==-1) { if(errno == EINPROGRESS) { lua_pushboolean(L, 0); @@ -316,7 +316,7 @@ static int l_tcp_client(lua_State *L) lua_pushstring(L, "connect() failed"); return 2; } - + lua_pushboolean(L, 1); return 2; } @@ -353,9 +353,9 @@ static int l_tcp_recv(lua_State *L) lua_pushstring(L, "bad alloc"); return 2; } - + int ret = recv(fd, data, len, 0); - + if(ret == -1) { lua_pushnil(L); // FIXXXXXME: strerror is not threadsafe!!! @@ -373,9 +373,9 @@ static int l_tcp_send(lua_State *L) int fd = luaL_checkint(L,1); size_t len = 0; const char* data = luaL_checklstring(L, 2, &len); - + int ret = send(fd, data, len, 0); - + if(ret == -1) { lua_pushnil(L); // FIXXXXXME: strerror is not threadsafe!!! @@ -409,7 +409,7 @@ static const struct luaL_reg tcp_funcs [] = { { NULL, NULL } }; -LUALIB_API int luaopen_tcp(lua_State *L) +LUALIB_API int luaopen_tcp(lua_State *L) { luaL_register(L, LUA_TCPLIBNAME, tcp_funcs); return 1; |