176 |
lprint_newline (); |
lprint_newline (); |
177 |
server_send !verbose_msg_clients sock (GetReq { |
server_send !verbose_msg_clients sock (GetReq { |
178 |
Get.name = filename; |
Get.name = filename; |
179 |
Get.pos = Int64.add (file_downloaded file) Int64.one; |
Get.pos = Int64.succ (file_downloaded file); |
180 |
}); |
}); |
181 |
c.client_download <- DcDownload file; |
c.client_download <- DcDownload file; |
182 |
c.client_pos <- (file_downloaded file); |
c.client_pos <- (file_downloaded file); |
247 |
lprintf "Wants to upload [%s]\n" filename; |
lprintf "Wants to upload [%s]\n" filename; |
248 |
let sh = CommonUploads.find_by_name filename in |
let sh = CommonUploads.find_by_name filename in |
249 |
|
|
250 |
c.client_pos <- Int64.sub t.Get.pos Int64.one; |
c.client_pos <- Int64.pred t.Get.pos; |
251 |
lprintf "from pos %Ld\n" c.client_pos; |
lprintf "from pos %Ld\n" c.client_pos; |
252 |
let info = IndexedSharedFiles.get_result sh.shared_info in |
let info = IndexedSharedFiles.get_result sh.shared_info in |
253 |
let rem = Int64.sub info.shared_size c.client_pos in |
let rem = info.shared_size -- c.client_pos in |
254 |
lprintf "remaining %Ld\n" rem; |
lprintf "remaining %Ld\n" rem; |
255 |
server_send !verbose_msg_clients sock (FileLengthReq rem); |
server_send !verbose_msg_clients sock (FileLengthReq rem); |
256 |
c.client_download <- DcUpload sh |
c.client_download <- DcUpload sh |
284 |
lprintf "Sending %d" send_len; lprint_newline (); |
lprintf "Sending %d" send_len; lprint_newline (); |
285 |
TcpBufferedSocket.write sock list pos send_len; |
TcpBufferedSocket.write sock list pos send_len; |
286 |
lprintf "sent"; lprint_newline (); |
lprintf "sent"; lprint_newline (); |
287 |
c.client_pos <- Int64.add c.client_pos (Int64.of_int send_len); |
c.client_pos <- c.client_pos ++ (Int64.of_int send_len); |
288 |
|
|
289 |
if pos + len = slen then begin |
if pos + len = slen then begin |
290 |
(* Normally, the client should close the connection after the download, |
(* Normally, the client should close the connection after the download, |
303 |
let pos = c.client_pos in |
let pos = c.client_pos in |
304 |
if pos < slen then |
if pos < slen then |
305 |
let rlen = |
let rlen = |
306 |
let rem = Int64.sub slen pos in |
let rem = slen -- pos in |
307 |
if rem > Int64.of_int can then can else Int64.to_int rem |
if rem > Int64.of_int can then can else Int64.to_int rem |
308 |
in |
in |
309 |
let upload_buffer = String.create rlen in |
let upload_buffer = String.create rlen in |
310 |
Unix32.read sh.shared_fd pos upload_buffer 0 rlen; |
Unix32.read sh.shared_fd pos upload_buffer 0 rlen; |
311 |
TcpBufferedSocket.write sock upload_buffer 0 rlen; |
TcpBufferedSocket.write sock upload_buffer 0 rlen; |
312 |
c.client_pos <- Int64.add c.client_pos (Int64.of_int rlen); |
c.client_pos <- c.client_pos ++ (Int64.of_int rlen); |
313 |
if c.client_pos = slen then begin |
if c.client_pos = slen then begin |
314 |
(* Normally, the client should close the connection after the download, |
(* Normally, the client should close the connection after the download, |
315 |
but since we don't want a buggy client to keep this connection, just |
but since we don't want a buggy client to keep this connection, just |
359 |
Unix2.really_write fd b.buf b.pos b.len; |
Unix2.really_write fd b.buf b.pos b.len; |
360 |
end; *) |
end; *) |
361 |
(* lprintf "DIFF %d/%d" nread b.len; lprint_newline ();*) |
(* lprintf "DIFF %d/%d" nread b.len; lprint_newline ();*) |
362 |
c.client_pos <- Int64.add c.client_pos (Int64.of_int b.len); |
c.client_pos <- c.client_pos ++ (Int64.of_int b.len); |
363 |
(* |
(* |
364 |
lprintf "NEW SOURCE POS %s" (Int64.to_string c.source_pos); |
lprintf "NEW SOURCE POS %s" (Int64.to_string c.source_pos); |
365 |
lprint_newline (); |
lprint_newline (); |
367 |
buf_used b b.len; |
buf_used b b.len; |
368 |
if c.client_pos > (file_downloaded file) then begin |
if c.client_pos > (file_downloaded file) then begin |
369 |
add_file_downloaded (as_file file.file_file) |
add_file_downloaded (as_file file.file_file) |
370 |
(Int64.sub c.client_pos (file_downloaded file)); |
(c.client_pos -- (file_downloaded file)); |
371 |
end; |
end; |
372 |
if (file_downloaded file) = (file_size file) then begin |
if (file_downloaded file) = (file_size file) then begin |
373 |
close sock Closed_by_user; |
close sock Closed_by_user; |
380 |
let len = b.len in |
let len = b.len in |
381 |
Buffer.add_substring buf b.buf b.pos b.len; |
Buffer.add_substring buf b.buf b.pos b.len; |
382 |
buf_used b b.len; |
buf_used b b.len; |
383 |
c.client_receiving <- Int64.sub c.client_receiving (Int64.of_int len); |
c.client_receiving <- c.client_receiving -- (Int64.of_int len); |
384 |
lprintf "Received %d of List\n" len; |
lprintf "Received %d of List\n" len; |
385 |
close sock Closed_by_user; |
close sock Closed_by_user; |
386 |
if c.client_receiving = Int64.zero then begin |
if c.client_receiving = Int64.zero then begin |