]>
git.saurik.com Git - apple/security.git/blob - Network/transfer.cpp
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // transfer - the embodiment of a single transfer transaction
23 #include "netmanager.h"
24 #include "netconnection.h"
34 // Construct and destroy Transfer objects
36 Transfer::Transfer(Protocol
&proto
, const Target
&tgt
, Operation op
, IPPort defPort
)
38 target(tgt
.host
.defaultPort(defPort
), tgt
.path
),
39 mState(cold
), mOperation(op
), mConnection(NULL
),
40 mSource(NULL
), mSink(NULL
),
41 mShareConnections(proto
.manager
.reuseConnections()),
42 mErrorStatus(defaultOSStatusError
)
44 debug("netxfer", "%p created for protocol %p(%s) target %s operation %d",
45 this, &proto
, proto
.name(), target
.urlForm().c_str(), mOperation
);
47 parameters(protocol
.manager
); // inherit environment from manager object
48 mObserver
= protocol
.manager
.observer();
53 debug("netxfer", "transfer %p destroyed", this);
58 // Generic error management.
59 // These defaults do (almost) nothing useful; they should be overridden by
60 // each Protocol's Transfer object.
62 Transfer::ResultClass
Transfer::resultClass() const
66 return unclassifiedFailure
;
74 OSStatus
Transfer::errorStatus() const
76 assert(state() == failed
);
80 string
Transfer::errorDescription() const
82 assert(state() == failed
);
83 return mErrorDescription
;
90 void Transfer::restart()
93 return mConnection
->restart();
98 // Notify any observer
100 void Transfer::observe(Observer::Events events
, const void *info
)
102 if (mObserver
&& mObserver
->wants(events
))
103 mObserver
->observe(events
, this, info
);
108 // Set yourself to be successfully done
110 void Transfer::finish()
112 debug("xferengine", "transfer %p is finishing up", this);
115 mConnection
->undock();
116 protocol
.manager
.done(this);
117 observe(Observer::transferComplete
);
122 // Set yourself to have failed
124 void Transfer::fail()
126 debug("xferengine", "transfer %p is failing", this);
129 mConnection
->undock();
130 protocol
.manager
.done(this);
131 observe(Observer::transferFailed
);
136 // This default implementation of abort() simply fails.
137 // This is not likely to be enough for most protocols.
139 void Transfer::abort()
141 observe(Observer::aborting
);
143 mConnection
->retain(false); // indeterminate state; don't keep it
148 } // end namespace Network
149 } // end namespace Security