]>
git.saurik.com Git - apple/security.git/blob - Network/netconnection.h
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 // connection - a (potentially) persistent access path to a (possibly :-) remote entity.
22 // Connection objects are the bearers of actual network (or other) I/O. They are distinct
23 // from Transfers, which embody an individual activity for a particular client (and Target).
24 // To do its stuff, a Transfer "docks" with a Connection, uses its resources, then "undocks"
25 // and leaves the Connection free to dock again with another Transfer (or, eventually, expire).
27 // Access protocols that do not have persistent state connections (e.g. FILE) will not use
28 // Connections at all; there is no requirement for a Transfer to use a Connection for its work.
30 // Actual Connection objects are specialized per protocol; for example, you'd expect
31 // an HTTPTransfer to dock to an HTTPConnection. If you subclass an existing protocol,
32 // you *may* be able to get away with using its Connection objects - but more often you'd
33 // subclass them in turn.
35 #ifndef _H_NETCONNECTION
36 #define _H_NETCONNECTION
38 #include <Security/ip++.h>
39 #include <Security/hosts.h>
40 #include <Security/streams.h>
43 #include "parameters.h"
48 using namespace IPPlusPlus
;
61 // A generic Connection represents a semi-persistent channel of access to something
62 // identified by a Target.
64 class Connection
: public ParameterSource
{
65 friend class Transfer
;
67 typedef Protocol::Operation Operation
;
69 Connection(Protocol
&proto
, const HostTarget
&spec
);
70 virtual ~Connection();
73 const HostTarget hostTarget
;
76 virtual void dock(Transfer
*xfer
);
77 virtual void undock();
78 bool isDocked() const { return mTransfer
; }
81 XFer
&transferAs() const { assert(mTransfer
); return *safe_cast
<XFer
*>(mTransfer
); }
84 bool retain() const { return mRetainMe
; }
85 void retain(bool r
) { mRetainMe
= r
; }
87 // see if we're still alive (after perhaps a delay)
88 virtual bool validate();
90 // return our hostTarget or that of the proxy server, if any
91 const HostTarget
&proxyHostTarget() const
92 { return protocol
.isProxy() ? protocol
.proxyHost() : hostTarget
; }
95 Sink
&sink() const { assert(isDocked()); return mTransfer
->sink(); }
96 Source
&source() const { assert(isDocked()); return mTransfer
->source(); }
97 const Target
&target() const { assert(isDocked()); return mTransfer
->target
; }
98 Operation
operation() const { assert(isDocked()); return mTransfer
->operation(); }
100 ParameterSource
*parameters() { assert(mTransfer
); return mTransfer
->parameters(); }
101 bool getParams(Key key
, Value
&value
) const
102 { assert(mTransfer
); return mTransfer
->getParams(key
, value
); }
103 void observe(Observer::Event event
, const void *info
= NULL
) const
104 { if (mTransfer
) mTransfer
->observe(event
, info
); }
106 void setError(const char *s
, OSStatus err
= Transfer::defaultOSStatusError
)
107 { if (mTransfer
) mTransfer
->setError(s
, err
); }
112 virtual void restart();
113 void restarting(bool rs
) { mRestarting
= rs
; }
114 bool restarting() const { return mRestarting
; }
117 Transfer
*mTransfer
; // currently docked transfer (NULL if idle)
118 bool mRetainMe
; // want to be retained in connection pool
119 bool mRestarting
; // restart allowed
124 // A Connection that is also a TransferAgent::Client.
125 // This is a common case (but it isn't always true).
127 class TCPConnection
: public Connection
,
128 public TransferEngine::Client
, public TCPClientSocket
{
130 TCPConnection(Protocol
&proto
, const HostTarget
&spec
)
131 : Connection(proto
, spec
) { }
134 // remove from I/O hooks and close
137 // manage asynchronous connection establishment
138 void connect(const Host
&host
, IPPort port
);
141 int fileDesc() const;
144 std::set
<IPAddress
> mAddressCandidates
;
147 void nextCandidate();
151 } // end namespace Network
152 } // end namespace Security
155 #endif _H_NETCONNECTION