diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-06-30 06:10:02 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-06-30 06:10:02 +0000 |
| commit | 167727be3cefb3f45a26b0b1d96dc94a900a84b4 (patch) | |
| tree | bb07db0d01dbdebe6b25162b25fbeefc2ee19d05 | |
| parent | bd54cd42d4c8a7d6bb9550d8aa0eac243cda63c0 (diff) | |
| download | luasocket-167727be3cefb3f45a26b0b1d96dc94a900a84b4.tar.gz luasocket-167727be3cefb3f45a26b0b1d96dc94a900a84b4.tar.bz2 luasocket-167727be3cefb3f45a26b0b1d96dc94a900a84b4.zip | |
Bug in usocket_recv...
| -rw-r--r-- | makefile.dist | 66 | ||||
| -rw-r--r-- | samples/tinyirc.lua | 42 | ||||
| -rw-r--r-- | src/auxiliar.c | 5 | ||||
| -rw-r--r-- | src/inet.c | 1 |
4 files changed, 62 insertions, 52 deletions
diff --git a/makefile.dist b/makefile.dist index e493305..9cf2757 100644 --- a/makefile.dist +++ b/makefile.dist | |||
| @@ -2,45 +2,49 @@ | |||
| 2 | # Distribution makefile | 2 | # Distribution makefile |
| 3 | #-------------------------------------------------------------------------- | 3 | #-------------------------------------------------------------------------- |
| 4 | 4 | ||
| 5 | DIST = luasocket-1.5-alpha | 5 | DIST = luasocket-2.0-alpha |
| 6 | 6 | ||
| 7 | LUA = \ | 7 | LUA = \ |
| 8 | concat.lua \ | 8 | auxiliar.lua |
| 9 | code.lua \ | 9 | code.lua |
| 10 | url.lua \ | 10 | concat.lua |
| 11 | http.lua \ | 11 | ftp.lua |
| 12 | smtp.lua \ | ||
| 13 | ftp.lua \ | ||
| 14 | select.lua \ | ||
| 15 | luasocket.lua | ||
| 16 | 12 | ||
| 17 | TESTS = \ | 13 | TESTS = \ |
| 18 | testclnt.lua \ | 14 | codetest.lua |
| 19 | testsrvr.lua \ | 15 | concattest.lua |
| 20 | testcmd.lua \ | 16 | ftptest.lua |
| 21 | codetest.lua \ | ||
| 22 | urltest.lua \ | ||
| 23 | concattest.lua \ | ||
| 24 | ftptest.lua \ | ||
| 25 | httptest.lua \ | ||
| 26 | smtptest.lua \ | ||
| 27 | mbox.lua \ | ||
| 28 | udptest.lua | ||
| 29 | 17 | ||
| 30 | EXAMPLES = \ | 18 | EXAMPLES = \ |
| 31 | check-links.lua \ | 19 | check-links.lua |
| 32 | daytimeclnt.lua \ | 20 | daytimeclnt.lua |
| 33 | echoclnt.lua \ | 21 | echoclnt.lua |
| 34 | echosrvr.lua \ | 22 | echosrvr.lua |
| 35 | get.lua \ | 23 | dict.lua |
| 36 | listener.lua \ | ||
| 37 | talker.lua \ | ||
| 38 | tinyirc.lua | ||
| 39 | 24 | ||
| 40 | ETC = \ | 25 | ETC = \ |
| 41 | cl-compat.lua \ | 26 | cl-compat.lua |
| 42 | tftp.lua \ | 27 | |
| 43 | dict.lua | 28 | get.lua |
| 29 | http.lua | ||
| 30 | httptest.lua | ||
| 31 | listener.lua | ||
| 32 | lua.lua | ||
| 33 | luasocket.lua | ||
| 34 | mbox.lua | ||
| 35 | noglobals.lua | ||
| 36 | select.lua | ||
| 37 | smtp.lua | ||
| 38 | smtptest.lua | ||
| 39 | talker.lua | ||
| 40 | testclnt.lua | ||
| 41 | test.lua | ||
| 42 | testsrvr.lua | ||
| 43 | tftp.lua | ||
| 44 | tinyirc.lua | ||
| 45 | udptest.lua | ||
| 46 | url.lua | ||
| 47 | urltest.lua | ||
| 44 | 48 | ||
| 45 | MAIN = \ | 49 | MAIN = \ |
| 46 | auxiliar.c \ | 50 | auxiliar.c \ |
diff --git a/samples/tinyirc.lua b/samples/tinyirc.lua index 0ad00ab..d9cb896 100644 --- a/samples/tinyirc.lua +++ b/samples/tinyirc.lua | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
| 7 | host = host or "*" | 7 | host = host or "*" |
| 8 | port1 = port1 or 8080 | 8 | port1 = port1 or 8080 |
| 9 | port2 = port2 or 8081 | 9 | port2 = port2 or 8181 |
| 10 | if arg then | 10 | if arg then |
| 11 | host = arg[1] or host | 11 | host = arg[1] or host |
| 12 | port1 = arg[2] or port1 | 12 | port1 = arg[2] or port1 |
| @@ -15,11 +15,16 @@ end | |||
| 15 | 15 | ||
| 16 | server1, error = socket.bind(host, port1) | 16 | server1, error = socket.bind(host, port1) |
| 17 | assert(server1, error) | 17 | assert(server1, error) |
| 18 | server1:timeout(1) | 18 | server1:timeout(1) -- make sure we don't block in accept |
| 19 | server2, error = socket.bind(host, port2) | 19 | server2, error = socket.bind(host, port2) |
| 20 | assert(server2, error) | 20 | assert(server2, error) |
| 21 | server2:timeout(1) | 21 | server2:timeout(1) -- make sure we don't block in accept |
| 22 | 22 | ||
| 23 | io.write("Servers bound\n") | ||
| 24 | |||
| 25 | -- simple set implementation | ||
| 26 | -- the select function doesn't care about what is passed to it as long as | ||
| 27 | -- it behaves like a table | ||
| 23 | function newset() | 28 | function newset() |
| 24 | local reverse = {} | 29 | local reverse = {} |
| 25 | local set = {} | 30 | local set = {} |
| @@ -32,46 +37,43 @@ function newset() | |||
| 32 | table.remove(set, reverse[value]) | 37 | table.remove(set, reverse[value]) |
| 33 | reverse[value] = nil | 38 | reverse[value] = nil |
| 34 | end, | 39 | end, |
| 35 | id = function(set, value) | ||
| 36 | return reverse[value] | ||
| 37 | end | ||
| 38 | }}) | 40 | }}) |
| 39 | return set | 41 | return set |
| 40 | end | 42 | end |
| 41 | 43 | ||
| 42 | sockets = newset() | 44 | set = newset() |
| 43 | 45 | ||
| 44 | sockets:insert(server1) | 46 | io.write("Inserting servers in set\n") |
| 45 | sockets:insert(server2) | 47 | set:insert(server1) |
| 48 | set:insert(server2) | ||
| 46 | 49 | ||
| 47 | while 1 do | 50 | while 1 do |
| 48 | local readable, _, error = socket.select(sockets, nil) | 51 | local readable, _, error = socket.select(set, nil) |
| 49 | for _, input in readable do | 52 | for _, input in readable do |
| 50 | -- is it a server socket? | 53 | -- is it a server socket? |
| 51 | local id = sockets:id(input) | ||
| 52 | if input == server1 or input == server2 then | 54 | if input == server1 or input == server2 then |
| 55 | io.write("Waiting for clients\n") | ||
| 53 | local new = input:accept() | 56 | local new = input:accept() |
| 54 | if new then | 57 | if new then |
| 55 | new:timeout(1) | 58 | new:timeout(1) |
| 56 | sockets:insert(new) | 59 | io.write("Inserting client in set\n") |
| 57 | io.write("Server ", id, " got client ", sockets:id(new), "\n") | 60 | set:insert(new) |
| 58 | end | 61 | end |
| 59 | -- it is a client socket | 62 | -- it is a client socket |
| 60 | else | 63 | else |
| 61 | local line, error = input:receive() | 64 | local line, error = input:receive() |
| 62 | if error then | 65 | if error then |
| 63 | input:close() | 66 | input:close() |
| 64 | io.write("Removing client ", id, "\n") | 67 | io.write("Removing client from set\n") |
| 65 | sockets:remove(input) | 68 | set:remove(input) |
| 66 | else | 69 | else |
| 67 | io.write("Broadcasting line '", id, "> ", line, "'.\n") | 70 | io.write("Broadcasting line '", line, "'\n") |
| 68 | __, writable, error = socket.select(nil, sockets, 1) | 71 | __, writable, error = socket.select(nil, set, 1) |
| 69 | if not error then | 72 | if not error then |
| 70 | for ___, output in writable do | 73 | for ___, output in writable do |
| 71 | io.write("Sending to client ", sockets:id(output), "\n") | 74 | output:send(line .. "\n") |
| 72 | output:send(id, "> ", line, "\r\n") | ||
| 73 | end | 75 | end |
| 74 | else io.write("No one ready to listen!!!\n") end | 76 | else io.write("No client ready to receive!!!\n") end |
| 75 | end | 77 | end |
| 76 | end | 78 | end |
| 77 | end | 79 | end |
diff --git a/src/auxiliar.c b/src/auxiliar.c index 8b2fa37..65425c5 100644 --- a/src/auxiliar.c +++ b/src/auxiliar.c | |||
| @@ -25,6 +25,11 @@ void aux_open(lua_State *L) | |||
| 25 | lua_pushnumber(L, 1); | 25 | lua_pushnumber(L, 1); |
| 26 | lua_rawset(L, -3); | 26 | lua_rawset(L, -3); |
| 27 | #endif | 27 | #endif |
| 28 | /* make version string available so scripts */ | ||
| 29 | lua_pushstring(L, "version"); | ||
| 30 | lua_pushstring(L, LUASOCKET_VERSION); | ||
| 31 | lua_rawset(L, -3); | ||
| 32 | /* store namespace as global */ | ||
| 28 | lua_settable(L, LUA_GLOBALSINDEX); | 33 | lua_settable(L, LUA_GLOBALSINDEX); |
| 29 | /* make sure modules know what is our namespace */ | 34 | /* make sure modules know what is our namespace */ |
| 30 | lua_pushstring(L, "LUASOCKET_LIBNAME"); | 35 | lua_pushstring(L, "LUASOCKET_LIBNAME"); |
| @@ -177,7 +177,6 @@ const char *inet_tryconnect(p_sock ps, const char *address, | |||
| 177 | if (!strlen(address) || !inet_aton(address, &remote.sin_addr)) { | 177 | if (!strlen(address) || !inet_aton(address, &remote.sin_addr)) { |
| 178 | struct hostent *hp = gethostbyname(address); | 178 | struct hostent *hp = gethostbyname(address); |
| 179 | struct in_addr **addr; | 179 | struct in_addr **addr; |
| 180 | remote.sin_family = AF_INET; | ||
| 181 | if (!hp) return sock_hoststrerror(); | 180 | if (!hp) return sock_hoststrerror(); |
| 182 | addr = (struct in_addr **) hp->h_addr_list; | 181 | addr = (struct in_addr **) hp->h_addr_list; |
| 183 | memcpy(&remote.sin_addr, *addr, sizeof(struct in_addr)); | 182 | memcpy(&remote.sin_addr, *addr, sizeof(struct in_addr)); |
