diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-06-17 04:04:55 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-06-17 04:04:55 +0000 |
commit | 4d455c6206747ca65b14d65f75d34e16450d352b (patch) | |
tree | 4607fc690526e4d227e5c5148025ffa9ba879843 /src/socket.lua | |
parent | 65c35845c54c7f84b1cf5b0e3d4c7bbdaf1014e3 (diff) | |
download | luasocket-4d455c6206747ca65b14d65f75d34e16450d352b.tar.gz luasocket-4d455c6206747ca65b14d65f75d34e16450d352b.tar.bz2 luasocket-4d455c6206747ca65b14d65f75d34e16450d352b.zip |
Using core.so instead of csocket.so and cmime.so.
Diffstat (limited to 'src/socket.lua')
-rw-r--r-- | src/socket.lua | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/socket.lua b/src/socket.lua index d1c7846..13b474d 100644 --- a/src/socket.lua +++ b/src/socket.lua | |||
@@ -10,13 +10,13 @@ | |||
10 | local base = _G | 10 | local base = _G |
11 | local string = require("string") | 11 | local string = require("string") |
12 | local math = require("math") | 12 | local math = require("math") |
13 | local socket = require("csocket") | 13 | local socket = require("socket.core") |
14 | module("socket") | 14 | module("socket") |
15 | 15 | ||
16 | ----------------------------------------------------------------------------- | 16 | ----------------------------------------------------------------------------- |
17 | -- Auxiliar functions | 17 | -- Exported auxiliar functions |
18 | ----------------------------------------------------------------------------- | 18 | ----------------------------------------------------------------------------- |
19 | function socket.connect(address, port, laddress, lport) | 19 | function connect(address, port, laddress, lport) |
20 | local sock, err = socket.tcp() | 20 | local sock, err = socket.tcp() |
21 | if not sock then return nil, err end | 21 | if not sock then return nil, err end |
22 | if laddress then | 22 | if laddress then |
@@ -28,7 +28,7 @@ function socket.connect(address, port, laddress, lport) | |||
28 | return sock | 28 | return sock |
29 | end | 29 | end |
30 | 30 | ||
31 | function socket.bind(host, port, backlog) | 31 | function bind(host, port, backlog) |
32 | local sock, err = socket.tcp() | 32 | local sock, err = socket.tcp() |
33 | if not sock then return nil, err end | 33 | if not sock then return nil, err end |
34 | sock:setoption("reuseaddr", true) | 34 | sock:setoption("reuseaddr", true) |
@@ -39,9 +39,9 @@ function socket.bind(host, port, backlog) | |||
39 | return sock | 39 | return sock |
40 | end | 40 | end |
41 | 41 | ||
42 | socket.try = socket.newtry() | 42 | try = newtry() |
43 | 43 | ||
44 | function socket.choose(table) | 44 | function choose(table) |
45 | return function(name, opt1, opt2) | 45 | return function(name, opt1, opt2) |
46 | if base.type(name) ~= "string" then | 46 | if base.type(name) ~= "string" then |
47 | name, opt1, opt2 = "default", name, opt1 | 47 | name, opt1, opt2 = "default", name, opt1 |
@@ -56,12 +56,12 @@ end | |||
56 | -- Socket sources and sinks, conforming to LTN12 | 56 | -- Socket sources and sinks, conforming to LTN12 |
57 | ----------------------------------------------------------------------------- | 57 | ----------------------------------------------------------------------------- |
58 | -- create namespaces inside LuaSocket namespace | 58 | -- create namespaces inside LuaSocket namespace |
59 | socket.sourcet = {} | 59 | sourcet = {} |
60 | socket.sinkt = {} | 60 | sinkt = {} |
61 | 61 | ||
62 | socket.BLOCKSIZE = 2048 | 62 | BLOCKSIZE = 2048 |
63 | 63 | ||
64 | socket.sinkt["close-when-done"] = function(sock) | 64 | sinkt["close-when-done"] = function(sock) |
65 | return base.setmetatable({ | 65 | return base.setmetatable({ |
66 | getfd = function() return sock:getfd() end, | 66 | getfd = function() return sock:getfd() end, |
67 | dirty = function() return sock:dirty() end | 67 | dirty = function() return sock:dirty() end |
@@ -75,7 +75,7 @@ socket.sinkt["close-when-done"] = function(sock) | |||
75 | }) | 75 | }) |
76 | end | 76 | end |
77 | 77 | ||
78 | socket.sinkt["keep-open"] = function(sock) | 78 | sinkt["keep-open"] = function(sock) |
79 | return base.setmetatable({ | 79 | return base.setmetatable({ |
80 | getfd = function() return sock:getfd() end, | 80 | getfd = function() return sock:getfd() end, |
81 | dirty = function() return sock:dirty() end | 81 | dirty = function() return sock:dirty() end |
@@ -87,11 +87,11 @@ socket.sinkt["keep-open"] = function(sock) | |||
87 | }) | 87 | }) |
88 | end | 88 | end |
89 | 89 | ||
90 | socket.sinkt["default"] = socket.sinkt["keep-open"] | 90 | sinkt["default"] = sinkt["keep-open"] |
91 | 91 | ||
92 | socket.sink = socket.choose(socket.sinkt) | 92 | sink = choose(sinkt) |
93 | 93 | ||
94 | socket.sourcet["by-length"] = function(sock, length) | 94 | sourcet["by-length"] = function(sock, length) |
95 | return base.setmetatable({ | 95 | return base.setmetatable({ |
96 | getfd = function() return sock:getfd() end, | 96 | getfd = function() return sock:getfd() end, |
97 | dirty = function() return sock:dirty() end | 97 | dirty = function() return sock:dirty() end |
@@ -107,7 +107,7 @@ socket.sourcet["by-length"] = function(sock, length) | |||
107 | }) | 107 | }) |
108 | end | 108 | end |
109 | 109 | ||
110 | socket.sourcet["until-closed"] = function(sock) | 110 | sourcet["until-closed"] = function(sock) |
111 | local done | 111 | local done |
112 | return base.setmetatable({ | 112 | return base.setmetatable({ |
113 | getfd = function() return sock:getfd() end, | 113 | getfd = function() return sock:getfd() end, |
@@ -127,8 +127,9 @@ socket.sourcet["until-closed"] = function(sock) | |||
127 | end | 127 | end |
128 | 128 | ||
129 | 129 | ||
130 | socket.sourcet["default"] = socket.sourcet["until-closed"] | 130 | sourcet["default"] = sourcet["until-closed"] |
131 | 131 | ||
132 | socket.source = socket.choose(socket.sourcet) | 132 | source = choose(sourcet) |
133 | 133 | ||
134 | --getmetatable(_M).__index = nil | 134 | -- clear globals from namespace |
135 | getmetatable(_M).__index = nil | ||