]> git.lizzy.rs Git - luairc.git/commitdiff
stop passing file size all over the place... on accept we just keep accepting until...
authorjluehrs2 <jluehrs2@uiuc.edu>
Mon, 3 Sep 2007 00:59:45 +0000 (19:59 -0500)
committerjluehrs2 <jluehrs2@uiuc.edu>
Mon, 3 Sep 2007 00:59:45 +0000 (19:59 -0500)
src/irc.lua
src/irc/dcc.lua

index 2b2bca7a9682085132dd0bfd3bee623e52cf2a8f..ff90c363fc007cf27353cfd76390334b405a31ca 100644 (file)
@@ -502,7 +502,7 @@ function ctcp_handlers.on_dcc(from, to, message)
     local type, argument, address, port, size = base.unpack(misc.split(message, " ", nil, '"', '"'))
     if type == "SEND" then
         if misc.try_call(on_dcc, from, to, argument, address, port, size) then
-            dcc.accept(argument, address, port, size)
+            dcc.accept(argument, address, port)
         end
     elseif type == "CHAT" then
         -- TODO: implement this? do people ever use this?
index 45eb446c81adf5fa9de619d778966e61323a0907..bd06864f958bce3b6c4feeb7e54a9255cef0c42e 100644 (file)
@@ -23,17 +23,13 @@ LAST_PORT = 5000
 
 -- private functions {{{
 -- send_file {{{
--- TODO: no reason to be sending the size parameter all over the place when we
--- only need it in this function. also, should probably seek to the beginning
--- of the file before sending it.
 --
 -- Sends a file to a remote user, after that user has accepted our DCC SEND
 -- invitation
 -- @param sock        Socket to send the file on
 -- @param file        Lua file object corresponding to the file we want to send
--- @param size        Size of the file to send
 -- @param packet_size Size of the packets to send the file in
-local function send_file(sock, file, size, packet_size)
+local function send_file(sock, file, packet_size)
     local bytes = 0
     while true do
         local packet = file:read(packet_size)
@@ -49,7 +45,6 @@ local function send_file(sock, file, size, packet_size)
                 break
             end
         end
-        if bytes >= size then break end
         coroutine.yield(true)
     end
     file:close()
@@ -66,9 +61,8 @@ end
 -- that we can send data on
 -- @param ssock Server socket that the remote user connected to
 -- @param file  Lua file object corresponding to the file we want to send
--- @param size  Size of the file to send
 -- @param packet_size Size of the packets to send the file in
-local function handle_connect(ssock, file, size, packet_size)
+local function handle_connect(ssock, file, packet_size)
     packet_size = packet_size or 1024
     local sock = ssock:accept()
     sock:settimeout(0.1)
@@ -76,7 +70,7 @@ local function handle_connect(ssock, file, size, packet_size)
     irc._unregister_socket(ssock, 'r')
     irc._register_socket(sock, 'w',
                          coroutine.wrap(function(sock)
-                             return send_file(sock, file, size, packet_size)
+                             return send_file(sock, file, packet_size)
                          end))
     return true
 end
@@ -87,9 +81,8 @@ end
 -- Accepts a file from a remote user which has offered it to us.
 -- @param sock        Socket to receive the file on
 -- @param file        Lua file object corresponding to the file we want to save
--- @param size        Size of the file we are receiving
 -- @param packet_size Size of the packets to receive the file in
-local function accept_file(sock, file, size, packet_size)
+local function accept_file(sock, file, packet_size)
     local bytes = 0
     while true do
         local packet, err, partial_packet = sock:receive(packet_size)
@@ -133,7 +126,7 @@ function send(nick, filename, port)
     file:seek("set")
     irc._register_socket(sock, 'r',
                          coroutine.wrap(function(sock)
-                             return handle_connect(sock, file, size)
+                             return handle_connect(sock, file)
                          end))
     filename = misc.basename(filename)
     if filename:find(" ") then filename = '"' .. filename .. '"' end
@@ -150,9 +143,8 @@ end
 -- @param filename    Name to save the file as
 -- @param address     IP address of the remote user
 -- @param port        Port to connect to at the remote user
--- @param size        Size of the file that the remote user is offering
 -- @param packet_size Size of the packets the remote user will be sending
-function accept(filename, address, port, size, packet_size)
+function accept(filename, address, port, packet_size)
     packet_size = packet_size or 1024
     local sock = base.assert(socket.tcp())
     base.assert(sock:connect(misc.ip_int_to_str(address), port))
@@ -160,7 +152,7 @@ function accept(filename, address, port, size, packet_size)
     local file = base.assert(io.open(misc.get_unique_filename(filename), "w"))
     irc._register_socket(sock, 'r',
                          coroutine.wrap(function(sock)
-                             return accept_file(sock, file, size, packet_size)
+                             return accept_file(sock, file, packet_size)
                          end))
 end
 -- }}}