我正在使用以下代码打开将文件发送到 FTP 的流。我需要的是从中取出套接字,以便我可以实现此处发布的第二个代码。
self.networkStream = CFBridgingRelease(
CFWriteStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url)
);
assert(self.networkStream != nil);
if ([usernameText length] != 0) {
success = [self.networkStream setProperty:usernameText forKey:(id)kCFStreamPropertyFTPUserName];
assert(success);
success = [self.networkStream setProperty:passwordText forKey:(id)kCFStreamPropertyFTPPassword];
assert(success);
}
self.networkStream.delegate = self;
[self.networkStream setProperty:(id)kCFBooleanFalse forKey:(id)kCFStreamPropertyFTPAttemptPersistentConnection];
[self.networkStream setProperty:(id)kCFBooleanTrue forKey:(id)kCFStreamPropertyShouldCloseNativeSocket];
[self.networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.networkStream open];
.
CFSocketRef cfsock = [sock getCFSocket];
CFSocketNativeHandle rawsock = CFSocketGetNative(cfsock);
int flag = 1;
int result = setsockopt(rawsock, IPPROTO_TCP, TCP_NODELAY,
(char *)&flag, sizeof(int));
if (result != 0)
NSLog(@\"Could Not Disable Nagle...\");
else
NSLog(@\"Nagle Is Disabled.\");
第二个块需要一个套接字才能执行,我只有一个流并且不知道如何将套接字从流中取出。
谢谢