diff --git a/src/bin/tinn.exe b/src/bin/tinn.exe index 36e30e0..94b0455 100644 Binary files a/src/bin/tinn.exe and b/src/bin/tinn.exe differ diff --git a/src/computicle/IOCPSocket.lua b/src/computicle/IOCPSocket.lua index 7a1b4ae..6f73118 100644 --- a/src/computicle/IOCPSocket.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);