本文整理匯總了C++中CFReadStreamOpen函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFReadStreamOpen函數的具體用法?C++ CFReadStreamOpen怎麽用?C++ CFReadStreamOpen使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFReadStreamOpen函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: CFRelease
bool HTTP_Stream::open(const HTTP_Stream_Position& position)
{
bool success = false;
CFStreamClientContext CTX = { 0, this, NULL, NULL, NULL };
/* Already opened a read stream, return */
if (m_readStream) {
goto out;
}
/* Reset state */
m_position = position;
m_readPending = false;
m_httpHeadersParsed = false;
m_contentType = "";
m_icyStream = false;
m_icyHeaderCR = false;
m_icyHeadersRead = false;
m_icyHeadersParsed = false;
m_icyHeaderLines.clear();
m_icyMetaDataInterval = 0;
m_dataByteReadCount = 0;
m_metaDataBytesRemaining = 0;
if (!m_url) {
goto out;
}
/* Failed to create a stream */
if (!(m_readStream = createReadStream(m_url))) {
goto out;
}
if (!CFReadStreamSetClient(m_readStream, kCFStreamEventHasBytesAvailable |
kCFStreamEventEndEncountered |
kCFStreamEventErrorOccurred, readCallBack, &CTX)) {
CFRelease(m_readStream), m_readStream = 0;
goto out;
}
setScheduledInRunLoop(true);
if (!CFReadStreamOpen(m_readStream)) {
/* Open failed: clean */
CFReadStreamSetClient(m_readStream, 0, NULL, NULL);
setScheduledInRunLoop(false);
if (m_readStream) {
CFRelease(m_readStream), m_readStream = 0;
}
goto out;
}
success = true;
out:
return success;
}
示例2: LOGGER_WARNING
bool HTTPInputSource::Open(CFErrorRef *error)
{
if(IsOpen()) {
LOGGER_WARNING("org.sbooth.AudioEngine.InputSource.HTTP", "Open() called on an InputSource that is already open");
return true;
}
// Set up the HTTP request
mRequest = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), mURL, kCFHTTPVersion1_1);
if(NULL == mRequest) {
if(error)
*error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, ENOMEM, NULL);
return false;
}
CFHTTPMessageSetHeaderFieldValue(mRequest, CFSTR("User-Agent"), CFSTR("SFBAudioEngine"));
// Seek support
if(0 < mDesiredOffset) {
CFStringRef byteRange = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("bytes=%ld-"), mDesiredOffset);
CFHTTPMessageSetHeaderFieldValue(mRequest, CFSTR("Range"), byteRange);
CFRelease(byteRange), byteRange = NULL;
}
mReadStream = CFReadStreamCreateForStreamedHTTPRequest(kCFAllocatorDefault, mRequest, NULL);
if(NULL == mReadStream) {
CFRelease(mRequest), mRequest = NULL;
if(error)
*error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, ENOMEM, NULL);
return false;
}
// Start the HTTP connection
CFStreamClientContext myContext = { 0, this, NULL, NULL, NULL };
CFOptionFlags clientFlags = kCFStreamEventOpenCompleted | kCFStreamEventHasBytesAvailable | kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered;
if(!CFReadStreamSetClient(mReadStream, clientFlags, myCFReadStreamClientCallBack, &myContext)) {
CFRelease(mRequest), mRequest = NULL;
CFRelease(mReadStream), mReadStream = NULL;
if(error)
*error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, ENOMEM, NULL);
return false;
}
CFReadStreamScheduleWithRunLoop(mReadStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
if(!CFReadStreamOpen(mReadStream)) {
CFRelease(mRequest), mRequest = NULL;
CFRelease(mReadStream), mReadStream = NULL;
if(error)
*error = CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainPOSIX, ENOMEM, NULL);
return false;
}
while(NULL == mResponseHeaders)
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);
mIsOpen = true;
return true;
}
示例3: nc_trigger
static void
nc_trigger(int argc, char **argv)
{
Boolean background = FALSE;
int i;
CFStringRef hostName = NULL;
int port = 80;
for (i = 0; i < 3 && i < argc; i++) {
/* Parse host name. Must be first arg. */
if (i == 0) {
hostName = CFStringCreateWithCString(NULL, argv[i], kCFStringEncodingUTF8);
continue;
}
/* Check for optional background flag */
if (strcmp(argv[i], "background") == 0) {
background = TRUE;
continue;
}
/* Parse optional port number */
CFStringRef str = CFStringCreateWithCString(NULL, argv[i], kCFStringEncodingUTF8);
if (str) {
int num = CFStringGetIntValue(str);
if (num) {
port = num;
}
my_CFRelease(&str);
}
}
if (hostName) {
CFReadStreamRef readStream = NULL;
CFWriteStreamRef writeStream = NULL;
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, hostName, port, &readStream, &writeStream);
if (background) {
CFReadStreamSetProperty(readStream, CFSTR("kCFStreamNetworkServiceType"), CFSTR("kCFStreamNetworkServiceTypeBackground"));
CFWriteStreamSetProperty(writeStream, CFSTR("kCFStreamNetworkServiceType"), CFSTR("kCFStreamNetworkServiceTypeBackground"));
}
if (readStream && writeStream) {
CFReadStreamOpen(readStream);
CFWriteStreamOpen(writeStream);
SCPrint(TRUE, stdout, CFSTR("Opened stream to %@, port %d%s\n"), hostName, port, background ? ", background traffic class" : "");
sleep(1);
}
my_CFRelease(&readStream);
my_CFRelease(&writeStream);
} else {
SCPrint(TRUE, stderr, CFSTR("Invalid or missing host name\n"));
}
my_CFRelease(&hostName);
exit(0);
}
示例4: updateKeymap
void updateKeymap()
{
CFReadStreamRef readStream;
if (!fileExists(CFSTR(KEYMAP_PATH)))
{
stamp_file(CFSTR("Error: Keymap file is missing"));
keymap = NULL;
return;
}
readStream = CFReadStreamCreateWithFile(kCFAllocatorDefault,CFURLCreateWithFileSystemPath(kCFAllocatorDefault,CFSTR(KEYMAP_PATH),kCFURLPOSIXPathStyle,false));
if (!readStream||!(CFReadStreamOpen(readStream)))
{
stamp_file(CFSTR("Error: Can't open keymap file"));
keymap = NULL;
return;
}
keymap = (CFDictionaryRef)CFPropertyListCreateFromStream(kCFAllocatorDefault,readStream,0,kCFPropertyListImmutable,NULL,NULL);
CFReadStreamClose(readStream);
if (!keymap)
{
stamp_file(CFSTR("Error: Can't read keymap file"));
return;
}
Boolean validKey;
showMods = (CFPreferencesGetAppBooleanValue(CFSTR("Mods"),PREF_DOMAIN,&validKey))?kCFBooleanTrue:kCFBooleanFalse;
if (!validKey)
{
showMods = kCFBooleanTrue;
CFPreferencesSetAppValue(CFSTR("Mods"),showMods,PREF_DOMAIN);
}
}
示例5: WebApiClientMD5DigestCreateWithFilePath
CFDataRef WebApiClientMD5DigestCreateWithFilePath(CFStringRef filePath, size_t bufferSize) {
// Declare needed variables
CFDataRef result = NULL;
CFReadStreamRef readStream = NULL;
// Get the file URL
CFURLRef fileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)filePath, kCFURLPOSIXPathStyle, (Boolean)false);
if ( fileURL ) {
// Create and open the read stream
readStream = CFReadStreamCreateWithFile(kCFAllocatorDefault, fileURL);
if ( readStream ) {
Boolean didSucceed = CFReadStreamOpen(readStream);
if ( didSucceed ) {
// Initialize the hash object
CC_MD5_CTX hashObject;
CC_MD5_Init(&hashObject);
// Make sure chunkSizeForReadingData is valid
if ( bufferSize < 1 ) {
bufferSize = FileHashDefaultChunkSizeForReadingData;
}
// Feed the data to the hash object
bool hasMoreData = true;
while ( hasMoreData ) {
uint8_t buffer[bufferSize];
CFIndex readBytesCount = CFReadStreamRead(readStream, (UInt8 *)buffer, (CFIndex)sizeof(buffer));
if ( readBytesCount == -1 ) break;
if ( readBytesCount == 0 ) {
hasMoreData = false;
continue;
}
CC_MD5_Update(&hashObject, (const void *)buffer, (CC_LONG)readBytesCount);
}
// Check if the read operation succeeded
didSucceed = !hasMoreData;
// Compute the hash digest
unsigned char digest[CC_MD5_DIGEST_LENGTH];
CC_MD5_Final(digest, &hashObject);
// Abort if the read operation failed
if ( didSucceed ) {
result = CFDataCreate(kCFAllocatorDefault, digest, CC_MD5_DIGEST_LENGTH);
}
}
}
}
if ( readStream ) {
CFReadStreamClose(readStream);
CFRelease(readStream);
}
if ( fileURL ) {
CFRelease(fileURL);
}
return result;
}
示例6: GPPropertyListCopyLocalizableStringsDictionary
extern CFDictionaryRef GPPropertyListCopyLocalizableStringsDictionary(CFURLRef fileURL) {
CFReadStreamRef stream = CFReadStreamCreateWithFile(NULL, fileURL);
if (stream == NULL)
return NULL;
if (!CFReadStreamOpen(stream)) {
CFRelease(stream);
return NULL;
}
CFDictionaryRef dict = CFPropertyListCreateFromStream(NULL, stream, 0, kCFPropertyListImmutable, NULL, NULL);
CFReadStreamClose(stream);
CFRelease(stream);
if (dict == NULL)
return NULL;
if (CFGetTypeID(dict) != CFDictionaryGetTypeID()) {
CFRelease(dict);
return NULL;
}
CFDictionaryRef localizedStringsDict = CFDictionaryGetValue(dict, CFSTR("Localizations"));
if (localizedStringsDict == NULL || CFGetTypeID(localizedStringsDict) != CFDictionaryGetTypeID()) {
CFRelease(dict);
return NULL;
}
CFIndex langCount = CFDictionaryGetCount(localizedStringsDict);
CFStringRef keys[langCount]; // assume we don't have 4000 languages :p
CFDictionaryGetKeysAndValues(localizedStringsDict, (const void**)keys, NULL);
CFArrayCallBacks languagesCallbacks = {0, NULL, NULL, NULL, &CFEqual};
CFArrayRef languages = CFArrayCreate(NULL, (const void**)keys, langCount, &languagesCallbacks);
CFArrayRef preferedLanguages = CFBundleCopyPreferredLocalizationsFromArray(languages);
CFDictionaryRef retval = CFRetain(CFDictionaryGetValue(localizedStringsDict, CFArrayGetValueAtIndex(preferedLanguages, 0)));
CFRelease(languages);
CFRelease(preferedLanguages);
CFRelease(dict);
return retval;
}
示例7: CFStreamCreatePairWithSocket
CURLcode SSLImpl::connect(int sockfd, int nonblocking, int *done, int ssl_verify_peer, void *storage, char* host_name)
{
ssl_data_t *data = (ssl_data_t*)storage;
CFStreamCreatePairWithSocket(kCFAllocatorDefault, sockfd, &data->readStream, &data->writeStream);
// Indicate that the connection needs to be done in secure manner
CFReadStreamSetProperty(data->readStream, kCFStreamPropertySocketSecurityLevel, kCFStreamSocketSecurityLevelSSLv3);
CFWriteStreamSetProperty(data->writeStream, kCFStreamPropertySocketSecurityLevel, kCFStreamSocketSecurityLevelSSLv3);
CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if (!dict) {
RAWLOG_ERROR("Can not allocate CFMutableDictionaryRef");
return CURLE_SSL_CONNECT_ERROR;
}
CFDictionarySetValue(dict, kCFStreamSSLValidatesCertificateChain, ssl_verify_peer ? kCFBooleanTrue : kCFBooleanFalse);
CFReadStreamSetProperty(data->readStream, kCFStreamPropertySSLSettings, dict);
CFWriteStreamSetProperty(data->writeStream, kCFStreamPropertySSLSettings, dict);
CFRelease(dict);
if (!CFReadStreamOpen(data->readStream) || !CFWriteStreamOpen(data->writeStream)) {
RAWLOG_ERROR("SSL connection error");
return CURLE_SSL_CONNECT_ERROR;
}
CFReadStreamScheduleWithRunLoop( data->readStream,
CFRunLoopGetCurrent(),
kCFRunLoopCommonModes);
CFWriteStreamScheduleWithRunLoop( data->writeStream,
CFRunLoopGetCurrent(),
kCFRunLoopCommonModes);
*done = 1;
return CURLE_OK;
}
示例8: FetchIPAddress
static void FetchIPAddress()
{
if(publicIPState == IPStateFetching)
return;
publicIPState = IPStateFetching;
const UInt8 bodyBytes[] = {0};
CFDataRef body = CFDataCreate(kCFAllocatorDefault, bodyBytes, 0);
CFURLRef url = CFURLCreateWithString(kCFAllocatorDefault, CFSTR("http://icanhazip.com"), NULL);
CFHTTPMessageRef request = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), url, kCFHTTPVersion1_1);
CFHTTPMessageSetBody(request, body);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// Apple suggests the NSURLSession API instead of CFReadStreamCreateForHTTPRequest,
// But obviously that doesn't really work here
CFReadStreamRef stream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, request);
#pragma clang diagnostic pop
CFRelease(body);
CFRelease(url);
CFRelease(request);
CFMutableDataRef responseData = CFDataCreateMutable(kCFAllocatorDefault, 17);
CFStreamClientContext context = { 0, responseData, NULL, NULL, NULL };
if(!CFReadStreamSetClient(stream, kCFStreamEventOpenCompleted | kCFStreamEventHasBytesAvailable | kCFStreamEventEndEncountered | kCFStreamEventErrorOccurred, &IPStreamCallback, &context))
{
CFRelease(stream);
publicIPState = IPStateInvalid;
return;
}
// Add to the run loop and open the stream
CFReadStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
if(!CFReadStreamOpen(stream))
{
CFReadStreamSetClient(stream, 0, NULL, NULL);
CFReadStreamUnscheduleFromRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
CFRelease(stream);
publicIPState = IPStateInvalid;
return;
}
// Run the run loop
do {
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0, TRUE);
} while(publicIPState == IPStateFetching);
}
示例9: openNextStream
static void openNextStream(FormStreamFields* form)
{
// Skip over any streams we can't open.
// For some purposes we might want to return an error, but the current CFURLConnection
// can't really do anything useful with an error at this point, so this is better.
advanceCurrentStream(form);
while (form->currentStream && !CFReadStreamOpen(form->currentStream))
advanceCurrentStream(form);
}
示例10: openNextStream
static bool openNextStream(FormStreamFields* form)
{
// Skip over any streams we can't open.
if (!advanceCurrentStream(form))
return false;
while (form->currentStream && !CFReadStreamOpen(form->currentStream)) {
if (!advanceCurrentStream(form))
return false;
}
return true;
}
示例11: copy_disk_app_identifier
CFStringRef copy_disk_app_identifier(CFURLRef disk_app_url) {
CFURLRef plist_url = CFURLCreateCopyAppendingPathComponent(NULL, disk_app_url, CFSTR("Info.plist"), false);
CFReadStreamRef plist_stream = CFReadStreamCreateWithFile(NULL, plist_url);
CFReadStreamOpen(plist_stream);
CFPropertyListRef plist = CFPropertyListCreateWithStream(NULL, plist_stream, 0, kCFPropertyListImmutable, NULL, NULL);
CFStringRef bundle_identifier = CFRetain(CFDictionaryGetValue(plist, CFSTR("CFBundleIdentifier")));
CFReadStreamClose(plist_stream);
CFRelease(plist_url);
CFRelease(plist_stream);
CFRelease(plist);
return bundle_identifier;
}
示例12: MySimpleDirectoryListing
/* MySimpleDirectoryListing implements the directory list command. It sets up a MyStreamInfo
'object' with the read stream being an FTP stream of the directory to list and with no
write stream. It then returns, and the real work happens asynchronously in the runloop.
The function returns true if the stream setup succeeded, and false if it failed. */
static Boolean
MySimpleDirectoryListing(CFStringRef urlString, CFStringRef username, CFStringRef password)
{
CFReadStreamRef readStream;
CFStreamClientContext context = { 0, NULL, NULL, NULL, NULL };
CFURLRef downloadURL;
Boolean success = true;
MyStreamInfo *streamInfo;
assert(urlString != NULL);
downloadURL = CFURLCreateWithString(kCFAllocatorDefault, urlString, NULL);
assert(downloadURL != NULL);
/* Create an FTP read stream for downloading operation from an FTP URL. */
readStream = CFReadStreamCreateWithFTPURL(kCFAllocatorDefault, downloadURL);
assert(readStream != NULL);
CFRelease(downloadURL);
/* Initialize our MyStreamInfo structure, which we use to store some information about the stream. */
MyStreamInfoCreate(&streamInfo, readStream, NULL);
context.info = (void *)streamInfo;
/* CFReadStreamSetClient registers a callback to hear about interesting events that occur on a stream. */
success = CFReadStreamSetClient(readStream, kNetworkEvents, MyDirectoryListingCallBack, &context);
if (success) {
/* Schedule a run loop on which the client can be notified about stream events. The client
callback will be triggered via the run loop. It's the caller's responsibility to ensure that
the run loop is running. */
CFReadStreamScheduleWithRunLoop(readStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
MyCFStreamSetUsernamePassword(readStream, username, password);
MyCFStreamSetFTPProxy(readStream, &streamInfo->proxyDict);
/* CFReadStreamOpen will return success/failure. Opening a stream causes it to reserve all the
system resources it requires. If the stream can open non-blocking, this will always return TRUE;
listen to the run loop source to find out when the open completes and whether it was successful. */
success = CFReadStreamOpen(readStream);
if (success == false) {
fprintf(stderr, "CFReadStreamOpen failed\n");
MyStreamInfoDestroy(streamInfo);
}
} else {
fprintf(stderr, "CFReadStreamSetClient failed\n");
MyStreamInfoDestroy(streamInfo);
}
return success;
}
示例13: openNextStream
static bool openNextStream(FormStreamFields* form)
{
// CFReadStreamOpen() can cause this function to be re-entered from another thread before it returns.
// One example when this can occur is when the stream being opened has no data. See <rdar://problem/23550269>.
LockHolder locker(form->streamIsBeingOpenedOrClosedLock);
// Skip over any streams we can't open.
if (!advanceCurrentStream(form))
return false;
while (form->currentStream && !CFReadStreamOpen(form->currentStream)) {
if (!advanceCurrentStream(form))
return false;
}
return true;
}
示例14: AppleInputStream
AppleBufferInputStream::AppleBufferInputStream(const StringBuffer& dataString) : AppleInputStream()
{
data = dataString.c_str();
totalSize = dataString.length();
if (data) {
readStream = CFReadStreamCreateWithBytesNoCopy(kCFAllocatorDefault,
(const UInt8 *)data,
(CFIndex)totalSize,
kCFAllocatorNull);
if (CFReadStreamOpen(readStream) == TRUE) {
streamOpened = true;
}
}
}
示例15: SDMMD_ServiceReceiveStream
sdmmd_return_t SDMMD_ServiceReceiveStream(SocketConnection handle, CFPropertyListRef *data) {
CFDataRef dataBuffer = NULL;
if (SDM_MD_CallSuccessful(SDMMD_ServiceReceive(handle, &dataBuffer))) {
if (dataBuffer && CFDataGetLength(dataBuffer)) {
CFReadStreamRef read = CFReadStreamCreateWithBytesNoCopy(kCFAllocatorDefault, CFDataGetBytePtr(dataBuffer), CFDataGetLength(dataBuffer), kCFAllocatorNull);
CFReadStreamOpen(read);
*data = CFPropertyListCreateWithStream(kCFAllocatorDefault, read, CFDataGetLength(dataBuffer), 0x2, 0, NULL);
CFReadStreamClose(read);
if (read)
CFRelease(read);
}
return kAMDSuccess;
} else {
return kAMDNotConnectedError;
}
}