// Messages the NetworkConnection's delegate and takes ownership of |error|.
void ReportError(CFErrorRef error);
- // The actual socket.
+ // The socket that listens for incoming connections from the engine.
CFSocketRef listeningSocket_; // Strong.
+ // The child socket from the |listeningSocket_| that is connected to the
+ // engine. The streams are attached to this socket.
+ CFSocketNativeHandle socketHandle_;
+
// The read and write streams that are scheduled on the |runLoop_|. Both are
// weak and are owned by the run loop source.
CFReadStreamRef readStream_;
#import "NetworkConnectionPrivate.h"
NetworkCallbackController::NetworkCallbackController(NetworkConnection* connection)
- : readStream_(NULL),
+ : listeningSocket_(NULL),
+ socketHandle_(NULL),
+ readStream_(NULL),
writeStream_(NULL),
connection_(connection),
runLoop_(CFRunLoopGetCurrent())
void NetworkCallbackController::CloseConnection()
{
- CloseSocket();
+ if (socketHandle_) {
+ close(socketHandle_);
+ //socketHandle_ = NULL;
+ }
UnscheduleReadStream();
UnscheduleWriteStream();
}
CFDataRef address,
const void* data)
{
+ socketHandle_ = *(CFSocketNativeHandle*)data;
+
// Create the streams on the socket.
CFStreamCreatePairWithSocket(kCFAllocatorDefault,
- *(CFSocketNativeHandle*)data, // Socket handle.
+ socketHandle_, // Socket handle.
&readStream_, // Read stream in-pointer.
&writeStream_); // Write stream in-pointer.
case kCFStreamEventEndEncountered:
UnscheduleReadStream();
+ CloseConnection();
[connection_ socketDisconnected];
break;
};