diff options
author | Emil Renner Berthing <esmil@mailme.dk> | 2012-12-11 15:43:45 +0100 |
---|---|---|
committer | Emil Renner Berthing <esmil@mailme.dk> | 2012-12-17 10:11:06 +0100 |
commit | cd9662eee3d728512527f794f1c7f576bd84b2fd (patch) | |
tree | 9ac14333f0da4fed17303b1b619b681f26a0429a | |
parent | bce5e3beab432a359a3d27b9caaf02160e3fb2cc (diff) | |
download | lem-cd9662eee3d728512527f794f1c7f576bd84b2fd.tar.gz lem-cd9662eee3d728512527f794f1c7f576bd84b2fd.tar.xz lem-cd9662eee3d728512527f794f1c7f576bd84b2fd.zip |
rename lem.streams to lem.io
-rw-r--r-- | Makefile.in | 6 | ||||
-rwxr-xr-x | bin/lem-repl | 8 | ||||
-rwxr-xr-x | configure | 2 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | include/lem-io.h (renamed from include/streams.h) | 4 | ||||
-rw-r--r-- | lem/hathaway.lua | 6 | ||||
-rw-r--r-- | lem/http.lua | 20 | ||||
-rw-r--r-- | lem/http/core.c | 2 | ||||
-rw-r--r-- | lem/io.lua (renamed from lem/streams.lua) | 20 | ||||
-rw-r--r-- | lem/io/core.c (renamed from lem/streams/core.c) | 4 | ||||
-rw-r--r-- | lem/io/file.c (renamed from lem/streams/file.c) | 0 | ||||
-rw-r--r-- | lem/io/parsers.c (renamed from lem/streams/parsers.c) | 0 | ||||
-rw-r--r-- | lem/io/queue.lua (renamed from lem/streams/queue.lua) | 10 | ||||
-rw-r--r-- | lem/io/sendfile.c (renamed from lem/streams/sendfile.c) | 0 | ||||
-rw-r--r-- | lem/io/server.c (renamed from lem/streams/server.c) | 0 | ||||
-rw-r--r-- | lem/io/stream.c (renamed from lem/streams/stream.c) | 0 | ||||
-rw-r--r-- | lem/io/tcp.c (renamed from lem/streams/tcp.c) | 0 | ||||
-rwxr-xr-x | test/ctest.lua | 6 | ||||
-rwxr-xr-x | test/fread.lua | 20 | ||||
-rwxr-xr-x | test/fwrite.lua | 20 | ||||
-rwxr-xr-x | test/httptest.lua | 10 | ||||
-rwxr-xr-x | test/multiplexing.lua | 16 | ||||
-rwxr-xr-x | test/stest.lua | 6 |
23 files changed, 79 insertions, 83 deletions
diff --git a/Makefile.in b/Makefile.in index 2511d57..77b80aa 100644 --- a/Makefile.in +++ b/Makefile.in @@ -25,14 +25,14 @@ headers = @headers@ llibs = \ lem/repl.lua \ - lem/streams.lua \ - lem/streams/queue.lua \ + lem/io.lua \ + lem/io/queue.lua \ lem/http.lua \ lem/hathaway.lua clibs = \ lem/utils.so \ - lem/streams/core.so \ + lem/io/core.so \ lem/http/core.so ifdef V diff --git a/bin/lem-repl b/bin/lem-repl index 0bd78bf..e42b3a0 100755 --- a/bin/lem-repl +++ b/bin/lem-repl @@ -17,14 +17,14 @@ -- along with LEM. If not, see <http://www.gnu.org/licenses/>. -- -local streams = require 'lem.streams' -local repl = require 'lem.repl' +local io = require 'lem.io' +local repl = require 'lem.repl' -streams.stdout:write([[ +io.stdout:write([[ A Lua Event Machine 0.3 Copyright 2011-2012 Emil Renner Berthing ]]) -local _, err = repl.repl('stdin', streams.stdin, streams.stdout) +local _, err = repl.repl('stdin', io.stdin, io.stdout) print(err or '') -- vim: syntax=lua ts=2 sw=2 noet: @@ -2158,7 +2158,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_config_headers="$ac_config_headers libev/ev-config.h:ev-config.h.in" -headers='lem.h streams.h' +headers='lem.h lem-io.h' objects='bin/lem.o' diff --git a/configure.ac b/configure.ac index f78c395..a7fbe28 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ builtin_lua_version='5.2' AC_LANG(C) AC_CONFIG_HEADERS([libev/ev-config.h:ev-config.h.in]) -AC_SUBST([headers], ['lem.h streams.h']) +AC_SUBST([headers], ['lem.h lem-io.h']) AC_SUBST([objects], ['bin/lem.o']) AC_SUBST([SHARED], ['-shared']) diff --git a/include/streams.h b/include/lem-io.h index 9fcf6c6..2d2bc6e 100644 --- a/include/streams.h +++ b/include/lem-io.h @@ -16,8 +16,8 @@ * along with LEM. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _LEM_STREAMS_H -#define _LEM_STREAMS_H +#ifndef _LEM_IO_H +#define _LEM_IO_H #include <lem.h> diff --git a/lem/hathaway.lua b/lem/hathaway.lua index 2497232..bdc4535 100644 --- a/lem/hathaway.lua +++ b/lem/hathaway.lua @@ -26,7 +26,7 @@ local format = string.format local concat = table.concat local remove = table.remove -local streams = require 'lem.streams' +local io = require 'lem.io' require 'lem.http' local M = {} @@ -269,7 +269,7 @@ do local headers = res.headers local file, close = res.file, false if type(file) == 'string' then - file, err = streams.sendfile(file) + file, err = io.sendfile(file) if file then close = true else @@ -350,7 +350,7 @@ do end function M.Hathaway(address, port) - local server, err = streams.tcp4_listen(address, port) + local server, err = io.tcp4_listen(address, port) if not server then M.debug(err) return nil, err end M.server = server diff --git a/lem/http.lua b/lem/http.lua index 15f4125..6dd25b9 100644 --- a/lem/http.lua +++ b/lem/http.lua @@ -16,18 +16,18 @@ -- along with LEM. If not, see <http://www.gnu.org/licenses/>. -- -local streams = require 'lem.streams' -local M = require 'lem.http.core' +local io = require 'lem.io' +local http = require 'lem.http.core' -streams.parsers['HTTPRequest'] = M.HTTPRequest -M.HTTPRequest = nil -streams.parsers['HTTPResponse'] = M.HTTPResponse -M.HTTPResponse = nil +io.parsers['HTTPRequest'] = http.HTTPRequest +http.HTTPRequest = nil +io.parsers['HTTPResponse'] = http.HTTPResponse +http.HTTPResponse = nil local tonumber = tonumber local concat = table.concat -function M.Request:body() +function http.Request:body() local len, body = self.headers['Content-Length'], '' if not len then return body end @@ -46,7 +46,7 @@ function M.Request:body() return body end -function M.Response:body_chunked() +function http.Response:body_chunked() local istream = self.istream local t, n = {}, 0 local line, err @@ -74,7 +74,7 @@ function M.Response:body_chunked() return t end -function M.Response:body() +function http.Response:body() if self.headers['Transfer-Encoding'] == 'chunked' then return concat(self:body_chunked()) end @@ -88,6 +88,6 @@ function M.Response:body() return self.istream:read(num) end -return M +return http -- vim: ts=2 sw=2 noet: diff --git a/lem/http/core.c b/lem/http/core.c index ed1dce0..3c2d6b3 100644 --- a/lem/http/core.c +++ b/lem/http/core.c @@ -16,7 +16,7 @@ * along with LEM. If not, see <http://www.gnu.org/licenses/>. */ -#include <streams.h> +#include <lem-io.h> #if !(LUA_VERSION_NUM >= 502) #define lua_getuservalue lua_getfenv diff --git a/lem/streams.lua b/lem/io.lua index 51d9e4f..273a8ad 100644 --- a/lem/streams.lua +++ b/lem/io.lua @@ -16,17 +16,17 @@ -- along with LEM. If not, see <http://www.gnu.org/licenses/>. -- -local M = require 'lem.streams.core' +local io = require 'lem.io.core' do local type = type - local parsers = M.parsers + local parsers = io.parsers local parser_available = parsers.available parsers.available = nil local parser_target = parsers.target parsers.target = nil - function M.reader(readp) + function io.reader(readp) return function(self, fmt, ...) if fmt == nil then return readp(self, parser_available) @@ -42,10 +42,18 @@ do end end - M.IStream.read = M.reader(M.IStream.readp) - M.File.read = M.reader(M.File.readp) + io.IStream.read = io.reader(io.IStream.readp) + io.File.read = io.reader(io.File.readp) end -return M +do + local _write, stdout = io.OStream.write, io.stdout + + function io.write(str) + return _write(stdout, str) + end +end + +return io -- vim: ts=2 sw=2 noet: diff --git a/lem/streams/core.c b/lem/io/core.c index da1d62b..a37a6ee 100644 --- a/lem/streams/core.c +++ b/lem/io/core.c @@ -35,7 +35,7 @@ #include <sys/sendfile.h> #endif -#include <streams.h> +#include <lem-io.h> #include "sendfile.c" #include "file.c" @@ -81,7 +81,7 @@ module_index(lua_State *T) } int -luaopen_lem_streams_core(lua_State *L) +luaopen_lem_io_core(lua_State *L) { /* create module table */ lua_newtable(L); diff --git a/lem/streams/file.c b/lem/io/file.c index 4fde951..4fde951 100644 --- a/lem/streams/file.c +++ b/lem/io/file.c diff --git a/lem/streams/parsers.c b/lem/io/parsers.c index 72cd671..72cd671 100644 --- a/lem/streams/parsers.c +++ b/lem/io/parsers.c diff --git a/lem/streams/queue.lua b/lem/io/queue.lua index 7672798..63bda6d 100644 --- a/lem/streams/queue.lua +++ b/lem/io/queue.lua @@ -1,19 +1,19 @@ -- --- This file is part of lem-streams. --- Copyright 2011 Emil Renner Berthing +-- This file is part of LEM, a Lua Event Machine. +-- Copyright 2011-2012 Emil Renner Berthing -- --- lem-streams is free software: you can redistribute it and/or +-- LEM is free software: you can redistribute it and/or -- modify it under the terms of the GNU General Public License as -- published by the Free Software Foundation, either version 3 of -- the License, or (at your option) any later version. -- --- lem-streams is distributed in the hope that it will be useful, +-- LEM is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License --- along with lem-streams. If not, see <http://www.gnu.org/licenses/>. +-- along with LEM. If not, see <http://www.gnu.org/licenses/>. -- local utils = require 'lem.utils' diff --git a/lem/streams/sendfile.c b/lem/io/sendfile.c index c3395e3..c3395e3 100644 --- a/lem/streams/sendfile.c +++ b/lem/io/sendfile.c diff --git a/lem/streams/server.c b/lem/io/server.c index c2c03cf..c2c03cf 100644 --- a/lem/streams/server.c +++ b/lem/io/server.c diff --git a/lem/streams/stream.c b/lem/io/stream.c index f499f1e..f499f1e 100644 --- a/lem/streams/stream.c +++ b/lem/io/stream.c diff --git a/lem/streams/tcp.c b/lem/io/tcp.c index fd13760..fd13760 100644 --- a/lem/streams/tcp.c +++ b/lem/io/tcp.c diff --git a/test/ctest.lua b/test/ctest.lua index c62a57a..e33b372 100755 --- a/test/ctest.lua +++ b/test/ctest.lua @@ -19,10 +19,10 @@ print('Entered ' .. arg[0]) -local utils = require 'lem.utils' -local streams = require 'lem.streams' +local utils = require 'lem.utils' +local io = require 'lem.io' -local iconn, oconn = assert(streams.tcp_connect('127.0.0.1', arg[1] or 8080)) +local iconn, oconn = assert(io.tcp_connect('127.0.0.1', arg[1] or 8080)) for i = 1, 10 do assert(oconn:write('ping\n')) diff --git a/test/fread.lua b/test/fread.lua index 56309d8..8267bdd 100755 --- a/test/fread.lua +++ b/test/fread.lua @@ -17,25 +17,19 @@ -- along with LEM. If not, see <http://www.gnu.org/licenses/>. -- -local utils = require 'lem.utils' -local stream = require 'lem.streams' +local utils = require 'lem.utils' +local io = require 'lem.io' -local write -do - local stdout = stream.stdout - function write(str) - return stdout:write(str) - end -end +local write = io.write print("Press enter to read '" .. (arg[1] or arg[0]) .. "'") -stream.stdin:read() +io.stdin:read() local threads = 2 for i = 1, threads do utils.spawn(function() - local file = assert(stream.open(arg[1] or arg[0])) - assert(getmetatable(file) == stream.File, "Hmm...") + local file = assert(io.open(arg[1] or arg[0])) + assert(getmetatable(file) == io.File, "Hmm...") ---[[ local chunk, err @@ -67,6 +61,6 @@ while threads > 0 do end print "\nDone. Press enter to continue." -stream.stdin:read() +io.stdin:read() -- vim: set ts=2 sw=2 noet: diff --git a/test/fwrite.lua b/test/fwrite.lua index f4e8856..d76485f 100755 --- a/test/fwrite.lua +++ b/test/fwrite.lua @@ -17,25 +17,19 @@ -- along with LEM. If not, see <http://www.gnu.org/licenses/>. -- -local utils = require 'lem.utils' -local stream = require 'lem.streams' +local utils = require 'lem.utils' +local io = require 'lem.io' -local write -do - local stdout = stream.stdout - function write(str) - return stdout:write(str) - end -end +local write = io.write print("Press enter to read '" .. (arg[1] or arg[0]) .. "'") -stream.stdin:read() +io.stdin:read() local threads = 2 for i = 1, threads do utils.spawn(function(n) - local file = assert(stream.open('file' .. tostring(n) .. '.txt', 'w')) - assert(getmetatable(file) == stream.File, "Hmm...") + local file = assert(io.open('file' .. tostring(n) .. '.txt', 'w')) + assert(getmetatable(file) == io.File, "Hmm...") print(tostring(n) .. '-1') assert(file:write('Hej!\n')) @@ -60,6 +54,6 @@ while threads > 0 do end print "\nDone. Press enter to continue." -stream.stdin:read() +io.stdin:read() -- vim: set ts=2 sw=2 noet: diff --git a/test/httptest.lua b/test/httptest.lua index 7bc3b93..85d21d1 100755 --- a/test/httptest.lua +++ b/test/httptest.lua @@ -17,9 +17,9 @@ -- along with LEM. If not, see <http://www.gnu.org/licenses/>. -- -local utils = require 'lem.utils' -local streams = require 'lem.streams' -local http = require 'lem.http' +local utils = require 'lem.utils' +local io = require 'lem.io' +local http = require 'lem.http' local format = string.format local concat = table.concat @@ -27,8 +27,8 @@ local concat = table.concat local done = false utils.spawn(function() - --local istream, ostream = assert(streams.tcp_connect('www.google.dk', 80)) - local istream, ostream = assert(streams.tcp_connect('127.0.0.1', 8080)) + --local istream, ostream = assert(io.tcp_connect('www.google.dk', 80)) + local istream, ostream = assert(io.tcp_connect('127.0.0.1', 8080)) print('\nConnected.') diff --git a/test/multiplexing.lua b/test/multiplexing.lua index b294767..fc421cb 100755 --- a/test/multiplexing.lua +++ b/test/multiplexing.lua @@ -17,13 +17,13 @@ -- along with LEM. If not, see <http://www.gnu.org/licenses/>. -- -local utils = require 'lem.utils' -local streams = require 'lem.streams' -local queue = require 'lem.streams.queue' +local utils = require 'lem.utils' +local io = require 'lem.io' +local queue = require 'lem.io.queue' local exit = false local ticker = utils.newsleeper() -local stdout = queue.wrap(streams.stdout) +local stdout = queue.wrap(io.stdout) do local format = string.format @@ -51,14 +51,14 @@ end -- type 'mkfifo pipe' to create a named pipe for this script -- and do 'cat > pipe' (in another terminal) to write to it -local pipe = assert(streams.open(arg[1] or 'pipe', 'r')) +local pipe = assert(io.open(arg[1] or 'pipe', 'r')) -- spawn coroutines to read from stdin and the pipe -utils.spawn(poll, streams.stdin, 'stdin') +utils.spawn(poll, io.stdin, 'stdin') utils.spawn(poll, pipe, 'pipe') do - --local out = streams.stderr + --local out = io.stderr local out = stdout local sound @@ -73,7 +73,7 @@ do until exit end -streams.stdin:close() +io.stdin:close() pipe:close() -- vim: syntax=lua ts=2 sw=2 noet: diff --git a/test/stest.lua b/test/stest.lua index ab432d1..b791bc8 100755 --- a/test/stest.lua +++ b/test/stest.lua @@ -19,10 +19,10 @@ print('Entered ' .. arg[0]) -local utils = require 'lem.utils' -local streams = require 'lem.streams' +local utils = require 'lem.utils' +local io = require 'lem.io' -local server = assert(streams.tcp4_listen('*', arg[1] or 8080)) +local server = assert(io.tcp4_listen('*', arg[1] or 8080)) --timer(10, function() exit(0) end) utils.spawn(function() |