Roxen.git/
server/
plugins/
protocols/
ftp.pike
Branch:
Tag:
Non-build tags
All tags
No tags
2002-07-04
2002-07-04 11:42:19 by Per Hedbor <ph@opera.com>
b6802c1f6f407b98ec347e502bae519dff2c3cc2 (
62
lines) (+
24
/-
38
)
[
Show
|
Annotate
]
Branch:
Aphoto_2.0_beta3
Now works using the shuffler
Rev: server/plugins/protocols/ftp.pike:2.81
4:
/* * FTP protocol mk 2 *
-
* $Id: ftp.pike,v 2.
80
2002/
04
/
11
12
:
24
:
48
anders
Exp $
+
* $Id: ftp.pike,v 2.
81
2002/
07/
04
11:
42
:
19
per
Exp $
* * Henrik Grubbström <grubba@roxen.com> */
206:
prot = "FTP"; clientprot = "FTP"; real_variables = ([]);
+
variables = FakedVariables( real_variables );
misc = ([]); cookies = ([]); throttle = ([]);
1739:
/* * Data connection handling */
-
static private void send_done_callback(
array(
object
)
args
)
+
static private void send_done_callback(
object
fd, object session,
+
int amount
)
{ DWRITE("FTP: send_done_callback()\n");
-
object fd = args[0];
-
object session = args[1];
-
+
if(fd) { if (fd->set_blocking) {
1756:
curr_pipe = 0; if (session && session->file) {
+
session->file->len = amount;
session->conf->log(session->file, session); session->file = 0; }
1955:
break; }
-
#ifndef
DISABLE_FTP_THROTTLING
-
mapping throttle
=session->
throttle||([])
;
+
object
throttler
=session->
throttler
;
object pipe;
-
if ( conf &&
-
((throttle->doit && conf->query("req_throttle")) ||
-
conf->throttler
-
) ) {
-
// report_debug("ftp: using slowpipe\n");
-
pipe=
((program)"slowpipe")();
-
} else {
-
// report
_
debug
(
"ftp:
using
fastpipe\n"
);
-
pipe=((program)"fastpipe")(); //will use Stdio.sendfile
if
possible
-
throttle->doit=0;
-
}
-
if
(
throttle->doit)
{
-
throttle->rate=max(throttle->rate,
-
conf
->query("req_throttle_min"));
-
pipe->throttle(throttle->rate,
-
(int
)
(throttle->rate*
-
conf->
query("req
_
throttle_depth_mult")),
-
0);
-
}
-
if
(
conf
&& conf->throttler) { //we are sure to be using slowpipe
-
pipe->assign
_
throttler
(
conf->throttler
)
;
-
}
-
#else
-
object
pipe
=((program
)
"fastpipe")()
;
-
#endif
+
pipe
=
roxen.get
_
shuffler
(
fd
);
+
if( conf )
+
conf->
connection
_
add
(
this
_
object
()
,
pipe
);
-
pipe->set_done_callback(send_done_callback
,
(
{
fd, session
}
) );
+
if( throttler || conf->throttler )
+
pipe->set_
throttler( throttler || conf->throttler );
+
+
pipe->set_
done_callback(
+
lambda( Shuffler.Shuffle r, int reason ) {
+
send_done_callback( fd, session
,
r->sent_data(
) );
+
} );
master_session->file = session->file = file; if(stringp(file->data)) {
-
pipe->
write
(file->data);
+
pipe->
add_source
(file->data
,0,strlen(file->data
)
)
;
} if(file->file) {
-
+
int off;
file->file->set_blocking();
-
pipe->
input
(file->file, file->len);
+
catch( off = file->tell() );
+
pipe->
add_source
(
file->file,
max(off,0), (
file->len
||-1
)
)
;
}
-
+
pipe->start();
curr_pipe = pipe;
-
pipe->output(fd);
+
} static private void connected_to_receive(object fd, string data, string args)
2026:
break; }
-
RequestID
session = RequestID2(master_session);
+
object
session = RequestID2(master_session);
session->method = "PUT"; session->my_fd = PutFileWrapper(fd, session, this_object()); session->misc->len = 0x7fffffff;
3124:
{ if (curr_pipe) { catch {
-
destruct(
curr_pipe);
+
curr_pipe
->stop(
);
}; curr_pipe = 0; send(426, ({ "Data transmission terminated." }));