objective c - get socket from Stream -
i using following code open stream sends files ftp. need socket out of can implement second code posted here.
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 disabled.\");
second block requires socket in order executed , have stream , dont know how socket out of stream.
thanks
call cfwritestreamcopyproperty()
on write stream , specify kcfstreampropertysocketnativehandle
cfdataref containing underlying cfsocketnativehandle. can extract socket cfdatagetbytes()
.
cfsocketnativehandle rawsock; cfdataref socketdata = cfwritestreamcopyproperty((__bridge cfwritestreamref)(self.networkstream), kcfstreampropertysocketnativehandle); cfdatagetbytes(socketdata, cfrangemake(0, sizeof(cfsocketnativehandle)), (uint8 *)&rawsock); cfrelease(socketdata); /* make use of rawsock */
Comments
Post a Comment