-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_pgsql2.lua
More file actions
106 lines (92 loc) · 2.37 KB
/
test_pgsql2.lua
File metadata and controls
106 lines (92 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env luajit
-- for debug
local _tostring = require('logging').tostring
local write = function(s) io.stdout:write(s) end
local tprint = function(...)
print(_tostring{...})
end
local PQ = require('everlooping.pgsql')
local cosocket = require('everlooping.tcppool')
local util = require('everlooping.util')
local ioloop = require('everlooping.ioloop')
function request(host, port, data)
print('request thread:', coroutine.running())
local s = cosocket.tcp()
s:settimeout(2000)
local ok, err = s:connect(host, port)
if not ok then
print(err)
return
end
s:send(data)
while true do
local l, err = s:receive('*l')
if l then
print(l)
if l == '</html>' then
break
end
else
print(l, err)
break
end
end
s:setkeepalive(5000)
print('Request complete.')
end
cosocket.register(function()
for i=0, 10 do
print(util.time() .. ': moew~')
cosocket.sleep(0.1)
end
end)
cosocket.register(function()
print('request thread:', coroutine.running())
write('\n')
p = PQ.pgsql()
local ok, err = p:connect('postgres://postgres:@localhost/haddit_dev')
if not ok then
write(err)
end
-- ok, err = p:query("select * from account_entity_2 limit 4")
print('begin copying')
ok, err = p:query("copy account_entity_2 to '/tmp/testdata'")
if not ok then
write(err)
end
print('end copying')
p:setkeepalive(2000)
p:close()
p = PQ.pgsql()
local ok, err = p:connect('postgres://postgres:@localhost/haddit_dev')
if not ok then
write(err)
end
ok, err = p:query("select * from account_entity_2 limit 4")
if not ok then
write(err)
end
print(ok)
p:setkeepalive(2000)
cosocket.sleep(2)
p = PQ.pgsql()
local ok, err = p:connect('postgres://postgres:@localhost/haddit_dev')
if not ok then
write(err)
end
ok, err = p:query("select * from account_entity_2 limit 4")
if not ok then
write(err)
end
print(ok)
p:close()
print('Request complete.')
end)
-- cosocket.register(function()
-- request('baidu.com', 80, 'GET / HTTP/1.1\r\nHost: baidu.com\r\nConnection: keep-alive\r\n\r\n')
-- cosocket.sleep(2)
-- request('baidu.com', 80, 'GET / HTTP/1.1\r\nHost: baidu.com\r\nConnection: keep-alive\r\n\r\n')
-- cosocket.sleep(6)
-- request('baidu.com', 80, 'GET / HTTP/1.1\r\nHost: baidu.com\r\nConnection: keep-alive\r\n\r\n')
-- end)
ioloop.defaultIOLoop():start()