From 604ad35e24a9e7b82bee5bf52aace1673e296130 Mon Sep 17 00:00:00 2001 From: William Adams Date: Tue, 30 Jul 2013 11:43:20 -0700 Subject: [PATCH] modified: src/computicle/IOCPSocket.lua --- src/bin/tinn.exe | Bin 1686528 -> 1686528 bytes src/computicle/IOCPSocket.lua | 10 ++++++++- tests/UdpEchoClient.lua | 24 +++++++++++---------- tests/UdpEchoServer.lua | 38 ++++++++++++---------------------- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/bin/tinn.exe b/src/bin/tinn.exe index 36e30e0970029c94e7637c0a0eeda5a0c82cd348..94b0455c7c1e7e48e339e4238389948cad62d664 100644 GIT binary patch delta 2959 zcmeI!Z%|a%8OQP8y$fL}yUQ-@F5H%;YMF?MNi-n|8it{krWlQ`mQj;XLo6Z$BB;b# zqFF{TrH!%ZW&$Wy#7(4%5m+oFHK{m~IEElEOovJTQHQ2!gUV=INy1>iOxu~h?fcxB z&$-XpnZ5Vy+2=XuR8JIDPZYHnwhiMqLpI}CXGPf3174}J$x>AB8Sui6DF*X*{0$=* z#vsn23vFmYV@uG|PYJ5A6=fJ=WYgE9#0!xIKcaB`kfo3D8=S>dGXv$`f<4%dGCYAt z@gQa)0aHJ>bQK?A5NGg4kfsIuP>V_wVHI-mAZ~{PlLsx0VFW`si!QX{73@SM)?p>G zaSu}9!gU6F8JBPdU6}tmO*3|5J2oO80W3l~?tmXrn26k6m9u2!3Ym7pCP%s{xow8B zOw+u}COu>`Z0;yiSvJ#jN7E;E--Z~QvZJD;GqLMRHWtQhDXCgtUgX|V{)5t|3kx?t zRkAU%ssCJb?B_N`C)qqkZY1md6vNDQg?7I?Cv@n-ve0J(Yh%CQDRBy@sNwJ-GqWLZ z!s}?*bJLp^8TugEh?#F+u7&nxp}!2?6Bj@Imb~&n`R2+R@5LW`FB&jmLlmNM8)9Hb zEWUy`IN*c}@o>X~1SG->AN)w_@m@@B?ljfZ&{b{iT=={F|IVK23|dFVB=40R|MOWb z>6u$Eouichd*w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lua +++ b/src/computicle/IOCPSocket.lua @@ -416,6 +416,14 @@ IOCPSocket.bind = function(self, addr, addrlen) return WinSock.bind(self:getNativeSocket(), addr, addrlen) end +IOCPSocket.bindToPort = function(self, port) + local addr = sockaddr_in(port); + local addrlen = ffi.sizeof(addr); + + return self:bind(addr,addrlen) +end + + --[[ Data Transport --]] @@ -620,7 +628,7 @@ IOCPSocket.receiveFrom = function(self, lpFrom, fromLen, buff, bufflen) local key, bytes, ovl = IOProcessor:yieldForIo(self, SocketOps.READ, lpOverlapped.opcounter); -print("WSARecvFrom: ", key, bytes, ovl); +--print("WSARecvFrom: ", key, bytes, ovl); return bytes; end diff --git a/tests/UdpEchoClient.lua b/tests/UdpEchoClient.lua index 27aad21..3cce58f 100644 --- a/tests/UdpEchoClient.lua +++ b/tests/UdpEchoClient.lua @@ -14,13 +14,13 @@ local serviceport = 9090 local argv = {...} local argc = #argv -local EchoRequest = function(socket, addr, addrlen) +local EchoRequest = function(socket, addr, addrlen, phrase) -- fill the buffer with current time - local datestr = os.date("%c"); + phrase = phrase or os.date("%c"); - local bytessent, err = socket:sendTo(addr, addrlen, datestr, #datestr); + local bytessent, err = socket:sendTo(addr, addrlen, phrase, #phrase); -print("bytessent: ", bytessent, err); +--print("bytessent: ", bytessent, err); if not bytessent then print("sendTo ERROR: ", bytessent, err); @@ -40,8 +40,9 @@ print("bytessent: ", bytessent, err); end if bytesreceived > 0 then - print("RECEIVED: ", bytesreceived); - return ffi.string(buff, bytesreceived); + --print("RECEIVED: ", bytesreceived); + --return ffi.string(buff, bytesreceived); + return true end return string.format("bytesreceived == %d", bytesreceived); @@ -49,10 +50,11 @@ end -loop = function() +loop = function(phrase) local sw = StopWatch(); local iterations = tonumber(argv[1]) or 1; + --print("iterations: ", iterations); @@ -73,19 +75,19 @@ loop = function() local transcount = 0; for i=1,iterations do - local dtc, err = EchoRequest(socket, addr, addrlen); + local dtc, err = EchoRequest(socket, addr, addrlen, phrase); if dtc then transcount = transcount + 1; - print(transcount, dtc, transcount/sw:Seconds()); + --print(transcount, dtc, transcount/sw:Seconds()); else print("Error: ", i, err); end - collectgarbage(); + --collectgarbage(); end print("Transactions: ", transcount, transcount/sw:Seconds()); end -run(loop); +run(loop, "Hello, World!"); diff --git a/tests/UdpEchoServer.lua b/tests/UdpEchoServer.lua index 571bbc0..a56acaa 100644 --- a/tests/UdpEchoServer.lua +++ b/tests/UdpEchoServer.lua @@ -2,32 +2,25 @@ local ffi = require("ffi"); local IOProcessor = require("IOProcessor"); local IOCPSocket = require("IOCPSocket"); -local ws2_32 = require("ws2_32"); ---IOProcessor:setMessageQuanta(5); local serverport = 9090; -local createServerSocket = function(port) - local port = port or serverport; - local socket, err = IOCPSocket:create(AF_INET, SOCK_DGRAM, 0); +-- Setup the server socket +local socket, err = IOCPSocket:create(AF_INET, SOCK_DGRAM, 0); - if not socket then - print("create socket ERROR: ", err); - return nil, err; - end +--if not socket then +-- print("create socket ERROR: ", err); +-- return nil, err; +--end - local addr = sockaddr_in(port); - local addrlen = ffi.sizeof(addr); +local success, err = socket:bindToPort(serverport); - success, err = socket:bind(addr,addrlen) +--if not success then +-- print("bindToPort, ERROR: ", err); +-- return false, err; +--end - if not success then - return false, err; - end - - return socket; -end -- The primary application loop local loop = function() @@ -36,12 +29,7 @@ local loop = function() local from = sockaddr_in(); local fromLen = ffi.sizeof(from); - local socket, err = createServerSocket(serverport); - if not socket then - print("createServerSocket Error: ", err); - return false, err; - end while true do local bytesread, err = socket:receiveFrom(from, fromLen, buff, bufflen); @@ -51,9 +39,9 @@ local loop = function() return false, err; end - print("BYTESREAD: ", bytesread, from); + --print("BYTESREAD: ", bytesread, from); - print(ffi.string(buff, bytesread)); + --print(ffi.string(buff, bytesread)); -- echo back to sender local bytessent, err = socket:sendTo(from, fromLen, buff, bufflen);