3 * Copyright (c) 2007 - 2011, Blue Static <http://www.bluestatic.org>
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17 #import <CoreFoundation/CoreFoundation.h>
19 @
class NetworkConnection
;
21 // This class is used for the CFNetwork callbacks. It is a private class and
22 // the instance is owned by the NewtorkConnection instance. This class can be
23 // considered an extension of NetworkConnection.
24 class NetworkCallbackController
27 // This object should be constructed on the thread which the streams are
28 // to be scheduled on. It will hold a weak reference to the run loop on that
30 NetworkCallbackController(NetworkConnection
* connection
);
32 // These static methods forward an invocation to the instance methods. The
33 // last void pointer, named |self|, is the instance of this class.
34 static void SocketAcceptCallback(CFSocketRef socket
,
35 CFSocketCallBackType callbackType
,
39 static void ReadStreamCallback(CFReadStreamRef stream
,
40 CFStreamEventType eventType
,
42 static void WriteStreamCallback(CFWriteStreamRef stream
,
43 CFStreamEventType eventType
,
47 void OnSocketAccept(CFSocketRef socket
,
50 void OnReadStreamEvent(CFReadStreamRef stream
, CFStreamEventType eventType
);
51 void OnWriteStreamEvent(CFWriteStreamRef stream
, CFStreamEventType eventType
);
53 // Removes the read or write stream from the run loop, closes the stream,
54 // releases the reference.
55 void UnscheduleReadStream();
56 void UnscheduleWriteStream();
58 // Messages the NetworkConnection's delegate and takes ownership of |error|.
59 void ReportError(CFErrorRef error
);
61 NetworkConnection
* connection_
; // Weak, owns this.
62 CFRunLoopRef runLoop_
; // Weak.