aboutsummaryrefslogtreecommitdiff
path: root/src/socket.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2005-06-17 04:04:55 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2005-06-17 04:04:55 +0000
commit4d455c6206747ca65b14d65f75d34e16450d352b (patch)
tree4607fc690526e4d227e5c5148025ffa9ba879843 /src/socket.lua
parent65c35845c54c7f84b1cf5b0e3d4c7bbdaf1014e3 (diff)
downloadluasocket-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.lua37
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 @@
10local base = _G 10local base = _G
11local string = require("string") 11local string = require("string")
12local math = require("math") 12local math = require("math")
13local socket = require("csocket") 13local socket = require("socket.core")
14module("socket") 14module("socket")
15 15
16----------------------------------------------------------------------------- 16-----------------------------------------------------------------------------
17-- Auxiliar functions 17-- Exported auxiliar functions
18----------------------------------------------------------------------------- 18-----------------------------------------------------------------------------
19function socket.connect(address, port, laddress, lport) 19function 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
29end 29end
30 30
31function socket.bind(host, port, backlog) 31function 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
40end 40end
41 41
42socket.try = socket.newtry() 42try = newtry()
43 43
44function socket.choose(table) 44function 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
59socket.sourcet = {} 59sourcet = {}
60socket.sinkt = {} 60sinkt = {}
61 61
62socket.BLOCKSIZE = 2048 62BLOCKSIZE = 2048
63 63
64socket.sinkt["close-when-done"] = function(sock) 64sinkt["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 })
76end 76end
77 77
78socket.sinkt["keep-open"] = function(sock) 78sinkt["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 })
88end 88end
89 89
90socket.sinkt["default"] = socket.sinkt["keep-open"] 90sinkt["default"] = sinkt["keep-open"]
91 91
92socket.sink = socket.choose(socket.sinkt) 92sink = choose(sinkt)
93 93
94socket.sourcet["by-length"] = function(sock, length) 94sourcet["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 })
108end 108end
109 109
110socket.sourcet["until-closed"] = function(sock) 110sourcet["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)
127end 127end
128 128
129 129
130socket.sourcet["default"] = socket.sourcet["until-closed"] 130sourcet["default"] = sourcet["until-closed"]
131 131
132socket.source = socket.choose(socket.sourcet) 132source = choose(sourcet)
133 133
134--getmetatable(_M).__index = nil 134-- clear globals from namespace
135getmetatable(_M).__index = nil